Vous êtes sur la page 1sur 8

File comparision: -

Cmp : Compares the content of 2 files and generates o/p into std. Output.

à Following are the o/p generated by the cmp command :

à No o/p if the Files are exactly identical.

à Display the byte no. and line no. of the first position where the
files are different.
-l Displays, for each different, the byte no. in decimal and the differing bytes
in the octal.

-s Return only and exit value without generating any output.

The values of the return code are null for identical files,

1) if the files are different ,


2) if the cmp file is not successful in comparing the files.
Eg:- 1. cmp newprog1 old prog1

2. ret_code =’cmp –s newprog1 oldprog1’

if [[$ret_code –eq null]] then

echo “file are identical “

else

echo “files are different “

fi

Comm : If you have files that are sorted and you want to compare them, use the comm. Command.

-can be used to either exclude or include the common lines between the two files.

-def. Output on the std. Output in 3 columns.

 Lines that exist only in the first file.


 Lines that exist only in the second file.
 Lines that exist in both files.
Flag:

-1 – Suppress the display of the first column

-2 – Suppress the display of the second column


-3 – Suppress the display of the third column

Ex: comm file1 file2

-if you are interested only in finding out which lines are identical in file1 and file2,

comm –12 file1 file2

diff: you can compare text files with diff command

flag

-b Ensure that more than one space on tab character is considered as one.

However, reading space or tab characters are processed as –is.

-c Line –

-c Line –

-D string – Create a merged version of the first and second files on the standard output

-Defining string compiles the second file

-e Generate output that can be input to ed to produce the second file from the first file

-I Compare the 2 files ignoring case of letters.

-l – Generate formatted output

- Also generates a summary at the end


-n Generate output in the reverse order of the –e flag

Also generates the count of lines added and deleted

-r Execute this command on all identically named subdirectory of the specified directory.

-S file – Ignore files

- used while comparing directory to ignore filenames


-w Ignore all space and tab character

i.e. Treat them identically for comparison purposes

diff3:

- The diff command compares 2 files


- If you want to compare 3 files at the same time then use diff3 command
- Writes output to standard output that contains the following notations to identify the
differences:
==== means all 3 files differ

====1 means the first file differ

====2 means the second file differs

====3 means the third file differs

flag

-3 produce an edit script that contains only lines containing the differences from the

third file

-E , -X –

-e –

-x –

dir cmp :

-à if u want to compare the contenets of 2 directories

-à this commant compares the names of the files in each directory and generates a list
of filename that exits in only one of the directories followed by filenames that exist
in both and whether they are identical or not .

flag :

-d -à generate a list of files that exist in either of the directories followed by a list of .
files that exist in both directories.

-s -à generates a list of files that exist in eighter of the directories followed by a list of

files that are different.


Sdiff :

Compares 2 files and display o/p on the std o/p in a side-by-side format.

Details of o/p :

-à if the w lines are identical the command displays each line of the 2 files with a series

of space between them.

-à if the line exists in only the first file , a < is displayed at the end of the line.

-à if the line exists in only the second file, a < is displayed at the beginning of the file.

àif the lines from the two files are different , a | is displayed between the lines.

Flags :

-s à if u do not want to display the identical lines

-w no à set the width of the display to no.

-l à display onlu the line from the first file if ht lines from the two files are identical.

-o file à create a marged file from the first and second file depending on a no of

subcommands u can specify.

Touch :

If a file does not exist this command creates it (if u have write access to the directory.
à if a file is already present this command modifies the last modifications time of the

file.

Chmod :

U may have to modify the permission of a firectory or files to either secure then or to make
them accessible to others .

 chmod command to modify the permission for files and directoties

à The permission in unix is specified in and octal no(0 to 7)

à permission for a file or directory can be specified for the folloing:

 Owner : The user who created the file.


 Group : the group to which the owner be longs.
 World of others : Users other than the owner and users in the group to which the owner
belonge.

# ( 4 * value of read bit ) + ( g * value of wrie bit ) + ( 1 * value of execute bit )

This is chmod 744 test file

à owner with read write and execute permission.

à group with read only permission

à others with execute only permission.

# we can use symbolic mode also,

à whose permission ( owner,group or others ) u want to change.

à what permission add,subtract or equals u want to perform on the permission


à The permission ( r,w,x and s on)

write permission to group them è chmod gtw testfile.

à if u want to rewoke the read permission other then è chmod o-r test file.

à if u want to grant the saw sorld è chmod o=g test file.

Chgrp :

If u want to change the group to which the file belongs use the chgrp command.

Ex è To change the owner of testfiel from staff to devp chgrp newgroup testfilename.

Chown :-

If u want to change the owner of a file or directory.

Note :- à on unix systems only the root user can change the owner of a file or directory.

à if u want to change owner of testfile to friwel then

chown friend testfile.

Rm :

To remove files permanently from the disk

Flag :

-i à interactively remove the files ( ask Y or N)

-f à Remove the files without any messages

does not generate any messages the case in which a file does not

exist or u donot has permission to remove files.

-r à Remove files within a directory and directories themselves


recursively.

Mv :

To rename a file and to move from one directory to another refaining the origined file name
( save as copy )

Flages :

-i à move or rename files interaetively

-r à without any messages.

Cp :

Can be used to make a copy of the contents of one or more source files as sypecified target
files if target files already exists it is overwritten with the contents of the cource file.

Flag :

-p à retain the modification date & time as will as permission modes of the source file

-I à interactive mode

-h à follow the symbolic links

-r à copy files under the specified directories and their subdirectory.

Cat :

Cp command allows u to copy one files into another files it does not allow u to copy multiple
files into the sanefile

à to coneatemultiple files into a single files into a single file use the cat command

cat f1 f2 f3 > newfile


flage :

-n à display o/p lines preceded by line nos., numbered sequentially from 1

-b à eliminate line nos., from blank lines when used with the –n flag.

-q à suppress messages if the cat command can not find one or more of the input files.

-v à display nonprintable characters in the file as printable chars

-e à display a $ at the end of each line, when specified with the –v flage.

 cat file1 file2 file3 > newfile


o if the file newfile already exists it is overwritten with the coneatenated files file1
file2 & file3.
 if nesfile already exists & u want to concatenage at the end of the existing file instead of
using the redirection op >use the >> op.
o cat file1 file2 file3 >> newfile.

Rcp :-

Instead of local,

If y want to copy files from one host to another u can use the rcp command to copy files
between the same or different hosts.

If neither thesance non the target file specifies the host name the rcp can behaves the same carry as
the cp command.

Flag :

-p à date

-r à recuersevely

Vous aimerez peut-être aussi