You are on page 1of 40

Tutorial of Unix/Linux

Cédric Notredame (Adapted from NOMURA)


3. 4.

6. 7. 8. 9.

Overview of Unix System Basic Commands Relative & Absolute Path Redirect, Append and Pipe Permission Process Management Install Software Text Editor Foreground and Background Jobs

Overview of Unix System
Kernel & Shell
 Unix/Linux is operating system (OS).  Unix system is described as kernel & shell.
 Kernel is a main program of Unix system.


it controls hard wares, CPU, memory, hard disk, network card etc.
 Shell is an interface between user and

Shell Kernel

kernel. Shell interprets your input as commands and pass them to kernel.

Unix Overview (cont.)
Multi-user & Multi-process  Many people can use one machine at the same time. File & Process  Data, directory, process, hard disk etc (almost everything) are expressed as a file.  Process is an running program identified by a unique id (PID).

) Directory Structure      Files are put in a directory. Users have the own directory. User can put and remove any directories on the tree. (home directory) . All directories are in a hierarchical structure (tree structure). which is called slash or root. Top directory is “/”.Unix Overview (cont.

Unix Overview (cont.) Directory Structure .

and must be available to be written to.Unix Overview (cont.  /var This directory is used to store files which change frequently. Various system configuration files are stored here.  /etc .) Important Directories  /bin This contains files that are essential for correct operation of the system. These are available for use by all users.  /home This is where user home directories are stored.

 /tmp . hard disk.) Important Directories  /dev This contains various devices as files. e.g.Unix Overview (cont. Temporary files.  /sbin Binaries which are only expected to be used by the super user. CD-ROM drive. etc.

Online Manual  Unix has well-written online manuals.Unix Overview (cont. Case Sensitivity  Unix is case-sensitive.doc.) Normal user and Super user  In Unix system. which can do anything.  This special user is called root or superuser. mYfiLe.  MYFILE.Doc are different. there is one special user for administrator. Myfile.doc. .

i. Example) [someone~]$ command-name optionA optionB argument1 argument2 .e. you will see. arguments. options. [someone]$  One command consists of three parts.Basic Commands How to run commands  Finder => Application => Utilitaires => Terminal  When you log on Unix machine. command name.

ls –l .. space is necessary. options and arguments.bashrc mv fileA fileB .Basic Commands How to run commands  Between command name.  Opitions always start with “-”  Example: cd .

more. cat man show files in current position change directory copy file or directory move file or directory remove file or directory show current position create directory remove directory display file contents display online manual .Basic Commands Commands           ls cd cp mv rm pwd mkdir rmdir less.

Basic Commands Commands         su passwd useradd userdel mount umount df shutdown switch user change password create new user account delete user account mount file system unmount file system show disk space usage reboot or turn off machine .

check disk space usage df df -h . In your home directory.bash_profile cp . press “q”) rm sample.txt (note: to quit less.bash_profile sample.Basic Commands 1.txt less sample. Make a directory mkdir linux pwd cd linux pwd cd pwd rmdir linux 3. ls . Type following command in your directory.txt 4. ls ls –a ls –la ls -Fa 2.

you can use relative path or absolute path. . the path is not defined uniquely. depends on your current path. the path is defined uniquely.Relative & Absolute Path  Path means a position in the directory tree.  In relative path expression.  In absolute path expression.  To express a path. does not depend on your current path.

Absolute Path  Address from the root /home/linux/ ~/linux ~: ~: Alt+N  Similar to: Lausanne University/Lausanne/Canton de Vaud/ Switzerland/Europe/Earth/Solar System/ .

/ : lists everything that is two dir higer  Similar to: Go Left/turn right/take the TSOL/go ./linux : lists the content of the dir linux ls . : one directory above your current location pwd: gives you your current location  Example ls .Relative Path  Relative to your current location ../.. : your current location ..

. pwd cd .. pwd cd . pwd cd cd mkdir mydir pwd cd /Users/invite pwd cd /Users pwd cd / pwd cd /Users/invite cd ~/mydir .Relative & Absolute Path  Relative Path  Ablsoute Path pwd cd .

The Pipe sign: (Shift+Alt+N: franc. Append and Pipe Redirect and append  Output of command is displayed on screen.Redirect. you can redirect the output from screen to a file.  Using “>>” you can append the output to the bottom of the file. Alt+7) .  Using “>”. Pipe  Some commands require input from a file or other commands.  Using “|”. you can use output from other command as input to the command.  On MacOSX.

Redirect. Append and Pipe Commands  head  tail show first several lines and omit other lines. show last several lines and omit other lines.  grep XXX File show lines matching pattern XXX in File .

tail -3 sample.txt Use redirect.txt head -3 sample.txt rm redirect. less redirect.txt grep –n Desk redirect. type ls -1 > sample.txt | grep Desk rm sample.txt Use append.txt grep Desk redirect.Redirect. Append and Pipe    In home directory.txt  Use pipe.txt less sample.txt .txt tail -3 sample.txt man grep tail redirect.txt less redirect. head -3 sample.txt > redirect.txt >> redirect.

using the numeric value of the third field .Sorting Commands  sort  -n  -k3  -rnk3 Sorts using the first field of each line. Sorts considering the numeric value of the strings Sorts using the third field of each line Sorts in reverse order.

Redirect. Append and Pipe  Identify the largest file in a directory: ls –la /bin/ | sort –nk5 | tail -1 .

 There are three types of permission. writeable and executable.Permission  All of files and directories have owner and permission. readable.bash_profile  r:readable. group member and others. Example: ls -l . owner.bash_profile -rw-r--r-. x: executable . w:writable.1 cnotred cnotred 191 Jan 4 13:11 .  Permissions are given to three kinds of group.

g: group.Permission Command  chmod  chown change file mode. add or remove permission change owner of the file Example) chmod a+w filename add writable permission to all users chmod o-x filename remove executable permission from others chmod a+x Gives permission to the usser to execute a file  u: user (owner). o: others a: all .

Permission  Check permission ls –l . chmod u+rw sample.txt less sample.txt ls –l sample.txt ls –l sample.bash_profile sample.txt less sample.txt ls –l sample.txt   .txt Remove readable permission from all. chmod a-r sample.bash_profile cp .txt Add readable & writable premissions to file owner.txt rm sample.

Process Management  Process is a unit of running program. Example) Output of “top” command . etc. owner.  Each process has some information. priority. like process ID.

Process Management Commands  kill  killall  ps  top Stop a program. The program is specified by command name. Show process status Show system usage statistics . Stop a program. The program is specified by process ID.

top (To quit top. press “q”) ps –e ps –ef  Find your process. ps ps –u  Check process of all users.Process Management  Check your process. ps –ef | grep cnotred .

make & make install Typical software installation procedure as following. Download source code. Program compilation is written in Makefile. configure. 1. 3. 2. it’s archived with tar command and compressed with gzip command.Install Software  Unix system has a “de facto standard” way to install a software. configure command creates Makefile automatically which is used to compile the source.  . Usually.

Install Software Commands      gzip gunzip tar configure make compress a file uncompress a file archive or expand files create Makefile compile & install software .

tar./install OR make all OR … .tar cd software .gz tar –xvf software.Install Software Example: parallel programming library installation gunzip software.

.  There are two popular text editors. it is also true that they are complicated for beginners and difficult to learn. vi and Emacs.  pico is an easy and simple alternative.Text Editor pico  Programs & configuration files are text file.  Although they are very powerful and useful.

CTRL+u Paste (uncut) last cut text at the cursor position.  Autre: xemacs. CTRL+v Move forward one page. CTRL+e Move to the end of the current line. saving the file. CTRL+o Save (output) the file.Text Editor Commands            Arrow-keys Move cursor CTRL+a Move to the beginning of the current line. CTRL+k Remove (cut) current line or selected text. CTRL+y Move backward one page. CTRL+x Exit Pico. CTRL+d Delete the current character. emacs . CTRL+w Search for text.

pl  Run it! .Text Editor  Create the file Hello pico  Write as follows./ .  Make il executable chmod u+x hello. #!/usr/bin/perl print “Hello World\n”.

Foreground and Background  Running job has two modes. “foreground” and “background”  If program is running as “background”. the program keeps running even after your session was closed  If program is running as “foreground”. Ctrl-C Ctrl-Z stop program let program background .

Foreground and Background  To run programs in background mode. use “fg” command. [nomura@ssc-1]$ fg . use “&” [nomura@ssc-1]$ command &  To get background job back into foreground mode.

Remote Login & File Transfer • rshd. sshd are server program and provide similar services. • The major difference is security level. telnetd. rshd < telnetd + ftpd < sshd Commands Client  rsh & rcp  telnet & ftp  ssh & scp Server  rshd  telnetd & ftpd  sshd . remote login & file transfer. ftpd.

Remote Login & File Transfer Remote login & file transfer system are based on server and client model. telnet server provides remote login service. ftp server provides file transfer service. SMTP client . client program on your machine ask sever program certain service remote machine. For example. Sample client programs. WS FTP Internet Exploror Eudora FTP client HTTP client POP.

Tutorial of Unix/Linux END .