Date post: | 17-Dec-2015 |
Category: |
Documents |
Upload: | emerald-booth |
View: | 231 times |
Download: | 1 times |
©Col
in J
amis
on
2004
Introduction to Linux
Colin Jamison
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
UNIX Command Formatcommand <options> <arguments>
• 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
©Col
in J
amis
on
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
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
Directory Navigation
• Changing directory
$ cd /usr
$ cd local/bin
$ cd ..• Present directory
$ pwd
/home/cjamison/• Creating/removing directories
$ mkdir directoryname
$ rmdir directoryname
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
bash2.04$ ls -ltotaldrwxr-xr-x 1 cjamison staff 123 Dec 12 2003 Aproject-rwx--x--x 1 cjamison staff 514 Dec 24 2003 Ascript-rwxr--r-- 1 cjamison staff 2345 Jan 02 2004 afile-rwxr--r-- 1 cjamison staff 231 Aug 12 2003 checksum-rwxr-x--x 1 cjamison staff 126 Dec 24 1990 dos2unix-rwx------ 1 cjamison staff 732 Oct 23 2003 dev.txt-rwxr-x--x 1 cjamison staff 9470 Aug 26 2003 excaliburdrwxr-x--x 1 cjamison staff 512 Dec 10 2003 homedrwx------ 1 cjamison staff 512 Jan 16 2004 mp3drwx------ 1 cjamison staff 512 Sep 01 2003 payroll-rwxr-x--- 1 cjamison staff 8972 Aug 21 2003 swallow -rw------- 1 cjamison staff 42 Dec 24 2003 swift.txtbash2.04$
File listing
type
access permission
owner
group
sizedate and timelast modified
name
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
Access Permissions• The first character indicates the type of file:
– directory (d) – link (l)– plain file (-)
-rwxrwxr-x-rwxrwxr-x The rest, specify three types of users
owner group others
who are allowed to (r) read (w) write (x) execute
©Col
in J
amis
on
2004
Numerical Access Permissions
-|rwx|r-x|r--|
|111 |101|100|
Character
Binary
Octal | 7 | 5 | 4 |
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
Changing Access Permissionschmod 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
©Col
in J
amis
on
2004
Viewing and Editing Files
• Listing files– cat e.g. cat filename– tail e.g. tail -f filename
• Listing files one screen at a time– more e.g. cat filename | more
• Editing files– vi– emacs– GUI tools
©Col
in J
amis
on
2004
File Manipulation
• Copy – cp filename1 filename2
• move (rename)– mv filename directory
• remove (delete) - be careful!– rm filename
©Col
in J
amis
on
2004
Listing Processes
• List processes e.g.
• ps
• ps -ef
©Col
in J
amis
on
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)
©Col
in J
amis
on
2004
Disposing of Rogue Processes
• The kill command
• kill parameter PID
• parameters ‘-1’ to ‘-9’
• PID available from one of the process commands
©Col
in J
amis
on
2004
Redirection (1)
• ls -al > lsoutput1.txt
• ls -al >> lsoutput2.txt
• file descriptors
• standard input 0
• standard output 1
• standard error 2
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
Pipes
• Simplify redirection e.g.
• ps | sort | more
• ps | grep ‘sh’ > listshells.txt
©Col
in J
amis
on
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
©Col
in J
amis
on
2004
‘C’ Tools (gdb)
• gdb - GNU debugger• gdb programfilename
• most commonly used options• run break [file:]function print expr
• next step c
• edit [file:]function list
• help command quit
©Col
in J
amis
on
2004
Questions ?