Sie sind auf Seite 1von 28

WWW.DevilsDuke.

Com

UNIX & SHELL PROGRMMING COMMANDS

PATH:
To specify a list of directories separated by ‗:‘

Syntax: $echo $PATH


/bin:/usr/bin:/usr/cse

Man:
Unix online help. Used to view manual page.

Syntax: $man command


$man cat
Output:
Name : cat –concatenate files and print on the standard output.
Synopsis: cat [OPTION] [FILES…]
.
.
.

Echo:
1.Used to display a message.
Syntax: $echo ―message‖
Ex: echo ―UNIX‖
UNIX

2.To evaluate shell variables.


Syntax: $echo $command
Ex: $echo $SHELL
/bin/bash

3.To create files.


Syntax: $echo ―data‖ > filename
Ex: $echo ―Hello‖>myfile

Printf:
An alternative to ‗echo‘ to display formatted output.
Syntax: $printf ―data‖
Ex: $printf ―Hai‖

Script:
Used to record your login session.
Syntax: $script

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Script started, file is typescript.

To exit from script use $exit


$exit
Script done, file is typescript.

Passwd:
To assign a password to your login or to change current password .
Syntax: $passwd:*******
(current) UNIX password:***********
New UNIX password: ***********
Retry new UNIX password:

Uname :
To find the name of the UNIX system.
Syntax: $uname [-options]
Options: -n displays hostname
-r displays version of O.S..
-s displays name of O.S.
$uname
Linux
$uname –n
Localhost.local domain
$uname –r
2.6.9 -1.667smp
$uname –s
Linux
Who:
To know who are currently logged in.
Syntax: $who
Ex:$who
Cse561 console jan30 10:00
Cse567 tty01 jan30 10:06
Cse569 tty02 jan30 10:15

$who am i
To display current login name.

Date:
To display system clock.
Syntax: $date [-options]
Options: +%m displays month in no.
+%h displays month in alphabets
+d . day of month

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
+y last 2 digits of year

Stty:
To set options for a terminal.
Syntax: $stty
Speed 96 baud: Line=0
-brkint -imaxbel
Pwd:
To know your current directory.
Syntax: $pwd
/home/cse
Cd:
To change path of directory.
Syntax: $cd directory
Ex: $pwd
/home/cse
$cd cse1
/home/cse/cse1

Mkdir:
To make a directory .
Syntax: $mkdir directoryname
Ex: $mkdir cse_B

Rmdir:
To remove a directory .
Syntax: $rmdir directoryname
Ex: $rmdir cseB
$ls cseB
No such file or directory.

Ls:
To list files in a directory.
Syntax: $ls [-options]
Options:
-X displays multicolumnar outpt.
-F marks exe with *,directory with / and symoliclinks with @.
-a shows all file including .,..
-R recursive listing
-d listing of directories

$ls
A b c file1
File2 file3 switch.sh w1.sh

Cp:

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
To copy a file or group of files.
Syntax: $cp [-options] sourcefile destinationfile
Ex: $cp fil1 fil2
Options -i interactive copying
-r copying directory structures

Mv:
To move or rename a file or group of files.
Syntax:1:$mv oldname newname
Ex:$mv file2 file1
Syntax:2 $mv files destinationdirectory
Ex: $mv file1 file2 ppk

Rm:
To delete files.
Syntax: $rm [-options] filename
Ex: $rm file3
Options:* deletes all files of a directory.
:- i interactive deletion

Cat:
To create files.
Syntax: $cat>filename
Ex: $cat>myfile
123
456
789
[ctrl+d}

To display files
Syntax: $cat filename
Ex: $cat myfile
123
456
789

More:
Displays the contents of a file on the screen one page at a time.
Syntax: $more [-options] filename
Ex: $more myfile
Options -c cleans screen before displaying page
-d displays error messages
-s squeezes blanks into single one
Output: unix

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
And shell programming

Wc:
To count no. of lines, words, characters in a file.
Syntax: $wc [-options] filename
Ex: $wc myfile
4 3 9 myfile
Options: –l counts only no. of lines
-w counts only no. of words
-c counts only no. of characters

Lp:
To print the contents of the specified files to the default printers.
Syntax: $lp [-options] filenames

Od: od means octal dump


To show the extract contents of a file including the printing and non-printing characters
Syntax: $od [-options] filenames
$od –bc
00000000 165 166 151 170 040 154 141 142
u n i x l a b
Tar: tar means tape archieve
To save & restore the files to &from different types of media such as tape or floppy disk.
Syntax:
For creating backups:
$tar –cvf tarfile/tapedevice directory
For restoring:
$tar –cvf tarfile/tapedevice directory

File Handling Uttilities:


Ln:
To establish more than one link for a file.
Syntax: $oldname newname/directory
Ex:
$ln file1 file2
$cat file1
:bash :no such file or directory
$cat file2
India is my country

Ulimit: user limit


Displays a value as an output,which specifies the largest file that can be created by the user.
Syntax: $ulimit
3045678

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Find:
Recursively checkes for the given files by names or by matching one or more file attributes
Syntax: $find path_list selection_criteria
$find / - name a.out –print
/home/raju/scripts/a.out
/home/Andrew/scripts/reports/a.out

Unlink:
Deletes the name from the filesystem
Syntax: $unlink filename
Ex: $unlink file1
‗ file1‘ deleted

Umask: user mask


Shows the current value of umask which shows the current permissions
Syntax: $umask
022

Security by File Permissions:


Chmod: change mode
To change permissions of a file.
Syntax: chmod [-options] filename
Ex: $chmod u+x flie1
$ls –l file1
-rwxr—r— 1 cse 10 cse may 10 20:30 file1

$chmod ugo+x flie1 ; ls –l file1


-rwxr-xr- x 1 cse 10 cse may 10 20:30 file1

Category operation Permission


u-user + assigns permissions r-read
g-group - removes permissions w-write
o-others = assigns absolute permissions x-excute
a-all

$chmod 666 flie1 ; ls –l file1


-rw-rw-rw-1 cse 10 cse may 10 20:30 file1

$chmod 644 flie1 ; ls –l file1


-rw-r--r--1 cse 10 cse may 10 20:30 file1

Process Utilities :

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Ps:
To display the attributes of a process.
Syntax: $ps [-options]
Ex: $ps
PID TTY TIME CMD
495 tty00 23:12:10 sh
748 tty01 12:10:10 ps
Options :
-e :shows a list of running processes includes system&user.
-f :shows entire details of user process
-u :shows processes of specified user

Disk Utilities:
Df: Disk Free
To find out free disk space.
Syntax: $df
(/dev/root): 612286 blocks 524153 files
Do1(/dev/dsk/dev): 510064 blocks 676613 files
java (/dev/dsk/dev2): 6453518 blocks 614547 files

du: Disk Usage


To find out used disk space.
Syntax: $du [-options] filename
options :
-a,--a :includes contents of all files
-b,--b :prints size in bytes
-c: prints grand total
-h: prints size in human readable form

Text processing Utilities:


Head:
Displays first few lines of the text file.
Syntax: $head filename
Ex: $head myfile.sh
Output:
Who
Who am i
Cat

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Cp
Mkdir
Rmdir

Tail:
Displays flast few lines of the text file.
Syntax: $tail filename
Ex: $tail myfile.sh
Output:
Who
Who am i
Cat
Cp
Mkdir
Rmdir

Sort:
Sorts the contents of afile in ASCII code characters
Syntax: $sort [-opt] filename
$sort –t \| +1 shortlist
5423|barry wood |chairman |admin |08/30/56|160000
9876|bill johnson |director |production |03/12/50|130000
2233|charless harris |g.m. |sales |12/12/52| 90000
2365|john woodcock |director |personnel |05/11/47|120000
5678|Robert Dylan |d.g.m. |marketing |04/19/43| 85000

-n
$sort –t: +2 -3 –n group1
root:x:0:root
bin:x:l:root,bin,deamon
dialout:x:18:root,henry
lp:x:19:lp
adm:x:25:adm,deamon,listen
ftp:x:50:
users:x:200:henry,image,enquiry

-u
$cut –d”|” –f3 shortlist | sort –u |tee desigx.lst
chairman
d.g.m.
director
g.m.

Nl:
Used to prefix line no. for each line in a file.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Syntax: $nl [-options] filename
$ nl desigx.lst
1 chairman
2 d.g.m.
3 director
4 g.m.

-s
$nl –w1 –s: desigx.lst
1:chairman
2:d.g.m.
3:director
4:g.m.

Uniq:
To search duplicate & non-duplicate lines in a file.
Syntax: $uniq [-options] filename
$cat dept.lst
01:accounts:6213
01:accounts:6213
02:admin:5423
03:marketing:6521
03:marketing:6521
03:marketing:6521
04:personnel:2365
05:production:9876
06:sales:1006
Options :
-u displays only non-repeated characters.
$uniq –u dept.lst
02:admin:5423
04:personnel:2365
05:production:9876
06:sales:1006

-d displays only repeated characters


$uniq –d dept.lst
01:accounts:6213
03:marketing:6521

-c displays frequency of each line.


$uniq –c dept.lst

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
2 01:accounts:6213
1 02:admin:5423
3 03:marketing:6521
1 04:personnel:2365
1 05:production:9876
1 06:sales:1006

Cut:
To extract a particular columns/columns ina file.
Syntax: $cut [-options] filename
-c
$cut –c1-4 group1
root
bin:
user
adm
dial
lp:x
ftp:

-f
$cut –d: -f1,3 gorup1
root:0
bin:1
users:200
adm:25
dialout:18
lp:19
ftp:50

Paste:
To combine different text lines of 2 files together.
Syntax: $paste [-options] filename
$paste –d: group1 dept.lst
root:0 : accounts|6213
bin:1 : admin|5423

Join:
For merging of two different files.
Syntax: $join [-options] filename1 filename2
$cat>file1
GIET COLLEGE
RJY

$cat>file2

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
CIET COLLEGE

$join file1 fille2


GIET COLLEGE
RJY
CIET COLLEGE

Tee:
It accepts input from standard input and copies output at 2 different locations.
Syntax: $tee [-options ] filename
$who |tee file1|wc –l
20

Pg:
To view files pagewise.
Syntax: $pg [-options ] filename
Output: It displays the given file information that has longer pages
Comm:
Prints lines that are common in 2 files.
Syntax: $comm [-options ] file1 file2
$comm file1 file2
COLLEGE
Cmp:
To compare between 2 files
Syntax: $cmp [-options] file1 file2
$cmp file1 file2
Lines-1 Bytes-2

Diff:
To display differences between 2 files by comparing line- by – line.
Syntax: $diff [-options ] file1 file2
$diff file1 file2
Lines-1 Bytes-2

Tr:
To translate character set to another.
Syntax: $tr [-options ] string1 string2
$tr ‗G‘ ‗g‘ <file1
gIET COLLEGE
RJY

Back Up Utilities:
Cpio:
Used to copy a file to any back up or retrieve data from the backup drive.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Syntax: $cpio [-options ] filename
-o to create back up on standard output
-i restoring file from backup

Tar:Tape archiver
Options:
-c creates a new archive
-x Extracts files from archive
-t List contents of archive
-r Appends files at end of archive
-u Like r, but only if files are newer than those in archive

Grep: Searching for a patte rn in the given file.


Finds text within a file.
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
$cat>dict
red rojo
green verde
blue azul
white blanco
black negro

$ grep red dict


red rojo

-i: Ingnores the casefor matching.


$grep –i red dict
red rojo

-v:Does not display lines matching expression.


$grep –v red dict
rojo

-n:diplays the line no along with lines.


$grep –n dict
1 red rojo
2 green verde
3 blue azul
4 white blanco
5 black negro

-l:displays file names


$grep –l „ram‟ *.lst

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
ramayan.lst
raghu.lst
ram.lst

-c:counting occurrences
$grep –c director e mp*.lst
Director of the year
Co-director

*(asterisk):
It refers immediately preceding character.
$grep “true*man” emp.lst
Trueman :executive
Truman :g.m.

egrep: extended regular expression.


Search a file for a pattern using full regular expressions.
Syntax
egrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list ] [-f file ] [ strings ]
[ file].
$egrep –E ”true?man” emp.lst
Trueman :executive
Truman :g.m.

fgrep
Search a file for a fixed-character string.
Syntax
fgrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list] [-f pattern-
file] [pattern] [ file]

$fgrep ‘ trueman
>Truman ‘ mp.lst
Output:
Trueman
truman
sed
Sort for Stream Editor sed allows you to use pre-recorded commands to make changes
to text
Syntax
sed [ -n ] [ -e script ] ... [ -f script_file ] ... [ file ... ]

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
PART II
UNIX & SHELL PROGRMMING COMMANDS

PATH:
To specify a list of directories separated by ‗:‘

Syntax: $echo $PATH


/bin:/usr/bin:/usr/cse

man:
Unix online help. used to view manual page.

Syntax: $man command


Ex: $man cat
Output:
Name : cat –concatenate files and print on the standard output.
Synopsis: cat [OPTION] [FILES…]
.
.
.

echo:
I.echo is used to display a message.
Syntax: $echo ―message‖
Ex:$ echo “UNIX”
UNIX

II.To evaluate shell variables.


Syntax: $echo $command
Ex: $echo $SHELL
/bin/bash

III.To create files.


Syntax: $echo ―data‖ > filename
Ex:$echo “Hello”>myfile

printf:
An alternative to ‗echo‘ to display formatted output.
Syntax: $printf ―data‖
Ex: $printf “Hai”
Hai
script:
Used to record your login session.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Syntax: $script

Ex:$script
Script started, file is typescript.

To exit from script use $exit


$exit
Script done, file is typescript.

passwd:
To assign a password to your login or to change current password .
Syntax: $passwd
Ex:$passwd
Old password :***********
New password :***********
Reenter password:***********

uname :
To find the name of the UNIX system.
Syntax: $uname [-options]
$uname
Linux

-n displays hostname
$uname –n
Localhost.local domain

-r displays version of O.S..


$uname –r
2.6.9 -1.667smp

-s displays name of O.S.


$uname –s
Linux

who:
To know who are currently logged in.
Syntax: $who
Ex:$who
cse576 cse576 jan 30 10:00
cse568 cse568 jan 30 10:06
cse569 cse569 jan 30 10:15

$who am i
To display current login name.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com

date:
To display system clock.
Syntax: $date [-options]
Options: +%m displays month in no.
+%h displays month in alphabets
+d day of month
+y last 2 digits of year

stty:
To set options for a terminal.
Syntax: $stty
Speed 96 baud: Line=0
-brkint -imaxbel
pwd:
To know your current directory.
Syntax: $pwd
/home/cse
cd:
To change path of directory.
Syntax: $cd directory
Ex: $pwd
/home/cse
$cd cse576
/home/cse/cse576

mkdir:
To make a directory .
Syntax: $mkdir directoryname
Ex: $mkdir cse_B

rmdir:
To remove a directory .
Syntax: $rmdir directoryname
Ex: $rmdir cse_B
$ls cseB
No such file or directory.

ls:
To list files in a directory.
Syntax: $ls [-options]
Options:
-X displays multicolumnar outpt.
-F marks exe with *,directory with / and symoliclinks with @.
-a shows all file including .,..

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
-R recursive listing.
-d listing of directories.

$ls
A b c file1
File2 file3 switch.sh w1.sh

cp:
To copy a file or group of files.
Syntax: $cp [-options] sourcefile destinationfile
Ex: $cp fil1 fil2
Options -i interactive copying
-r copying directory structures

mv:
To move or rename a file or group of files.
Syntax:1:$mv oldname newname
Ex:$mv file2 file1
Syntax:2 $mv files destinationdirectory
Ex: $mv file1 file2 ppk

rm:
To delete files.
Syntax: $rm [-options] filename
Ex: $rm file3
Options:* deletes all files of a directory.
-i interactive deletion

cat:
To create files.
Syntax: $cat>filename
Ex: $cat>myfile
123
456
789
[ctrl+d}

To display files
Syntax: $cat filename
Ex: $cat myfile
123
456
789

more:
Displays the contents of a file on the screen one page at a time.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Syntax: $more [-options] filename
Ex: $more myfile
Options : -c cleans screen before displaying page
-d displays error messages
-s squeezes blanks into single one
Output: unix
And shell programming

wc:
To count no. of lines, words, characters in a file.
Syntax: $wc [-options] filename
Ex: $wc myfile
4 3 9 myfile
Options: –l counts only no. of lines
-w counts only no. of words
-c counts only no. of characters

lp:
To print the contents of the specified files to the default printers.
Syntax: $lp [-options] filenames

od: od means octal dump


To show the extract contents of a file including the printing and non-printing characters
Syntax: $od [-options] filenames
$od –bc re
00000000 165 166 151 170 040 154 141 142
u n i x l a b
tar: tar means tape archieve
To save & restore the files to &from different types of media such as tape or floppy disk.
Syntax:
For creating backups:
$tar –cvf tarfile/tapedevice directory
For restoring:
$tar –cvf tarfile/tapedevice directory

File Handling Uttilities:


ln:
To establish more than one link for a file.
Syntax: $oldname newname/directory
$ln file1 file2
$cat file1
:bash :no such file or directory
$cat file2
India is my country
ulimit: user limit
Displays a value as an output,which specifies the largest file that can be created by the user.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Syntax: $ulimit
3045678

find:
Recursively checkes for the given files by names or by matching one or more file attributes
Syntax: $find path_list selection_criteria
$find / -name a.out –print
/home/raju/scripts/a.out
/home/Andrew/scripts/reports/a.out

unlink:
Deletes the name from the filesystem
Syntax: $unlink filename
Ex: $unlink file1
‗ file1‘ deleted

umask: user mask


Shows the current value of umask which shows the current permissions
Syntax: $umask
022

Security by File Permissions:


chmod: change mode
To change permissions of a file.
Syntax: chmod [-options] filename
Ex: $chmod u+x flie1
$ls –l file1
-rwxr—r— 1 cse 10 cse may 10 20:30 file1

$chmod ugo+x flie1 ; ls –l file1


-rwxr-xr- x 1 cse 10 cse may 10 20:30 file1

Category operation Permission


u-user + assigns permissions r-read
g-group - removes permissions w-write
o-others = assigns absolute permissions x-excute
a-all

$chmod 666 flie1 ; ls –l file1


-rw-rw-rw-1 cse 10 cse may 10 20:30 file1

$chmod 644 flie1 ; ls –l file1


-rw-r--r--1 cse 10 cse may 10 20:30 file1

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com

Process Utilities :
ps:
To display the attributes of a process.
Syntax: $ps [-options]
Ex: $ps
PID TTY TIME CMD
495 tty00 23:12:10 sh
748 tty01 12:10:10 ps
Options :
-e :shows a list of running processes includes system&user.
-f :shows entire details of user process
-u :shows processes of specified user

Disk Utilities:
df: Disk Free
To find out free disk space.
Syntax: $df
(/dev/root): 612286 blocks 524153 files
Do1(/dev/dsk/dev): 510064 blocks 676613 files
java (/dev/dsk/dev2): 6453518 blocks 614547 files

du: Disk Usage


To find out used disk space.
Syntax: $du [-options] filename
options :
-a,--a :includes contents of all files
-b,--b :prints size in bytes
-c :prints grand total
-h :prints size in human readable form

Text processing Utilities:


head:
Displays first few lines of the text file.
Syntax: $head filename
Ex: $head myfile.sh
Output:
who
who am i
cat
cp

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
mkdir
rmdir
tail:
Displays flast few lines of the text file.
Syntax: $tail filename
Ex: $tail myfile.sh
Who
Who am i
Cat
Cp
Mkdir
Rmdir

Sort:
Sorts the contents of afile in ASCII code characters
Syntax: $sort [-opt] filename
$sort –t \| +1 shortlist
5423|barry wood |chairman |admin |08/30/56|160000
9876|bill johnson |director |production |03/12/50|130000
2233|charless harris |g.m. |sales |12/12/52| 90000
2365|john woodcock |director |personnel |05/11/47|120000
5678|Robert Dylan |d.g.m. |marketing |04/19/43| 85000

-n
$sort –t: +2 -3 –n group1
root:x:0:root
bin:x:l:root,bin,deamon
dialout:x:18:root,henry
lp:x:19:lp
adm:x:25:adm,deamon,listen
ftp:x:50:
users:x:200:henry,image,enquiry

-u
$cut –d”|” –f3 shortlist | sort –u |tee desigx.lst
chairman
d.g.m.
director
g.m.

nl:
Used to prefix line no. for each line in a file.
Syntax: $nl [-options] filename
$ nl desigx.lst
1 chairman
2 d.g.m.

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
3 director
4 g.m.
-s
$nl –w1 –s: desigx.lst
1:chairman
2:d.g.m.
3:director
4:g.m.

uniq:
To search duplicate & non-duplicate lines in a file.
Syntax: $uniq [-options] filename
$cat dept.lst
01:accounts:6213
01:accounts:6213
02:admin:5423
03:marketing:6521
03:marketing:6521
03:marketing:6521
04:personnel:2365
05:production:9876
06:sales:1006
Options :
-u displays only non-repeated characters.
$uniq –u dept.lst
02:admin:5423
04:personnel:2365
05:production:9876
06:sales:1006

-d displays only repeated characters


$uniq –d dept.lst
01:accounts:6213
03:marketing:6521

-c displays frequency of each line.


$uniq –c dept.lst
2 01:accounts:6213
1 02:admin:5423
3 03:marketing:6521
1 04:personnel:2365
1 05:production:9876
1 06:sales:1006

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com

cut:
To extract a particular columns/columns ina file.
Syntax: $cut [-options] filename
-c
$cut –c1-4 group1
root
bin:
user
adm
dial
lp:x
ftp:

-f
$cut –d: -f1,3 gorup1
root:0
bin:1
users:200
adm:25
dialout:18
lp:19
ftp:50

paste:
To combine different text lines of 2 files together.
Syntax: $paste [-options] filename
$paste –d: group1 dept.lst
root:0 : accounts|6213
bin:1 : admin|5423

join:
For merging of two different files.
Syntax: $join [-options] filename1 filename2
$cat>file1
GIET COLLEGE
RJY
$cat>file2
CIET COLLEGE

$join file1 fille2


GIET COLLEGE
RJY
CIET COLLEGE

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com

tee:
It accepts input from standard input and copies output at 2 different locations.
Syntax: $tee [-options ] filename
$who |tee file1|wc –l
20

pg:
To view files pagewise.
Syntax: $pg [-options ] filename
Output: It displays the given file information that has longer pages

comm:
Prints lines that are common in 2 files.
Syntax: $comm [-options ] file1 file2
$comm file1 file2
COLLEGE
cmp:
To compare between 2 files
Syntax: $cmp [-options] file1 file2
$cmp file1 file2
Lines-1 Bytes-2

diff:
To display differences between 2 files by comparing line- by – line.
Syntax: $diff [-options ] file1 file2
$diff file1 file2
Lines-1 Bytes-2

tr:
To translate character set to another.
Syntax: $tr [-options ] string1 string2
$tr „G‟ „g‟ <file1
gIET COLLEGE
RJY

Back Up Utilities:
cpio:
Used to copy a file to any back up or retrieve data from the backup drive.
Syntax: $cpio [-options ] filename
-o to create back up on standard output
-i restoring file from backup

tar:Tape archiver
Options:

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
-c creates a new archive
-x Extracts files from archive
-t List contents of archive
-r Appends files at end of archive
-u Like r, but only if files are newer than those in archive

grep: Searching for a pattern in the given file.


Finds text within a file.
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | - f FILE] [FILE...]
$cat>dict
red rojo
green verde
blue azul
white blanco
black negro

$ grep red dict


red rojo

-i: Ingnores the casefor matching.


$grep –i red dict
red rojo

-v:Does not display lines matching expression.


$grep –v red dict
rojo

-n:diplays the line no along with lines.


$grep –n dict
1 red rojo
2 green verde
3 blue azul
4 white blanco
5 black negro

-l:displays file names


$grep –l „ram‟ *.lst
ramayan.lst
raghu.lst
ram.lst

-c:counting occurrences
$grep –c director e mp*.lst

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
Director of the year
Co-director

*(asterisk):
It refers immediately preceding character.
$grep “true*man” emp.lst
Trueman :executive
Truman :g.m.

egrep: extended regular expression.


Search a file for a pattern using full regular expressions.
Syntax
egrep [-b] [-c] [-h] [- i] [- l] [-n] [-s] [-v] [-x] [ -e pattern_list ] [- f file ] [ strings ]
[ file].
$egrep –E ”true?man” emp.lst
Trueman :executive
Truman :g.m.

fgrep
Search a file for a fixed-character string.
Syntax
fgrep [-b] [-c] [- h] [- i] [-l] [-n] [-s] [- v] [- x] [ -e pattern_list] [- f pattern-file]
[pattern] [ file]

$fgrep „ true man


>Truman „ mp.lst
Output:
Trueman
truman
sed
Sort for Stream Editor sed allows you to use pre-recorded commands to make changes to text
Syntax
sed [ -n ] [ -e script ] ... [ - f script_file ] ... [ file ... ]

$sed „3q‟ emp.lst


5423|barry wood |chairman |admin |08/30/56|160000
9876|bill johnson |director |production |03/12/50|130000
2233|charless harris |g.m. |sales |12/12/52| 90000

-n:It suppressing duplicate line printing.

$sed –n „1,2p‟ emp.lst

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com
5423|barry wood |chairman |admin |08/30/56|160000
9876|bill johnson |director |production |03/12/50|130000

!:It reverses line selection criteria.


$sed –n „3,$!p‟ e mp.lst
5423|barry wood |chairman |admin |08/30/56|160000
9876|bill johnson |director |production |03/12/50|130000

Context addressing
$sed –n „/from: /p‟ $HOME/mbox
From: Praveen ppraveen576@gmail.com
From: Monica monicamady@vicky.com
From: Sudheer sudher9025@gamil.com

$sed „s/|/:/g‟ e mp.lst |head -2


5423:barry wood :chairman :admin :08/30/56:160000
9876:bill johnson :director :production :03/12/50:130000

$sed „s^ *|^|^g‟ e mp.lst | head -2


5423|barry wood|chairman|admin|08/30/56|160000
9876|bill johnson| director| production|03/12/50|130000

$sed –n „s/marketing/s/director/me mber/p‟ emp.lst


6521|derrry o‘drien |member |marketing |09/26/45|125000

$ sed –n „/^.\{49\}45/p‟ e mp.lst


6521|derrry o‘drien |member |marketing |09/26/45|125000
2345|james wilcok |g.m. |marketing |03/12/45|110000

$echo “henty Higgins” | sed „s/\(henry\)\(higgins)/\2, \1/‟


Higgins, henry

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com


WWW.DevilsDuke.Com

For more online bits,ppts,projects,tech news,social media news visit us at www.devilsduke.com

Das könnte Ihnen auch gefallen