Comparing files (diff) – HP NonStop G-Series User Manual

Page 104

Advertising
background image

$ ls

file1 file3 newfile project reports

Finally, list the contents of the /reports directory to verify that the command has moved the file
there:

$ ls reports

file2 file3 notes

You can use pattern-matching characters to move files. For example, to move file1 and file3
into /reports, you could enter the following command:

$ mv file* reports

Now list the contents of your home directory to verify that file1 and file3 have been moved:

$ ls

newfile project reports

Now copy file1, file2, and file3 back into your home directory. The . (dot) in the following
command line specifies the current directory, which, in this case, is your home directory:

$ cp reports/file* .

Verify that the files are back in your home directory:

$ ls

file1 file2 file3 newfile project reports

Finally, verify that file1, file2, and file3 are still in the /reports directory:

$ ls reports

file1 file2 file3 notes

You should be aware that when you use mv to move an entire directory, all subdirectories of the
source directory are included in the move. If the source directory is the root directory (/), the /G
(Guardian files) and /E (remote files) are included in the move, which could result in a much larger
move than you intended. You can prevent the /E and /G directories from being moved by including
the -W NOG and -W NOE flags, respectively, on the mv command when the source directory is the
root directory. These flags prevent the /G and /E directories from being moved.

Comparing Files (diff)

You can compare the contents of text files with the diff command. The diff command compares
the files and displays the differences between them. Use the diff command when you wish to
pinpoint the differences in the contents of two files that are expected to be somewhat different.

The general format of the diff command is as follows:

diff file1 file2

The diff command scans each line in file1 and file2, looking for differences. When it finds
a line (or lines) that differ, it reports the following:

Line number of line in which a difference occurs

Whether the difference is an addition, a deletion, or a change to the line

If the change is caused by an addition, diff displays the following form:

l[,l] a r[,r]

where l is a line number in file1 and r is a line number in file2. The a indicates an addition.
If the difference is a deletion, diff specifies d, and if it is a change to a line, diff specifies c.

104 Managing Files

Advertising
This manual is related to the following products: