Copying an entire directory, Renaming and moving files (mv) – HP NonStop G-Series User Manual

Page 102

Advertising
background image

$ ls reports

file2 file3

Note that you do not have to specify file2 and file3 as part of dirname. This is because the
files being copied are retaining their original filenames.

You can use pattern-matching characters when specifying files to be copied. For example, to copy
file1

, file2, file2x, and file3 into /reports, you can use the following command: cp

file* reports

.

To change the name of a file when you copy it into another directory, enter the name of the source
file (the original file), the directory name, a / (slash), and then the new filename. In the following
example, copy file3 into the /reports directory under the new name notes. Then list the
contents of the /reports directory:

$ cp file3 reports/notes

$ ls reports

file2 file3 notes

Copying an Entire Directory

You can copy the contents of an entire directory, including all subdirectories, by specifying the -R
flag on the cp command. But be careful; if the source directory is root (/), the /G (Guardian files)
and /E (remote nodes) directories are included in the copy, which could result in a much larger
copy than you intended. You can prevent the /E and /G directories from being copied by including
the -W NOG and -W NOE flags on the cp command when -R is specified and the source directory
is the root directory. These flags prevent the /G and /E directories from being copied.

For example, To copy a directory tree to another directory, enter:

cp -R dir1 dir2

The dir1 directory tree is created in the directory dir2.

Renaming and Moving Files (mv)

You can use the mv (move) command to:

Rename files

Move one or more files from one directory into another directory

Following is the general format of the mv command:

mv oldfilename newfilename

The oldfilename entry is the name of the file you wish to move or rename. The newfilename
entry is the new name you wish to assign to the original file. Both entries can be names of files in
the current directory or pathnames to files in a different directory. You can also use pattern-matching
characters.

The mv command links a new name to an existing inode-number and breaks the link between the
old name and that inode-number. It is useful to compare the mv command with the ln and cp
commands, which are explained in

“Linking Files (ln)” (page 108)

and

“Copying Files (cp)” (page 100)

.

Refer also to the reference pages for these commands either online or in the Open System Services
Shell and Utilities Reference Manual
.

102 Managing Files

Advertising
This manual is related to the following products: