Unixcommandsreference 161210085718
Unixcommandsreference 161210085718
Unixcommandsreference 161210085718
COMMANDS
File Commands
1) cat
2) cp
3) mv
4) rm
cat command:
Ex:
$cat >paypal.txt
--------
--------
--------
ctrl+d
3) Concatenation of files:
cp command:
Example:
$ cp paypal.txt google.txt
mv command:
Example:
$mv paypal.txt funpal.txt --> renaming a file
$mv chennai hyd --> renaming a directory
$mv google.txt hyd -->here the file google moves to hyd
directory
Example:
** Here this commands removes hyd directory even thou its having sub directories
& files.
* But rmdir command removes directory when it should be empty.
* -r is recursive
mkdir: Creating a directory which has set of files & sub directories.
Example:
$mkdir hyd
$mkdir chennai
Example:
$cd chennai
$chennai>
$chennai>cd ..
$ cd --> come back to root directory
Example:
$rmdir chennai
Example:
$ ls
$ ls -S
Examples:
$ ls ? Displays files with one letter
$ ls x* Displays files which are starting with 'x'
$ ls ??? Displays files with 3 letters
$ ls *.out Displays all the files with extension 'out'
$ ls [a-z] Displays single character files which are from a to z
$ ls [a-z]* Displays files starting with a to z
$ rm ? Removes the files with single character
$ rm *.c Removes the files with extension 'c'
$ cp ? chennai Single digit files will be copied into directory 'chennai'
Example:
$ head paypal.txt
This command displays default 10 lines of the file paypal.txt
$ head -n15 paypal.txt
This command displays 15 lines of the file paypal.txt
$ head -n3 paypal.txt
This command displays 3 lines of the file paypal.txt
tail : Used to display last lines of the file.
Ex:
$ tail paypal.txt
This command displays default last 9 lines.
$ tail -n5 paypal.txt
This command displays last 4 lines of the file.
$ tail -n15 paypal.txt
This command displays last 14 lines of the file.
Ex:
$ cal 2011 Displays 2011 calender
$ cal 2 2011 Displays Feb month in 2011 year
ln :
1.This will create link between 2 files.(2nd file should new one)
2. If one file modified another one affected.
Ex:
$ln paypal.txt funpal.txt
Syntax:
$ grep [- optopn] "search patern" Filename [redirection symbol newfilename]
Options:
Example:
Syntax:
options:
Ex1:
Ex2:
$ sort >google.txt
176
2165
8
93
-----
------ [ctrl+d]
$cat google.txt It considered first digit
$sort -n google.txt > yahoo.txt It considered whole
number.
more: This filter command used to display information from multiple files based n
page wise.
It gives an identification of end of file for first file and begining of next file.
Syn:
options:
-p clears the screen and displays next file in the list of files
*note:
cut: Used to cut the required text from a file.It can cut the data on the columns and
feilds.
Syntax:
-f To cut the data in feilds that is that data which is separated by tab.
Ex1:
$ cat>paypal.txt
Hyderabad
Secunderabad
Andhra [ctrl+d]
d
c
d
Hyd
Sec
And
Ex2:
Delhi
Hyderabad
Net
wc: It will count number of lines,worlds,characters in a file.
Syntax:
$ wc [-option] filename
options:
Ex:
$ wc -l paypal.txt
$ wc -w paypal.txt
$ wc -c paypal.txt
uniq: This filter is used to get the uniq or duplicate lines from a file.Data should be in
order.
options:
Ex:
$ uniq -u city1.txt
$ uniq -d city1.txt
$ uniq -c city1.txt
cmp: It comapares 2 files.If files are same it returns promp or else it returns the
message where the difference encountered.
diff: This command compares 2files like cmp.If any difference found in 2 files it
displays those lines.
Ex:
$ cat> paypal.txt
risk
payments
ebay
uv
norkom
$ cat> funpal.txt
foodball
cricket
crems
ebay
payments
Step2: Sort above files and store the data into another 2 different files
1) owners
2) groups
3) others
1) read (r)
2) write (w)
3) execute (e)
r- 4
w- 2
e- 1
-----------
7
-----------
Owners are users whose files gets referred from their respective accounts.
Groups are users whose accounts are dependent on the other accounts.
Others are users who can access the files of other users.
Syntax:
Examples:
Examples:
$ ls -lrta
$ ps -ef
and if we want to find specific process we can use 'grep' with pipe
$ ps -ef | grep -i 'application'
4) How to find Exception in log files available in current directory and how to find number
of occurrence?
5) find all files in current and subdirectories which contains 'log' name?
6) How do you access command line arguments from within a shell script?
Arguments passed from the command line to a shell script can be accessed within the shell script
by using a $ (dollar sign) immediately followed with the argument's numeric position on the
command line.
7) How to tails last 200 lines of any log fine?
$ df -kl
df -kl
Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on