1 / 13

The “File System”

The “File System”. Under UNIX, (almost) everything is a “file”: Normal files Directories Hardware Sockets Pipes Things that are not files: Users Groups Processes. File Permissions. Every file has three access levels: user (the user owner of the file)

santa
Download Presentation

The “File System”

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. The “File System” • Under UNIX, (almost) everything is a “file”: • Normal files • Directories • Hardware • Sockets • Pipes • Things that are not files: • Users • Groups • Processes

  2. File Permissions • Every file has three access levels: • user (the user owner of the file) • group (the group owner of the file) • other (everyone else) • At each level, there are three access types: • read (looking at the contents) • write (altering the contents) • execute (executing the contents)

  3. Ownership • Files have two owners • Every file has exactly one user owner • Every file has exactly one group owner • Everyone is a user • Users are in at least one group • Processes have owners, too (known as an “id”) • Every process has exactly one user id • Every process has at least on group id • Users and groups are really just numbers with names • Every username is mapped to a single numeric “uid” • Every groupname is mapped to a single numeric “gid”

  4. Who am I? • Commands that tell you who you are: • whoamidisplays your username • iddisplays your username and groups • Commands that tell you who others are: • finger [<name>]displays info for <name> • id [<username>]displays info for <username> • Commands that change who you are: • su <username>“switch user” to <username> • login login as a different user

  5. Changing Permissions • The “change mode” command: chmod <level><op><permissions>[,…] <filename> <level> string of: u, g, o, a (user, group, other, all) <op> one of +, -, = (gets, loses, equals) <permissions> string of: r, w, x, s, t, u, g, o (read, write, execute, set-id, text, same as user, same as group, same as other), • Examples: chmod u+rwx,go-w foobar chmod g=u,+t temp/ chmod u=rwx,g=rwxs,o= shared/

  6. What is input/output redirection? • Normally, a program’s standard output is displayed on user’s terminal, and its standard input comes from the keyboard. • Redirecting the output of a program means asking the shell to put the program’s output (stdout [C++’s cout]) into a file. • Redirecting the input of a program means asking the shell to feed a file as the program’s standard input (stdin [C++’s cin]). • Note: redirection works with files.

  7. How to redirect program’s output? • To redirect just the standard output:<program> > <FILE> • Example: ls –l > root-folders

  8. > vs. >> • Both > and >> will create the output file, if it doesn’t already exist • If the file does exist, then: • Using > to redirect output will overwrite the output file: • ls > newlisting • printenv > my_environment • Using >> to redirect output will append to the output file • cat ch1 ch2 ch3 > book • cat ch4 ch5 ch6 >> book

  9. Why redirect program’s input? • To run the program repeatedly with the same (or similar input) • Having the program read from standard input may make the program simpler to write.

  10. How to redirect program’s input? • Simple!<program> < <FILE> • Examplesort < my_grades.txthead < really_long_book.txt

  11. Piping • Piping is connecting programs together by using the output of one program as the input to the next. • Syntax:<program1> | <program2> | … | <programN> • A simple example (view a sorted file-listing a page at a time):ls | sort | less • Note: piping deals with the input/output of programs (that is, stdin, stdout, stderr)

  12. Why piping? • Because “the whole is bigger than the sum of its parts. • By combining Unix utilities in a pipeline, you can build tools “on-the-fly” as you need them.

  13. Piping examples • How many .c files are in this directory?ls *.c | wc –l • What files were modified most recently?ls –t | head • What processes am I running?ps auxw | grep <mylogin> • Redirection and piping used together • Sort –r < root-folders | more

More Related