Download presentation
Presentation is loading. Please wait.
Published byDella Gray Modified over 9 years ago
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: –whoami displays your username –id displays your username and groups Commands that tell you who others are: –finger [ ] displays info for –id [ ] displays info for Commands that change who you are: –su “switch user” to –login login as a different user
5
Changing Permissions The “change mode” command: chmod [,…] string of: u, g, o, a (user, group, other, all) one of +, -, = (gets, loses, equals) 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: > 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! Example sort < my_grades.txt head < 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: | | … | 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 Redirection and piping used together –Sort –r < root-folders | more
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.