The document discusses file permissions in Linux/Unix systems. It covers:
1. The chmod command is used to set permissions and has three components - user, operation, and permission type.
2. There are two ways to set permissions with chmod - symbolic mode using letters and absolute mode using octal values.
3. Permissions on directories determine what users can do to files within that directory, like deleting or modifying. File permissions determine what users can do to the file's content.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
11 views
Lab 3 Commands
The document discusses file permissions in Linux/Unix systems. It covers:
1. The chmod command is used to set permissions and has three components - user, operation, and permission type.
2. There are two ways to set permissions with chmod - symbolic mode using letters and absolute mode using octal values.
3. Permissions on directories determine what users can do to files within that directory, like deleting or modifying. File permissions determine what users can do to the file's content.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14
File permissions
chmod command contains three components:
User Category: U=user, G=group, O=other (world) Operation to be performed: Grant (+), Denial(-) and assign (=) Type of permission: read, write, execute File permissions
There are two ways to set permissions when
using the chmod command: Symbolic mode: testfile has permissions of -r--r--r-- U G O* $ chmod g+x testfile ==> -r--r-xr-- $ chmod u+wx testfile ==> -rwxr-xr-- $ chmod ug-x testfile ==> -rw--r--r-- $ chmod a=r testfile -r--r--r-- U=user, G=group, O=other (world) File permissions cont.
Absolute mode: We use octal (base eight) values represented like this: Letter Permission Value R read 4 W write 2 X execute 1 - none 0
For each column, User, Group or Other you can set
values from 0 to 7. Here is what each means: 0= --- 1= --x 2= -w- 3= -wx 4= r-- 5= r-x 6= rw- 7= rwx File permissions cont.
Numeric mode cont:
Example index.html file with typical permission values: $ chmod 755 index.html $ ls -l index.html -rwxr-xr-x 1 root wheel 10 May 14 06:20 index.html
$ chmod 644 index.html
$ ls -l index.html -rw-r--r-- 1 root wheel 10 May 14 06:20 index.html Inherited permissions
Two critical points:
1.The permissions of a directory affect whether someone can see its contents or add or remove files in it. 2.The permissions on a file determine what a user can do to the data in the file. Example: If you don't have write permission for a directory, then you can't delete a file in the directory. If you have write access to the file you can update the data in the file. grep Command
grep - "general regular expression parser“
• Search command for UNIX. • Used to search for text strings and regular expressions within one or more files. grep family grep - uses regular expressions for pattern matching fgrep - file grep, does not use regular expressions, only matches fixed strings but can get search strings from a file egrep - extended grep, uses a more powerful set of regular expressions, generally the fastest member of the grep family Common grep Command Options
grep [options] pattern [files]
-c Display the number of matched lines. -h Display the matched lines, but do not display the filenames. -i Ignore case sensitivity. -l Display the filenames, but do not display the matched lines. -n Display the matched lines and their line numbers. -v Display all lines that do NOT match. -w Match whole word. -e Matches multiple patterns grep -c “Alex” my_file.htm grep –c “Alex” my_file your_file grep -e “bat” -e “but” my_file.htm grep and Wildcards
Dot ( . ) – matches 1 character
Asterisks ( * ) – matches multiple characters Examples: grep b.g myfile finds the words “big”, “bag”
grep b*k myfile finds the word “back”, “buck”,
“book” grep and Regular Expressions
A "regular expression" is a pattern that
describes a set of strings. Regular expressions are used when you want to search for specific lines of text containing a particular pattern. grep and Regular Expressions ^ (Caret) = match expression at the start of a line, as in ^A. $ (Dollar Sign) = match expression at the end of a line, as in A$. \ (Back Slash) = turn off the special meaning of the next character, as in \ ^. [ ] (Brackets) = match any one of the enclosed characters, as in [aeiou]. Use Hyphen "-" for a range, as in [0-9]. [^ ] = match any one character except those enclosed in [ ], as in [^0-9]. grep and Regular Expressions grep bob files {search files for lines with ‘bob'} grep '^bob' files {‘bob' at the start of a line} grep ‘bob$' files {‘bob' at the end of a line} grep '^bob$' files {lines containing only ‘bob'} grep '\^b' files {lines starting with '^b', "\" escapes the ^} grep '[Bb]mug' files {search for ‘Bmug' or ‘bmug'} grep 'B[O][bB]' files {search for BOB, BOb} grep '^$' files {search for empty lines} grep '[0-9][0-9]' files {search for pairs of numeric digits} Piping in linux/ pipe command
The Pipe command lets you use two or more
commands such that output of one command serves as input to the next. In short, the output of each process acts as input to the next one like a pipeline. The symbol '|' denotes a pipe. Pipes help you combine two or more commands at the same time and run them consecutively. $ls -l | grep "Aug" -rw-rw-rw- 1 john doc 11008 Aug 6 14:10 ch02 -rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07 -rw-rw-r-- 1 john doc 2488 Aug 15 10:51 intro -rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros $