unix basics
play

UNIX Basics UNIX Basics CIS 218 Oakton Community College History - PowerPoint PPT Presentation

UNIX Basics UNIX Basics CIS 218 Oakton Community College History UNIX was invented in 1969 at AT&T Bell Labs Ken Thompson and Dennis Ritchie are credited as the original architects and developers of C. Written in the C


  1. UNIX Basics UNIX Basics CIS 218 Oakton Community College

  2. History • UNIX was invented in 1969 at AT&T Bell Labs • Ken Thompson and Dennis Ritchie are credited as the original architects and developers of “C”. • Written in the C programming language in 1973 • Resold under UNIX System License (USL) • Current USL version SystemV R4 • Different commercial flavors: Solaris (Sun), AIX (IBM), Irix (SGI), HPUX (Hewlett Packard), SCO • Academic version – BSD (Mac OS X base) • UNIX Variants – LINUX, • UNIX “ports” – Android, MAC OSX

  3. Unix Design UNIX Design • Modularity – Each part of the Unix system is a system unto itself • printing, networking, mail, file management, accounting, etc. – Many Unix systems can be run in different modes. This allow for a certain set of modules to be run based on usage (workstation, server). – UNIX utilities are independently developed packages

  4. UNIX Layers

  5. UNIX Versus DOS/Windows • UNIX – everything is a file • UNIX is case sensitive, DOS is not • UNIX searches $PATH for executables, DOS starts in current directory, then PATH. • UNIX is multi-user, DOS is not. Windows is (kind of) • UNIX GUI sits “on top of” the OS - same as Windows thru ME). This changed After NT. • UNIX directory has one starting point – root “/”. Windows has multiple A:, C:, D: etc.

  6. UNIX Versus DOS/Windows • DOS UNIX Command Description • CD pwd Display current directory • CD \ cd / Moves to the root directory • CD .. cd .. Moves up one level in the directory structure • CD path cd path Sets the current directory to a new directory • CHKDSK du Displays disk usage • CLS clear Clear the screen • COMMAND sh, csh .. Start a new shell (command processor) • COMP cmp Compares two files and shows the difference • COPY cp Copy a file • DATE date Displays the date • DEL or ERASE rm Deletes a file • DELTREE rm -r Deletes a directory tree ( CAREFUL ! ! ! ) • DIR ls -l Lists the directory in a long format • DIR /W ls Lists the directory in a short format • ECHO echo Displays a message or a variable • EXIT exit End a shell • FC diff Displays differences between two files • FIND grep Displays lines matching a given pattern • HELP man Display information about a command • MD or MKDIR mkdir Creates a directory • MORE more Displays text a page at a time • MOVE mv Moves a file • PRINT lpr Prints a file • RD or RMDIR rmdir Removes a directory • REN mv Renames a file • SET set Sets a variable to a given value • SORT sort Sorts a data • TIME date Displays the time • TYPE cat Displays a file

  7. Shells • Shell – “sh” original interface to UNIX • Bourne Shell added some desirable features but has different syntax for some things • Newer Bourne Shell variants are Korn Shell (ksh) and Born Again Shell (bash) • C Shell – C program language syntax, tcsh, • Perl – Program Extract and Reporting Language • Some systems allow user to chose which shell you prefer with “chsh”. The full path to the shell must be given

  8. The Shell • When you log in to interact with UNIX, you see a “shell prompt” ($ or %) • A “word” is a text string separated by white space – space, Tab or IFS • The shell is a program that runs constantly and executes the commands you give it • A command is the first “word” on a line. All following words are command line parameters • Commands terminators: “ <LF> ” – Enter or Return, “ ; ”, “ | ”, “ > ”

  9. UNIX command line • You interact with the Unix by entering commands thru thee shell. The line is parsed as text sepaated by whitspace caracters into words or tokens. The first word is always a command. • The basic form of any Unix command is: Command Option(s) Argument(s) • Most commands provide integral help or on-line Manual (man page) • Options or flags modify the way that a command works. They usually consist of a hyphen followed by a single letter.

  10. Unix file types (ls – l) • d: Directory - holds other files or directories . • -: Normal Files Text files - text that is “human readable” . Binary files - executable files • l: Link - allows space efficient copying of files/directories. Symbolic or “soft” - may span file systems. Hard - is indistinguishable from the original file/directory. • .: Hidden File - any file that begins with a “.” (dot). • c,b: Character or Block Special Files – hardware interface . • “virtual” files – pipes, semaphores, sockets.

  11. Files and Directories • UNIX uses a single hierarchy to store files beginning with root “/” • Files are a named collection of bytes juliana Project File1 File2 File3 • Directories contain other files (or not)

  12. Basic Directory Terms • Home directory ( ~ ) - top of your file tree: • Root directory ( / ) - top of a file tree: • Current directory (.) - directory you’re in now (pwd) • Dot (.) - current directory • Dot -dot (..) - parent of current directory • Path - Where to find file or directory – Absolute path: /fs/scd/home0/juliana/myfile – Relative path: ./myfile • “Standard files” – STDIN, STDOUT, STDERR

  13. Managing Files and Directories • cd - change directories (built into shell) • pwd – present working directory • mkdir - creates a directory • rmdir - removes a directory (must be empty first) • rm myfile1 - remove a file • rm -fr - removes directory and everything below • touch <filename> - creates an empty file • cat <filename> - displays a file on screen • more <filename> - to see a screenful at a time • mv myfile1 myfile2 - renames (moveas) a file

  14. Tar and Compress Tar stands for “tape archive” but is more often used to gather - files into one bundle. Equivalent of a ZIP file, without the compression . - cd to the directory above the one you want to archive tar cvf - diry_name > diry.tar - To “list” the archive, use tar -xvf diry.tar - To “untar” the archive, use tar -xvf diry.tar - Compressed files take up less space. To compress a tar file, use compress diry.tar or gzip diry.tar - To uncompress, use uncompress diry.tar.Z or gunzip diry.tar.gz - Note equivalent gzip commands: zcat, zgrep, zmore, zdiff

  15. File Permissions • You “own” your files and directories • u ser- g roup- o ther read/write/execute permissions • -rw-r--r-- 1 jsmith staff 164870 27 Feb 17:58 6.bmp • -rw-r--r-- 1 jsmith staff 164870 27 Feb 17:57 5.bmp • + to add , - to remove alphabetic permissions • r=4, w=2, x=1 so rwx: 4+2+1=7 for numeric • chmod command changes permissions chmod 604 6.bmp chmod g-rw 6.bmp -rw----r-- 1 jsmith staff 164870 27 Feb 17:58 6.bmp

  16. File Permissions • Access rights on files. r : indicates read permission (or otherwise), that is, the presence or absence of permission to read and copy the file w : indicates write permission (or otherwise), that is, the permission (or otherwise) to change a file x : indicates execution permission (or otherwise), that is, the permission to execute a file, where appropriate • Access rights on directories. r : allows users to list files in the directory; w : allows users to delete files from the directory or move files into it; x : allows users the right to access files in the directory (e.g. cd into directory), read files in the directory provided you have read permission on the individual files.

  17. File Permissions Symbol Meaning u user g group o other a all r read w write (and delete) x execute (and access directory) + add permission - take away permission

  18. User Commands for Files What’s in my directory? • ls db5-24 nwade.txt schumacher5-19.txt kirsh5-12.txt nwade5-13a.txt sheu5-20.txt • ls -alt -rw-r--r-- 1 jsmith staff 712 24 May 09:12 db5-24 -rw-r--r-- 1 jsmith staff 1660 12 May 12:12 kirsh5-12.txt -rw-r--r-- 1 jsmith staff 3610 11 May 08:16 ming.txt -rw-r--r-- 1 jsmith staff 2444 10 May 16:53 mingrep • Wildcard - * stands for any (# of) character(s) • Wildcard - ? stands for any single character • [abcde…] selection set, any single character within the brackets

  19. User Commands for Files • wc - word, line, character, and byte count • echo - echo characters back (print) • sort - sort lines of a text file • uniq – remove consecutive duplicats lines • cut/paste/join – manipulate data by physical location in a record or file • sed – stream editor, vi commands in a batch file • awk – string manipulation • tr – translate from one character to another • strings – review a binary file for text • od – examine a file for binary contents • head, tail – display begin and end of a file • cat – copy to stdout • cp – copy a file

  20. Finding and Searching • diff – find differences between two text files • find - a tricky but useful command find . -name myfile -print find . - name ‘*name*’ – print –exec “cmd” {} \; • grep - stands for “general regular expression print” Search all files for a pattern: grep -i “lightning system” * grep -v “lightning system” * grep -c “gee whiz” *

Recommend


More recommend