©Colin Jamison 2004 Introduction to Linux Colin Jamison
©Colin Jamison 2004 Help on Unix Commands List all options available for a command and also some example usage e.g. man command-name As for ‘man’ but the ‘info’ command has more information and is up to date e.g. info command-name
©Colin Jamison 2004 UNIX Command Format command The first word is the command Options follow commands Commands/options/arguments are case sensitive A command may or may not have options $ ls $ ls -al Arguments are normally files/directories $ ls -al /etc
©Colin Jamison 2004 Directory and File Names Case sensitive Any character Avoid “ / * > space ! ” –they are legal but their use is problematic with shells Must be unique inside its directory Wildcard – *any number of characters – ?any single character – [ ]Any one of the characters inserted between the brackets
©Colin Jamison 2004 Path Names Path name - is an address that uniquely identifies a file or directory in the UNIX file system. Absolute path name - always starts from the root directory e.g. /usr/local/bin Relative path name - path relative to the present working directory e.g. if pwd is /usr relative pathname local/bin is equivalent to the absolute pathname /usr/local/bin
©Colin Jamison 2004 Directory Navigation Changing directory $ cd /usr $ cd local/bin $ cd.. Present directory $ pwd /home/cjamison/ Creating/removing directories $ mkdir directoryname $ rmdir directoryname
©Colin Jamison 2004 Directory Contents File listing $ ls - abbreviated list $ ls -a - abbreviated list + hidden files $ ls -al - long list + hidden files $ ls -F - abbreviated list + file type
©Colin Jamison 2004 bash2.04$ ls -l total drwxr-xr-x 1 cjamison staff 123 Dec Aproject -rwx--x--x 1 cjamison staff 514 Dec Ascript -rwxr--r-- 1 cjamison staff 2345 Jan afile -rwxr--r-- 1 cjamison staff 231 Aug checksum -rwxr-x--x 1 cjamison staff 126 Dec dos2unix -rwx cjamison staff 732 Oct dev.txt -rwxr-x--x 1 cjamison staff 9470 Aug excalibur drwxr-x--x 1 cjamison staff 512 Dec home drwx cjamison staff 512 Jan mp3 drwx cjamison staff 512 Sep payroll -rwxr-x--- 1 cjamison staff 8972 Aug swallow -rw cjamison staff 42 Dec swift.txt bash2.04$ File listing type access permission owner group size date and time last modified name
©Colin Jamison 2004 Access Permissions Access permissions on a directory determine whether a file in the directory can be renamed or removed File permissions determine what can be done to the file contents To allow access to a directory, access permissions should be set for all of its parent directories all the way up to the root directory
©Colin Jamison 2004 Access Permissions The first character indicates the type of file: –directory (d) –link (l) –plain file (-) -rwxrwxr-x l The rest, specify three types of users m owner m group m others l who are allowed to m (r) read m (w) write m (x) execute
©Colin Jamison 2004 Numerical Access Permissions -|rwx|r-x|r--| |111 |101|100| Character Binary Octal | 7 | 5 | 4 |
©Colin Jamison 2004 Protecting Your Files -r (400) protect it from accidental editing -rw (600) owner can edit/read the file -rw- r-- r-- (644) owner can edit, others may read -rw- rw- rw- (666) everyone can edit/read dr-x r-x r-x (555) everyone can list but can’t create delete/rename files drwx (700) owner can do anything drwx r-x r-x (755) owner can do anything, others can read drwx rwx rwx (777) anyone can edit/read/run
©Colin Jamison 2004 Changing Access Permissions chmod permission files Character Method $ chmod a=r-x filename $ chmod u=rwx filename $ chmod go+r filename $ chmod ugo-w filename Numerical Method $ chmod 755 filename $ chmod 600 filename
©Colin Jamison 2004 Viewing and Editing Files Listing files –cate.g. cat filename –taile.g. tail -f filename Listing files one screen at a time –moree.g. cat filename | more Editing files –vi –emacs –GUI tools
©Colin Jamison 2004 File Manipulation Copy –cp filename1 filename2 move (rename) –mv filename directory remove (delete) - be careful! –rm filename
©Colin Jamison 2004 Listing Processes List processes e.g. ps ps -ef
©Colin Jamison 2004 Processes - Foreground v Background To run a process as a background process: process-name & To examine foreground/background processes use the jobs command fg bg Each process has a unique process id (PID)
©Colin Jamison 2004 Disposing of Rogue Processes The kill command kill parameter PID parameters ‘-1’ to ‘-9’ PID available from one of the process commands
©Colin Jamison 2004 Redirection (1) ls -al > lsoutput1.txt ls -al >> lsoutput2.txt file descriptors standard input 0 standard output 1 standard error 2
©Colin Jamison 2004 Redirection (2) Redirect standard error to a file ls -al > lsout.txt 2>lserror.txt redirect standard output and standard error to the same file ls -al > lsout.txt 2>&1 Redirecting input more < lsout.txt To discard standard output and standard error ls -al > /dev/null 2>&1
©Colin Jamison 2004 Pipes Simplify redirection e.g. ps | sort | more ps | grep ‘sh’ > listshells.txt
©Colin Jamison 2004 ‘C’ Tools (gcc) gcc - GNU C/C++ compiler gcc filename1 … filenameX -o programfilename most commonly used options [-Idir...] search dir for header files [-Ldir…] include dir to search for library ( -llibrary ) [-o outfile] [-ggdb] include gdb debugging information
©Colin Jamison 2004 ‘C’ Tools (gdb) gdb - GNU debugger gdb programfilename most commonly used options run break [file:]functionprint expr next step c edit [file:]function list help command quit
©Colin Jamison 2004 Questions ?