0

In this tutorial, we will see briefly how to delete files or directories from the command line under Ubuntu or any other Linux-based system. The tutorial will be precisely about using the "rm" and "rmdir" command line utilities.

Warning: You have to be careful when using the "rm" command because any misuse may render your system unusable, so be warned!

1. Deleting Files

You can delete a file from the terminal using this command:

rm filename

If you are not in the current file location, then use this command:

rm /path/to/folder/filename

If you want to remove all files in a folder, then use this command:

rm /path/to/folder/*

If the file you want to delete requires root privileges, then precede your command with "sudo":

sudo rm filename

2. Deleting Directories

You can simply delete an empty directory with the following command:

rmdir foldername

If the directory contains files and sub-folders, then rmdir will not allow you to delete it. The solution is to use the "rm" command to delete a non-empty directory as follows:

rm -r foldername

For root access, precede the command with "sudo":

sudo rm -r foldername

I hope you find this tutorial useful!

Post a Comment

 
Top