UNIX COMMANDS
1. $ LOGNAME : It displays the current user
information
2. $PWD : present working
directory
3. $DATE : It displays the
system date & time
4. $clear : To clear the screen
5. $cal :
It current month and year
6. $cal 2000 : Displays the 2000 year calendar
7. $cal 8 2006 : displays the 8th
month of 2006
8. $exit or
logout : exit from current
user account
9. $ who : displays the all
user in who are currently working on server
10. $finger :
displays the all user who are currently working on server with more information
11. Who am I :
displays current user information?
12. Which or where :
displays the location of the given command
Syn: $which pwd
13. Cat : is use to create
new files or to open exiting files or to append data to the exiting files
Create: cat >filename
-----------
-----------cntl+d(save file)
Redirect: cat file1 file2 file3 >file4--------àredirect output
Append: cat >>filename--------à
single file $cat file1
file2 file3 >>EMP------àmulti files
-----------
-----------cntl+d
Open file: cat
<filename-----àopen single file $cat file1, file2,
file3----------àto open multi files
Cat
>.filename---------for hidden files
14. Touch :
It is used to create an empty file i.e. 0 byte file
SYN:
$ touch filename
$
touch file1 file2 file3---------à create multiple
files
15. rm :
deleting files or directories
EX
rm
filename----------------àdeleting single file
rm
-i filename--------------àdeleting files with confirmation
rm
file1 file2----------------àdeleting multiple files
rmdir
dirname--------------àdeleting the directory but the directory must be
empty
rm -r dirname-------------àdeleting
directory recursively (i.e. with tree str)
rm
–ri dirname-------------àremove directory with confirmation
rm
* ---------------------à
it delete all files
rm -I *--------------------àdeletes
all files with confirmation
rm
t* ---------------------àit deletes whose file name starts with ‘t’
16. mkdir : creating directories
Syn:
$mkdir dirname
Sys:
$Mkdir .dirname------------àhidden directory
17. Cd : change directory
Sys:
$cd abc
$pwd------/home/testing/abc
using above cmd we can come out from abc now we at //home/testing
cd..---------------------------àto
come out from current directory
cd../..------------------------àparent
directory
cd/---------------------------àit
changes to root directory
cd
~-------------------------àit changes to home directory
18. cp :copy
source file to target file
Ex
Cp
emp1 emp2----------------------àemp1 to 2 coping
Cp
–I m1 m2-------------------------àoverwrite
confirmation? Y
Cp
–R source directory to target directory-------cp –R abc xyz
19. mv :
it is used to rename or move file
Ex:
mv exiting filename new filename
Mv emp .emp----------------------àto
hide
Mv
.emp emp--------------------àto unhide
20.ls :
display, list of all files & directories in a current directory
21.ls|more : display, list of all files &
directories page by page
22. ls –a : display, list of all files
& directories including hidden files and dirctories also in current
directory
23. ls –r :
display list of all files &
directories reverse order in a current directory
24. Ls –R : display list of all files &
directories recursively in a current
directory
25. Ls –t : display list of all files
& directories according to date of
creation in a
current directory
26. Ls –F : display all list of files
& directories, link files, .exe
files in a current directory
27. Ls -x : display all list of files
& directories according to width
wise in a current directory
28. Ls -L : display all list of files
& directories in a current directory in
a long list i.e. 9 fields
1) File
types
[1) -- For regular file
ii) d—for dir file
III) L—for link file
IV)
b—for block of files
V) c— for char files] [here IV, V is
device files]
2) File permissions
3) no. of links
4) owner name
5) group name
6) file size in bytes
7) Date
8) time
9) filename
30. cmp : it compares two files char by
char
Sys:
cmp file1 file2
Ex:
a1: Hello Good Morning
a2: Hello Good Evening
If two lines are same then return nothing
If two files are different then it
displays line number with character position
31. comm. : It display common lines b/w 2 files
Syn: Comm File1 file2
32. diff :
it display different lines b/w 2 files
33. pg :
it display the file contents page by page
Syn:
$Pg filename
34. more : it also display the file
contents page by page
Syn:
$more filename
34. head :it display the 1st n lines
from the file
Sys: $ head –n filename
35. tail :
it display the last n lines from file
Syn:
tail –n filename
Tail +n filename----àit
indicates nth line to end of the line
Ex: tail +30 file (in this file total no of
records is 100) it displays the records from 30th to 100
36. wc :
it counts the no of lines, words, chars in a given file.
Syn:
$wc filename
i) wc –l
filename------------------àit gives the no of lines in a given file
ii) wc –w
filename---------------àit gives the no of words in a given file
III) wc –c
filename---------------à it gives no. of char in file
iv) wc -lw
filename--------------à it gives the no of lines and character in a given
file
Comparing files:
1]$cmp: It compares two files char by char.
Syn:$cmp dile1 file2
Same---doesn’t return any value.
Diff---return char position&line no.
2]$comm: It displays comman lines b/w 2 files.
Syn:$comm file1 file2
3]$diff: It displays diff lines b/w 2 files.
Syn:$diff file1 file2
Zip files:
1]$gzip: To zip the file.
Syn:$gzip filename
Ex:$gzip sample
Sample.gz
2]zcat: it is used for to open zip file in readable format.
$zcat sample.gz
3]$gunzip: To unzip the file.
Syn:$gunzip filename
Ex:$gunzip sample.gz
Sample
FILE ACCESS PERMISSIONS (FAP)
-rwx------
drwxr--r--
-rwx-w--w-
d - Directory
w - Wrire
r - Read
x - Executable
Note: Without write permissions we can’t copy, remove,
modify, move, crate
drwxrwxrwx
7 7 7
Directory – 777
File –
666
Default Directory Permissions – 755
Default File Permissions –
644
Read – 4
Write – 2
Executable – 1
Total Permissions 7
TO CHANGE AND MODIFY THE PERMISSIONS
1. Numeric Method
2. Symbolic Method
1. Numeric Method:
Syntax: $ chmod [permissions] <file/Directory>
Ex: $ chmod 700 Dir2
$ chmod 640 file1
To check the changed permission use the command: ls - l
To change the permissions and check the permission using
following command
Ex: $ chmod -c 750 Dir2
To change the permission with Directories and subdirectories
with regressively
Ex: $ chmod -R 755 Dir2
To Change the present working Directory Permissions
Ex: $ chmod - R 750
Note : Plz don’t' try this command on the system
2. Symbolic Method
User – u
Group – g
Others – o
All – a
Read – r
Write – w
Execute – x
Syntax: $ chmod [options] <File/Directory>
To Add Write permission to Group and Others
Ex: $ chmod g+w, o+w Dir1
To Remove the Write Permission to User
Ex: $ chmod u-w Dir1
To Remove the Write and execute permissions to Group and
Others
Ex: $chmod g-r, g-x, o-r, o-x Dir1
Append the Write permissions to all
Ex: $chmod u+w, g+w,
o+w Dir1
(or)
$chmod a+w Dir1
UMASK (User File Creation Mask)
- cuting, remove, hidden
By Default umask value is 022
Directory File
777 666
022 022
755 644
GREP Commands:
If you want to save the output in a file in the current
directory named new file, enter:
Ex: fgrep dog my file | cut -f5
-d" " | sort > new file
$ grep –n
<file> - To display record number
$ grep
-i<file> - To ignore record
$ grep –c
<file> - To count in how many records expression
$ grep –E
<file> - To search for multiple expression
$ grep –L
<file> - It give the file name and which the
regular expression
$ grep –r
<file> - To search regressively and present working
directory
$ grep –w
<file> - To search for the exact match for the word
$ grep –s
<file> - To suppress errors
$ grep “jai”
<file> - It prints the expressive
record which
have got the “jai”
$ grep –n “jai”
<file> - It display the record number and
expression what we
give “jai”
$ grep –in “jay”
<file> - It ignore and prints the record
“Jay”
$ grep –E “jay prem”
<file> - It search for multiple
expressions and
prints the record
$ grep –l “jay”* - It displays the filename which the
“Jay” expression is
Process Related Commands:
df:
This command is used to find disk space of the file System.
Syn: df
df -h:
This command is used to find disk space of the human Readable format.
Syn:df -h.
df -k:
This command is used to find disk space of the Kilobites format.
Syn:df -k.
df -kh:
This command is used to find disk space of the Kilobites in human Readable format.
Syn:df -kh.
df -a:
It displays all the data
Syn:df -a.
df -i
This command is used to find disk space in Inodes ,I used, Ifree ,I use .
Syn:df -i.
du:
This command is used to find disk usege of the file System.
Syn: du
du -S
It displays include Sub directories.
Syn: du -S.
du -s:
It display include Total directories.
Syn: du -s
du -a or du -all
It display the space that each file is taking include Sub directories.
Syn: du-a.
du -Sh .
It display include current directory space.
Syn: du -Sh .
du -Sh *
It display all the data in directories.
Syn: du -Sh *
ps:
This is used to current running process.
Syn: ps
ps-aux:
This is used to all the current running process.
Syn:ps-aux.
Top:
It is used find the cpu usage and memory usage.
Syn:Top.
LoadAverage:
The Load Average represenation the Average System load over a period of time.Which Representing the system load during the Last 1,5,15.
Syn:uptime.
nohup:
This command will execute the process even if logout from the System.
Syn:nohup cmd.
vmstat:
netstat:
This command is used to display the all Ipaddrss and portnumber.
Syn:netstat.
Syn:netsat -anp.
find:
This command is used to searching ths files.
Syn:file -/ name Filename.
tar:
tar command is primary archive utilty.
Syn:tar cmd.
tar -cvf:
This is used to create the all files stored in one file (or) Backup file purpose you can use this one.
syn:tar -cvf file.tar f1 f2 f3 f4.
tar -xvf:
This is used to exteance the all files stored in one file.
Syn :tar -xvf file.tar files.
Telnet:
This is used to connect the remote serers.
Syn:telnet ipaddress.
Ftp:
This is used to transfor the files in one system to another system.
Syn:Ftp Ipaddress.
Ping:
This is used to cheek the connectivity.
Syn:ping Ipaddress.
Tracert:
It is used to which can show you the path a packet information takes from your computer to specify .It will list all the routes it passes through until reaches the destination.
Syn:Tracert mediacollege.
Scp:
This is used to secure copy the files in unix system.
Syn:scp filename root@ipaddress filename.
crontab
********
It is a job scheduling tool
crontab -l (it lists all crontab jobs)
crontab -e (edit cront jobs)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
crotab -e
esc+i
-----
------
------
esc: w -save
: q -quit with out save
: wq -save and exit
: wq! - over write