Being a Linux/Unix user you must be plying with the file system, and you noticed a directory which is fill with unwanted files and you want to delete all available files from the directory but don’t want to remove the directory from your file system, you can delete the files through GUI(if you have GUI available) or from CLI , so in this tutorial i will show you how you can delete all files from a directory in a very simple command.
To remove (or delete) a file(s) in Linux from the command line, use either the rm(remove) or unlink command.
The unlink command allows you to remove only a single file, while with rm command you can remove multiple files at once. So i will recommend you to use the rm command for deleting the file(s).
Linux Delete All Files In Directory
Here i will use the very known command rm to delete all the files from my directory named Downloads.
- First you open your terminal
- Navigate to the path of the directory from where you want to delete the files
- Run the command rm -rvf /path_of_the_directory/* (here i have used rvf as options and will explain you below how these options will be helpful during the data deletion)
Let us discuss the options i have used here.
-r (recursively) remove directories and their contents recursively
-v (verbose) shows/explain what is being done
-f (force) ignore nonexistent files and arguments, never prompt
You can follow rm command and use the options accordingly, here for example i have used the above options.