1. Owner
2. Group
3. Others
Syntax
Chmod nnn
Where n is a number from 0 to 7 representing an octal value. First n denotes the permission for owner, next n for group and the last n for others. These numbers are:
4: For Read Permission (r)
2: For Write Permission (w)
1: For Execute Permission (x)
To assign more than one permission, respective octal values are added. As to assign read and write permission, octal value will be the sum of 4 (read) and 2 (write),
0
-
No permission
1
-
Only execute
2
-
Only write
3
2+1
Write & execute
4
-
Only read
5
4+1
Read & execute
6
4+2
Read & write
7
4+2+1
Read, write, execute
Examples:
$ chmod 400
$ chmod 700
$ chmod 777
Another method to assigning permissions to files is symbolic method. To change permissions through this method one must specify:
Type of user (u,g,o).
Type of permission (r,w,x).
Whether the permission is to be granted(+) or revoked(-).
Name of the file.
Examples:
$ chmod u+r
$ chmod a+rw
$ chmod -w
7. mv: Move files.
Syntax:
$ mv
8. cp: Copy files.
Syntax:
$ cp
9. rm: Remove files
Syntax:
$ rm
10. ln: Link files.
‘ln’ command is used for establishing an additional name for the same ordinary file so that it can be shared between two users.
Syntax:
$ ln
11. find: To Find files.
Syntax:
$ find
12. cat: To view files.
Syntax:
$ cat
13. Combine files.
Syntax:
$ cat file1.dat file2.bac file3.pqr>file4
This command merges the files (file1.dat, file2.bac and file3.pqr) into file4 to make a combined file.
14. pr: To Print files.
Syntax:
$pr
15. sort: To Sort the contents of a file.
Syntax:
$ sort
To explain this let us prepare a file:
$ cat temp.dat
Hyderabad
Delhi
Lucknow
Agra
Banglore
Now to arrange file in alphabetic order we can sort the file in this manner :
$ sort temp.dat It will display the following result on the screen
Agra
Banglore
Delhi
Hyderabad
Lucknow
16. cmp: To compare files.
Syntax:
$ cmp
File1 file2 differ: char 280, line 18
Filters and Pipes
A filter is a program that takes input from the standard input, filters it and sends output to standard output. Some of filters provided by UNIX are grep, pg, wc, tr etc.
1.
grep
- search a file for keywords.
Syntax:
$grep regular_expr filename
Example
$grep “abc” emp.txt
2.
pg
- Used to display data one page (screenful) at a time.
Syntax:
$pg filename
3.
wc
- count number of lines/words/characters in file.
Syntax:
$wc [option] filename
Option
-l :Display number of lines
-w :Display number of words
-c :Display number of characters
4.
tr
– Translate or delete characters.
Syntax:
$tr [option] set1 set2
Example:
$tr ‘A-Z’ ‘a-z’| cat a1
5.
uniq -
The uniq command is used to display the uniq(ue) lines in a sorted file.
Syntax:
$uniq file1 file2
OTHER COMMANDS
1.
who -
list users currently logged in.
Syntax
$who
2.
tty -
Displays the terminal pathname.
syntax:
$tty
3.
echo –
display output on the screen. Echo also recognizes the c-language escape sequences that begin with a backslash.
\b : Backspace
\c : Print line without new line
\f : Form feed
\n : New-line
\r : Carriage return
\t : Tab
\v : Vertical Tab
\\ : Backslash
\nnn: It replaces the octal digits nnn to ASCII characters.
4. ps – Show list current processes.
Syntax:
$ps
5. date – display current date.
Syntax:
$date
6. password – Changes the password.
Syntax:
$passwd
7. clear – clear screen.
Syntax:
$clear
8. cal – display calendar.
Syntax:
$cal
$cal month year
$cal year
9. banner – prints the specified string in large letters.
Syntax:
$banner HELLO
10. man - read the online manual page for a command.
Syntax:
$man command
11. less - display a file a page at a time.
Syntax:
$less filename
12. tail - display the last few lines of a file.
Syntax:
$tail filename
13. head - display the first few lines of a file.
Syntax:
$head filename
14. whatis - brief description of a command.
Syntax:
$whatis command
15. id – It shows the user and group ID and corresponding name.
Syntax:
$id
16. uname – This command prints the name of current system on the standard output.
Syntax:
$uname