Unix Tutorial
Presented by UBC IEEE Student Branch
Topics to be Covered:
• • • • •
Unix Shell Basics Unix file system Email forwarding Suspending and Killing processes Printing
Shell Basics
• Shells are command line interpreters. This is where a user can type
in commands to create/del. files.. etc • Depending on the type of shell you use, the prompt may look different. – tcsh: prevost:~> – bash: bash-2.05b$ – csh: prevost<31> • To check which shell you are running type:
• To change the type name of the shell and hit enter. • Command Format
– Eg. If I wanted to use tcsh, just type in tcsh and then enter at the command line – Command [options] [arguments] – Eg. ls –la *.cpp
– Echo $SHELL
Unix File Structure
• Tree Hierachy
Diagram From CS219
Directory Navigation
• Directory Paths
– unlike MS-DOS, UNIX file systems use forward slashes – Eg. /usr/bob/hmwk/ (UNIX)
\mydocuments\hmwk\ (MS)
• Change Directory: cd directory_path
• Useful Commands
– Go up to parent directory: cd .. – Go to home directory: cd ~
– pwd: returns “present working directory” – ls: “list contents of directory” • ls –la “lists all files incl. hidden files + shows file permissions
Directories Cont…
• To create a new directory:
• To remove an empty directory:
– mkdir dir_name – rmdir dir_name
• To remove a directory that has files and
subfolders:
• To delete files
– rm file_name
– rm –R dir_name
File Permissions
prevost:~/demo> ls -la total 16 drwx------ 3 m0r1 undergrad drwx--x--x 23 m0r1 undergrad -rwxr-xr-x 1 m0r1 undergrad -rw------- 1 m0r1 undergrad drwx------ 2 m0r1 undergrad • d|r|w|x|r|w|x|r|w|x
• r: readable „d‟ de• w: writable • X: executable
512 Jan 11 14:39 ./ 3584 Jan 11 14:39 ../ 7 Jan 11 14:39 calc.c* 12 Jan 11 14:39 helloWorld.txt 512 Jan 11 14:39 test/
– First character „d‟, if shown, means that it is a directory – 3 groups of r|w|x.
– r|w|x permission groupings
• First r|w|x group is the permissions of the file for the user • Second group of r|w|x is for group members • Third group of r|w|x is for any other user
File Permissions cont..
• to change file permissions:
– Method:
• Eg. chmod [target][ops][permissions] [file name]
– targets: u g o – ops: + – permissions: r w x
(user) (group) (other) (add permission) (remove permission) (read) (write) (execute)
– Tips:
• Eg. chmod g+rwx helloWorld.txt • To protect your home directory, and all subdirectories on your Unix acct.
– chmod –R 755 ~ – this command changes the permissions for all folders, subfolders, and files in a user‟s home directory to allow read, write, and execute for the owner ONLY.
Email Forwarding
• To enable email forwarding:
– type in: echo email_address > ~/.forward
• To cancel email forwarding
– type in: rm ~/.forward
Processes and Job Control
• To check what jobs (programs) that you are running
– type in: jobs – Eg. prevost:~> jobs [1] + Suspended
•
• To suspend a running program
• To kill a running program
– press [Ctrl-z] on the keyboard – press [Ctrl-c] on the keyboard
Here we can see that a program called “man” with the argument “more” was suspended
man more
• To recover a suspended program
• To run a program in the background
– type in: program_name &
– type in: %[job number] – Eg. %1 (brings back the “man” program in the above example) (the ampersand will run the program in the background)
Printing Documents
• To print a file:
– lpr –Pprinter_name filename – Eg. lpr –Plaserprn1 work.txt
• To check printing queue:
– lpq –Pprinter_name – This will output list of print jobs.
• To remove printing queue:
– lprm –Pprinter_name job#
Useful Links
• SSH setup for remote connection to ECE
– http://www.ece.ubc.ca/twiki/bin/view/ITHelp/ HowToForEndUsers
• UNIX Cheat Sheet
– http://www.ece.ubc.ca/~ieee/resources/unix M.html