Thursday, May 1, 2014

4:37 PM
Good day!

Hello and welcome to another article on my howto; this time we will learn the basics on how to use the diff and cp commands effectively on *nix.

This is the six part of my howto in "Learning Linux/UNIX"


diff

compare files line by line. Displays a list of changes between two file. The general syntax of diff command as follows:

diff [file name [file name]

-  show difference between two files. Output of this will have something like 1,2c1, 5 then it will display both sets of files on the screen The 4 to 5 in one file to line 4 to 5 in another.

Some basic options for using this command are :

-b          - it ignores blank spaces
-h          - compares it quickly
-s          - report files that are the same
-s [file]  - this is when you want to compare a directory starting at a specific file

You can pipe the output to less command, using the -R or -r option which keeps escape sequences, otherwise displayed incorrectly or discarded by less:

$ diff file1 file2 | less -R


There is also a command to compare 3 files which is :

$ diff3 [options] [file1] [file2] [file3]


cp

copy files and directories. To copy files and directories use the cp command under Linux, UNIX, and BSD like operating systems. cp is the command entered in a Unix / Linux shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.

The syntax is as follows to copy files and directories using the cp command :

cp [file name] [file name] - makes a copy of a file
cp [SOURCE] [DIRECTORY]
cp [options] [SOURCE] [DESTINATION]



Example:

$ cp note notes
$

The file notes is a duplicate copy of note. In this case the origina is not erased like in the mv command

To copy a directory, including all its files and subdirectories, to another directory, enter (copy directories recursively):

Example:   $ cp -R  * /home/index/backup


That's it for today. Thanks for reading guys :-)

FIN!

0 comments:

Post a Comment