Saturday, August 17, 2013

Deleting a directory in Linux

To delete a directory in Linux OS, we use the command :
rmdir
or
 rm 

The syntax is :

rmdir [directory path]
But the rmdir or rm command works only for an empty directory. For deleting a directory, we need to perform what is called a Recursive Delete. Recursive Delete deletes the directory, its sub-directories and all the files contained within. To perform a recursive delete, we use the command :

rm -rf [directory path]

Obviously it doesn't make sense to have to run a command if you could do it manually. But sometimes, you cannot delete directories as a normal user and you will get an error saying you do not have necessary permissions. So you need to be a super user to do so. Use the command as follows :

sudo rm -rf [directory path]

3 comments: