- Slides: 13
A Mini UNIX Tutorial
What’s UNIX? w An operating system run on many servers/workstations w Invented by AT&T Bell Labs in late 60’s w Currently there are different versions and variants of UNIX such as Sun. OS, Linux, Solaris, BSD, …
Basic UNIX w Most UNIX functionality is accessed through the UNIX prompt. n Text based, like MS-DOS w Mastery of UNIX comes from being familiar with different commands n n We will cover some of the basic commands in this class Goal: to be able to navigate through the directories
UNIX Directory Structure w Files are grouped in the directory structure. The file-system is arranged like hierarchical tree structure. w The top of the tree is called “root” which usually contains several sub-directories. l “/”(forward slash) is used to present the “root”.
What is Directory? Directories can hold files and other directories / bin users etc root tmp backup usern user 1 user 2 …… public_html file 1 index. html
Pathnames w Absolute Pathnames w Relative pathnames n In the previous tree /users/usern/file 1 is an absolute pathname n If you are already in the users directory, the relative pathname for file 1 is usern/file 1
More on UNIX paths w “~” (tilda) points to the user’s home directory. Useful if you are logging into a workstation with many users. w Many of the other paths are inaccessible and unimportant to you w ~ is the default working directory when you log in. w If you are user “usern”, then /users/usern/file 1 is the same as ~/file 1. w “. ” refers to the current directory w “. . ” refers to the parent directory. w If you are in /users/usern/, then. . / refers to /users/.
UNIX – Basic commands w man – manual. Use “man name” to bring up a manual entry for command or program name. w clear – clear. Clears the screen. Navigation w ls – list. Lists folders/files in a directory w cd – change directory. Use “cd name” to navigate to directory name. w pwd – print working directory. Prints the path of the current directory. w du – disk usage. Shows the disk usage of the current directory
UNIX – More commands Creation w mkdir – make directory. Use “mkdir name” to create a new directory in the current directory named name. Can also create multiple directories. w cp – copy. Use “cp file 1 file 2” to create a new file, file 2 which is a copy of file 1. Can also use “cp file(s) directory” to copy all file(s) to directory. w mv – move. Same as copy, but deletes the original file.
UNIX – More commands Deletion – Be careful with these! w rm – remove. Use “rm file(s)” to delete files w rmdir – remove directory. Use it to delete an empty directory w You can not recover your files after you removed them!
Some tips w “tab” is used for auto-complete. n n If a file/directory name was partly typed in, tab will auto-complete it. If there are multiple options, tab will auto-complete up to the point where the options branch and show you a list of possible options w “*” is used as a wild card. n n “rm blah*” removes all files which start with blah, so blah 1, blah 2, and blah would all be removed Using “cp public/* private/” copies all files in your public directory into your private directory, and keeps all file names intact.
More tips w “-r” is a common option that usually makes a command recursive, that is, it will execute the same command on all subdirectories. n n n Commonly used to perform file commands on directories Using “cp private/* public/ -r” copies everything from the private folder to the public folder, and also copies all subdirectories. Using “rm –r *” deletes everything in the current directory and all sub-directories. Never use this in the root directory!
Programs w Some basic UNIX programs: n n emacs – text editing pico – another text editor gcc – C compiler pine – program for internet news and email