Removing directories (rmdir), Removing empty directories – HP NonStop G-Series User Manual

Page 118

Advertising
background image

Removing Directories (rmdir)

When you no longer need a particular directory, you can remove it from the file system with the
rmdir

(remove directory) command. This command removes only empty directories; that is, only

directories that contain no files or subdirectories. For information about removing files from
directories, see

“Removing Files and Directories Simultaneously (rm -r) ” (page 119)

and

Chapter 8

(page 93)

.

You cannot remove a directory while it is your current directory. See

“Removing Your Current

Directory ” (page 119)

for more information.

Following is the general format of the rmdir command:

rmdir dirname

The dirname entry is the name, or pathname, of the directory you want to remove.

Before working through the examples in the following subsections, create three subdirectories in
the directory /project2, as described here.

First use the cd command to move to the directory /project2, making /project2 your current
directory.

From the /project2 directory, use the mkdir command to create the directories /schedule,
/tasks

, and /costs. Finally, list the contents of the /project2 directory.

$ cd project2

$ mkdir costs schedule tasks

$ ls

costs reports schedule tasks

Next use the cd command to return to your home directory:

$ cd

$ pwd

/u/uname

Removing Empty Directories

The rmdir command removes only empty directories. If you try to remove a directory that contains
any files or subdirectories, the rmdir command gives you an error message, as the following
example shows:

$ rmdir project2

rmdir: project2: Directory not empty

Before you can remove the directory /project2, you must first remove the contents of that
directory. In the following example, the cd command makes /project2 your current directory,
and then the ls command lists the contents of /project2:

$ cd project2

$ ls

costs reports schedule tasks

Next, remove the directory /schedule from the current directory, and then list the remaining
contents of the /project2 directory:

$ rmdir schedule

$ ls

118

Managing Directories

Advertising
This manual is related to the following products: