Removing a single file, Removing multiple files, Removing a single file removing multiple files – HP NonStop G-Series User Manual

Page 107

Advertising
background image

Removing a Single File

In the following example, you remove the file called file1 from your home directory. If you aren’t
already in your home directory, return to it using the cd (change directory) command. Enter the
pwd

(print working directory) command to verify that your home directory is your current directory,

and then list its contents. Remember that the system substitutes the name of your home directory
for the notation /u/uname in the example.

$ cd

$ pwd

/u/uname

$ ls

file1 file2 file3 newfile project reports

Enter the rm command to remove newfile, and then list the contents of the directory to verify that
the system has removed the file.

$ rm newfile

$ ls

file1 file2 file3 project reports

You must have permission to access a directory before you can remove files from it. For information
about directory permissions, see

Chapter 10 (page 121)

.

In addition to removing one or more files, rm also removes the links between files and filenames.
The rm command removes the file itself only when it removes the last link to that file.

For information about using the rm command to remove links, see

“Removing Links” (page 110)

.

Removing Multiple Files

You can remove more than one file at a time with the rm command by using pattern-matching
characters.

For example, suppose your current directory contains the following files: receivablejun,
payablejun

, payrolljun, and expensesjun.

You can remove all four of these files with the rm *jun command.

CAUTION:

Be careful when using the * (asterisk) pattern-matching character in the rm command.

For example, the rm * command removes every file in your current directory. Be especially careful
when using * at the beginning or end of a filename. If you type rm * name instead of rm *name,
all your files are removed, not just those whose name ends with name. To help prevent problems,
use the -i flag with the rm command, which prompts you for verification before deleting a file or
files.

You can also use the pattern-matching character ? (question mark) with the rm command to remove
files whose names are the same except for a single character. For example, if your current directory
contains the files record1, record2, record3, and record4, you can remove all four files
with the rm record? command.

When using pattern-matching characters, you may find the -i (interactive) flag of the rm command
particularly useful. The rm -i command allows you to selectively delete files. For each file selected
by the command, you are prompted, allowing you to delete the file or to retain the file.

For example, suppose that your directory contains the files record1, record2, record3,
record4

, record5, and record6.

You could use the -i flag with the rm command as follows:

Removing Files (rm) 107

Advertising
This manual is related to the following products: