1 / 38

File System in UNIX

File System in UNIX. Files and Directories in UNIX. The first file in UNIX file system is “root” or “/”. Files and Directories in UNIX (continue.). Home directory (could be named differently) has subdirectory per user called “User Home Directory”

rafe
Download Presentation

File System in UNIX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File System in UNIX

  2. Files and Directories in UNIX • The first file in UNIX file system is “root” or “/”

  3. Files and Directories in UNIX (continue.) • Home directory (could be named differently) has subdirectory per user called “User Home Directory” • Directories can have more subdirectory and files • A file or a directory can be referred to by • Relative path name [a.doc if you are at Documents] • Absolute path name [/home/abuzneid/UNIX/Documents/a.doc}\] • File and directory names are case sensitive

  4. Files and Directories in UNIX (continue.) • To display working directory $ pwd /home/abuzneid/UNIX $ • cd command to change directory $ ls -l total 8 drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:40 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:53 memos drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:53 personal $ cd Documents $ pwd /home/abuzneid/UNIX/Documents $

  5. Files and Directories in UNIX (continue.) $ pwd /home/abuzneid/UNIX $ ls -l total 8 drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:40 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:53 memos drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:53 personal $ cd Documents $ pwd /home/abuzneid/UNIX/Documents $ cd .. $ pwd /home/abuzneid/UNIX $

  6. Files and Directories in UNIX (continue.) $ cd / $ pwd / $ cd /home/abuzneid/UNIX/Documents $ pwd /home/abuzneid/UNIX/Documents $ cd ../.. $ pwd /home/abuzneid $ cd $ pwd /home/abuzneid $

  7. List Files • ls command is used to list files and directories • ls –l displays more information about every file and directory • file type • d for directory • - for file • b, c, p for special file • access made for the owner, group and others • number of links • owner of the file • Size • last modification • file name

  8. List Files (continue.) $ pwd /home/abuzneid/UNIX/Documents $ ls a.doc c.doc $ ls -l total 4 -rw-r--r-- 1 abuzneid 534 14 Oct 8 13:37 a.doc -rw-r--r-- 1 abuzneid 534 14 Oct 8 13:38 c.doc $ cd $ pwd /home/abuneid $ ls UNIX Documents mail memos personal $

  9. List Files (continue.) $ ls -a . .. Documents mail Memos personal $

  10. Creating a Directory: the mkdir command • mkdir command $ pwd /home/abuzneid/UNIX $ mkdir test $ ls Documents mail Memos personal test $ cd test $ pwd /home/abuzneid/UNIX/test $

  11. Copying file from directory to another $ cp UNIX/personal/p1 UNIX/Documents/p11 $ ls UNIX/Documents a.doc c.doc p11 $ cp UNIX/personal/p1 UNIX/Documents $ ls UNIX/Documents a.doc c.doc p1 p11 $ cd UNIX/personal $ pwd /home/abuzneid/UNIX/personal $ ls p1 p2 $ cp p1 p2 /home/abuzneid/UNIX/mail $

  12. Moving Files between Directories $ cd /home/abuzneid/UNIX/personal $ ls -l total 4 -rw-r--r-- 1 abuzneid 534 11 Oct 10 21:46 p1 -rw-r--r-- 1 abuzneid 534 11 Oct 10 21:49 p2 $ mv p1 p2 /home/abuzneid/UNIX/Memos $ cd /home/abuzneid/UNIX/Memos $ ls p1 p2 $

  13. Rename File or Directory • mv is used to rename a file of a directory $ ls -l total 14 drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 Memos drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 memos drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 personal drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:39 test $ mv Memos memos $

  14. Rename File or Directory (continue.) Memos renamed to memos $ ls -l total 12 drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 3 abuzneid 534 512 Oct 10 21:57 memos drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 personal drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:39 test $

  15. Removing a directory: the rmdir command • To remove a directory: • rmdir <directory name> if the directory is empty • rm –r <directory name> if it’s not empty

  16. Removing a directory: the rmdir command (continue.) $ rmdir /home/abuzneid/UNIX/memos rmdir: directory "/home/abuzneid/UNIX/memos": Directory not empty ALL SUBDIRECTORIES AND FILES IN memos MUST BE DELETED FIRST $ cd /home/abuzneid/UNIX/memos $ ls -l total 4 -rw-r--r-- 1 abuzneid 534 11 Oct 8 23:23 p1 -rw-r--r-- 1 abuzneid 534 11 Oct 8 23:29 p2 $ rm * $ ls $ cd .. $ rmdir memos $ ls -l total 10 drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 personal drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:39 test $

  17. Linking Files: the ln command • To have two copies of any file, you can use: • cp to copy it to another file, or • ln to link the file to another file • The disadvantages of cp • Consumes twice as much disk space • Both files always has to be changed if any of them is updated to keep them identical • Number of links to a file is, normally 1 for non-linked, non-directory files • More than one link to a file is possible • Most often, ln is used to link files between directories

  18. Linking Files: the ln command (continue.) • There is two types of links

  19. Linking Files: the ln command (continue.) $ cat aaa Bridgeport Massashusets New Hampshire Vermont $ ls -l total 12 -rw-r--r-- 1 abuzneid 534 46 Oct 10 23:14 aaa -rw-r--r-- 1 abuzneid 534 34 Oct 10 23:12 bbb drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 personal drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:39 test $

  20. Linking Files: the ln command (continue.) $ ln aaa bbb $ ls -l total 14 -rw-r--r-- 2 abuzneid 534 46 Oct 10 23:14 aaa -rw-r--r-- 2 abuzneid 534 46 Oct 10 23:14 bbb drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 personal drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:39 test $ cat bbb Bridgeport Massashusets New Hampshire Vermont $

  21. Linking Files: the ln command (continue.) $ echo one more line >> aaa $ cat aaa Bridgeport Massashusets New Hampshire Vermont one more line $ cat bbb Bridgeport Massashusets New Hampshire Vermont one more line $ rm aaa $ cat bbb Bridgeport Massashusets New Hampshire Vermont one more line $

  22. Linking Files: the ln command (continue.) $ cp bbb ccc $ ln -s ccc ddd $ ls -l total 16 -rw-r--r-- 1 abuzneid 534 60 Oct 10 23:20 bbb -rw-r--r-- 1 abuzneid 534 60 Oct 10 23:25 ccc lrwxrwxrwx 1 abuzneid 534 3 Oct 10 23:26 ddd -> ccc drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:47 Documents drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:54 personal drwxr-xr-x 2 abuzneid 534 512 Oct 8 23:42 TEST drwxr-xr-x 2 abuzneid 534 512 Oct 10 21:39 test $ rm ccc $ cat ddd cat: cannot open ddd $

  23. File Name Substitution $ ls bbb ddd Documents mail personal TEST test $ echo * Documents TEST bbb ddd mail personal test $ echo *.* *.* $ echo a* a* $ echo m* mail $ echo *a* mail personal $ • The asterisk ”*”: substitutes zero or more characters

  24. File Name Substitution (continue.) • “?” matches single character $ ls bbb ddd Documents mail personal TEST test $ echo ??? bbb ddd $

  25. File Name Substitution (continue.) • Matching a single character using square brackets [] • [abc] matches one letter • [!a-z] matches any character except a lower case letter • *[!X] matches any file that doesn't end with the upper case X

  26. standard input standard output command Standard Input/Output • Standard input is the terminal (keyboard) • Standard output is the terminal (display)

  27. skan tty01 Jan 07 07:56 wiem tty52 Jan 07 06:15 samir tty03 Jan 07 09:26 who Standard Input/Output (continue.) • If a sort command is executed without a file name argument, then the command will take its input from standard input

  28. Standard Input/Output (continue.) • Example: $ sort nouha mahdi malek issam salwa issam mahdi malek nouha salwa $

  29. skan wiem samir skan wiem samir sort Standard Input/Output (continue.)

  30. Output Redirection • Output directed to a file instead of standard output • command > ofile directs output to the file ofile • command >> ofile appends output to the file ofile • > ofile creates an empty file “ofile”

  31. Output Redirection (continue.) • Example: $ who > users $ cat users bgeorge pts/16 Oct 5 15:01 (216.87.102.204) abakshi pts/7 Oct 10 22:56 (216.87.102.210) abuzneid pts/9 Oct 10 19:29 (avicenna.102.87.216.in-addr.arpa) xiafeng pts/10 Oct 10 23:16 (Shiva-RAS-Pool-13.uhmc.sunysb.edu) $ echo add one more line >> users $ cat users bgeorge pts/16 Oct 5 15:01 (216.87.102.204) abakshi pts/7 Oct 10 22:56 (216.87.102.210) abuzneid pts/9 Oct 10 19:29 (avicenna.102.87.216.in-addr.arpa) xiafeng pts/20 Oct 10 22:11 (Shiva-RAS-Pool-53.uhmc.sunysb.edu) xiafeng pts/21 Oct 10 22:15 (Shiva-RAS-Pool-55.uhmc.sunysb.edu) xiafeng pts/10 Oct 10 23:16 (Shiva-RAS-Pool-13.uhmc.sunysb.edu) add one more line $ > users $ cat users $

  32. Input Redirection • Input of a file is redirected from a file • command < infile get the input from the file infile • Example: $ who > users $ wc -l users 15 users $ wc -l < users 15 $

  33. Pipes • Connects the output of one command to the input of another command • Example: $ who | wc -l 14 $ ls | wc -l 8 $

  34. who wc -l 5 Pipes (continue.)

  35. Filters • Any program that can take input from standard input, perform some operation on that input, and write the results to standard output • Example: cat and sort are filters

  36. Standard Errors • Terminal is the standard error • In most cases, you never know the difference between standard output and standard error • command 2> efile directs the error to the file efile

  37. Standard Errors (continue.) • Examples: $ ls n* n*: No such file or directory $ ls n* > foo n*: No such file or directory $ ls 2> foo bbb Documents mail TEST users ddd foo personal test $ cat foo

  38. References • UNIX SHELLS BY EXAMPLE BY ELLIE QUIGLEY • UNIX FOR PROGRAMMERS AND USERS BY G. GLASS AND K ABLES • UNIX SHELL PROGRAMMING BY S. KOCHAN AND P. WOOD

More Related