Removing multiple directories, Removing your current directory, Removing your current – HP NonStop G-Series User Manual
Page 119

costs tasks
The /project2 directory still contains three subdirectories: /costs, /reports, and /tasks.
You can remove these directories by using pattern-matching characters if you wish. Once these
subdirectories are removed, you can delete the /project2 directory, as described in
Your Current Directory ” (page 119)
Removing Multiple Directories
You can remove more than one directory at a time with the rmdir command by using
pattern-matching characters.
For example, suppose that you are in the /project2 directory and wish to remove two
subdirectories: /costs and /tasks. To do so, enter the rmdir *s?s command. Then enter the
ls
command to verify that the /project2 directory contains no entries:
$ rmdir *s?s
$ ls
Entering the rmdir command with the * (asterisk) character alone (rmdir *) removes all empty
directories from your current directory. Use the * pattern-matching character with care.
Removing Your Current Directory
You cannot remove your current directory (that is, the directory you are currently working in), nor
can you remove a directory or subdirectory that contains your current directory. To remove your
current directory, you must first move into a directory above it.
The directory /project2 is empty. To remove /project2, first move to your home directory,
which is the parent directory of /project2. Then use the rmdir dirname command to remove
/project2
and enter ls to confirm the removal:
$ cd
$ rmdir project2
$ ls
file1 file2 file3 project record1 record6 reports
Your home directory no longer contains the /project2 directory.
Removing Files and Directories Simultaneously (rm -r)
The rmdir command removes only directories, not files.
You can use the rm command with the -r (recursive) flag to remove files and directories at the
same time.
The rm -r command first deletes the files and subdirectories (along with the files they contain)
from the specified directory, and then deletes the specified directory itself. As a result, this command
should be used with caution.
Following is the format for the rm -r command:
rm -r pathname
The pathname entry can be either the absolute pathname or relative pathname of the directory
that you wish to remove. You can also use pattern-matching characters to specify files.
CAUTION:
Be careful when using the -r flag. For example, entering the rm -r * command
from your home directory deletes all files and directories to which you have access.
When using the rm -r command to remove files or directories, it is a good idea to include the
-i
flag in the command line, in the following form:
Removing Directories (rmdir)
119