rmdir


The rmdir command removes one or more directories. The directory must be empty in order to be removed or you must use the -f option. You can also specify more than one directory to be removed. Going back to our earlier discussion on permissions, you must have both write and execute permissions on the parent of a directory to be removed in order to remove it.

As with some of the other commands we have covered, you can use the -i option, which asks you to confirm each directory as it is removed. This means that if you are asked whether you really wish to remove a directory and you respond n, then it is not removed. If you respond y, it is removed.

The order in which you specify that directories are to be removed is significant. If you want to remove both a directory and its subdirectory, you must specify the subdirectory to be removed first. If you specify the parent directory rather than its subdirectory to be removed first, the removal of the parent directory fails because it is not empty.

You can use the -f option to force the removal of directories, an action that performs removal without asking you to confirm them.

The following example performs a long listing of the directory krsort.dir.new , showing that this directory has in it a file called .dotfile . When we attempt to remove this directory with rmdir, a message is displayed informing us that this directory is not empty. The file . dotfile in this directory prevents the rmdir command from removing krsort.dir.new . After removing .dotfile, we are able to remove the directory with rmdir :

 $  ls -al ../krsort.dir.new  total 4 drwxr-xr-x   2 denise   users       1024 Oct 27 18:57 . drwxrwxr-x   4 denise   users       1024 Oct 27 18:40 .. -rw-r--r--   1 denise   users          0 Oct 27 18:56 .dotfile $  rmdir -i ../krsort.dir.new  ../krsort.dir.new: ? (y/n)  y  rmdir: ../krsort.dir.new: Directory not empty $  rm ../krsort.dir.new/.dotfile  $  rmdir -i ../krsort.dir.new  ../krsort.dir.new: ? (y/n)  y  $ 

rmdir has now successfully removed krsort.dir.new because .dotfile is gone:

rmdir - Remove directories.

Options

 

-i

Interactive remove whereby you are prompted to confirm that you wish to remove a directory.

 

-f

Force directories to be removed.

 

-p

If, after removing a directory, the parent directory is empty, then remove it also. This goes on until a parent directory is encountered that is not empty.



HP-UX 11i Systems Administration Handbook and Toolkit
HP-UX 11i Systems Administration Handbook and Toolkit (2nd Edition)
ISBN: 0131018833
EAN: 2147483647
Year: 2003
Pages: 301

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net