Ubuntu rmdir

The rmdir is a command to remove an empty directory in Ubuntu. Here is an example on how to run Ubuntu rmdir from the terminal:


luzar@ubuntu:~/linux$ ls -l
total 4
drwxr-xr-x 2 luzar luzar 4096 2011-05-20 03:58 tutorials
luzar@ubuntu:~/linux$ rmdir tutorials/
rmdir: failed to remove `tutorials/': Directory not empty
luzar@ubuntu:~/linux$


See the warning, rmdir: failed to remove `tutorials/': Directory not empty. The rmdir cannot remove the directory because it's not empty. So we need to remove all contents in the directory before we can use the Ubuntu rmdir command again. Use ls command with -l option to list the directory content:


luzar@ubuntu:~/linux$ ls -l tutorials/
total 0
-rw-r--r-- 1 luzar luzar 0 2011-05-20 03:58 ubuntu
luzar@ubuntu:~/linux$


So there's only one file in the directory. How do I know that it is a file? I'll tell you later because now we need to remove the file. Use rm command to remove file in Ubuntu. It doesn't matter if it's empty or not.


luzar@ubuntu:~/linux$ rm tutorials/ubuntu
luzar@ubuntu:~/linux$ ls -l tutorials/
total 0
luzar@ubuntu:~/linux$


The directory is empty now. Let's try to delete the directory again.


luzar@ubuntu:~/linux$ cd ..
luzar@ubuntu:~$ pwd
/home/luzar
luzar@ubuntu:~$ ls
linux
luzar@ubuntu:~$ rmdir -p linux/tutorials/
luzar@ubuntu:~$ ls -l
total 0
luzar@ubuntu:~$


I use the cd .. command to move to upper directory. Then I use pwd command to check my current working directory. See that this time I used rmdir with -p option. The -p option means please remove the DIRECTORY and its ancestors. That's why I move up one level earlier.

That's all about Ubuntu rmdir. Or that's the only thing I know about rmdir, to be more accurate.