Dec 31, 2015
Introduction to Linux
Julien [email protected]
A little bit of History
1969 - Bells Labs develop a new operating system called “UNIX” Written in C instead of assembly code Able to recycle code Improved compatibility between systems
Beginning of the 90’s PC becomes popular UNIX too slow for these machines and not free People switch to Windows 3.1 or MS-DOS
1991 – Linus Torvalds (University of Helsinki) starts working on the “Linux” project Free OS Compliant with the original UNIX
Today – why do you care? De-facto OS for high-performance computing (clusters) More and more popular in federal agencies and large
companies
Linus Torvalds
Linux distributions
Pros Free and open source Large community Secure, almost no virus (compared to Windows) Scalable: from palm to cluster with more 100 nodes
Cons Not as user-friendly as Windows or Mac but getting there Many distributions available: Ubuntu, RedHat, Fedora, SUSE,
Mandriva, Debian… See:
http://futurist.se/gldt/wp-content/uploads/11.04/gldt1104.png
What a Linux distribution can look like today…
Connecting to CHPC
Host: sanddunearch.chpc.utah.edu
Login: uNID Password:uNID password
Using PuTTY (Windows): Just enter the host name
Using ssh (Mac or Linux):ssh [-Y] login@hostThe -Y option is used to enable GUIs (it can be slow!!)
Basic commands to survive cd change current directory ls [-la] list files pwd show path to current directory mkdir create new directory mv move file/dir to new location cp [-r] copy file (use -r for directory)
scp [-r] secured copy over the network ssh secured remote login
man cmd cmd command manual
Exercise 1
Create the directory ~/workshops/linux/test in your home directory
Copy the test directory to ~/workshops/linux/test2
Move test2 to your home directory and rename it testlinux
VI text editor
Try out Emacs if you cant stand VI…
http://www.cs.colostate.edu/helpdocs/emacs.html
VI basic commands
Insertion mode: i Command mode: ESC
dd delete current line (and copy) yy copy current line p paste before cursor u undo
/string or ?string search string after or before cursor n or N go to next or previous match
:s/pattern/string/g replace pattern by new string
:w Save changes :q Exit :q! Exit and ignore any changes
More commands at: http://www.lagmonster.org/docs/vi.html
Exercise 2
Create a new text document, insert “Hello world” and save it as helloworld.txt
Download Moby Dick from http://www.gutenberg.org/ebooks/2701.txt.utf8 and rename it mobydick.txt
Delete everything that is before chapter 1
What is the title of chapter 107?
What is the last line?
Move the first paragraph (chapter 1) to be after the second one
How many times does the word ‘France’ appear in the text?
Administration
Using Linux in command-line Permissions
Root (super user)▪ Can control machine configuration and programs for all the
user ls -l will display the permissions for a file/dir
Interactive shell configuration aliases (e.g. “ll” instead of “ls -l”) environment variables
▪ $PATH: path to the executables▪ $HOME: point to your home directory
bash / C shell▪ 2 different scripting methods▪ .bashrc , .bash_profile , .profile / .tcshrc
Configuration scripts
Inside the configuration script: setenv / export Set environment variable alias Create alias
C shell script example (CHPC)
alias ll “ls -l”setenv EXEC “$HOME/programs”setenv PATH $EXEC/bin/:$PATH
Bash script example
alias ll=“ls -l”export EXEC=$HOME/programsexport PATH=$PATH:$EXEC/bin/
source apply changes to bash script for interactive shell echo var display value of environment variable
Useful commands
whichreturns the path to the command executable ps [aux] list of active processes top list of top active processes (updated ) find find a file or directory grep find a phrase in text cat display content of a file tail [–n] display the last lines of a file
su switch to superuser. Need root privileges
chmod change permissions on a file/dir chown change owner of a file/dir
wget download file from URL
Exercise 3
Find the location of the Matlab install at CHPC
Create an environment variable called $MATLAB_HOME that points to the install of Matlab version R2006 and add it to your PATH so it becomes the default version
Create an alias to display the version of java
Create a script called hello.sh that says “hello world” when you run it.
Managing jobs
Ctrl-C Cancel job Ctrl-Z Stop job
cmd & execute cmd in the background bg move job to background fg move job to foreground jobs list current jobs
Exercise 4
$ sleep 100 — Start a dummy job in foreground. (sleep = waits a x amount of second)Press Ctrl+z to stop the current job.
$ bg — Move the last stopped job to background.
$ sleep 150 — Dummy job 1Press Ctrl+z to stop the current job.
$ sleep 140 — Dummy job 2Press Ctrl+z to stop the current job.
$ sleep 130 — Dummy job 3Press Ctrl+z to stop the current job.
$ jobs — List all active jobs.
$ bg 2 — Move the 2nd active job to background.