Whenever you wish to delete a single file from a directory, you can simply find that file manually and delete it right away. However, when you intend to delete all the files from a directory at once, then it is more convenient to do so via the terminal in Linux. Therefore, in this tutorial, we will be discussing the method of removing all the files from a directory in Linux Mint 21.
Method of Removing all the Files from a Directory in Linux Mint 21:
To remove all the files from a directory in Linux Mint 21, you have to follow the steps mentioned below:
Step # 1: Display all the Files of the Target Directory:
First, we would like to show you all the files of the directory that we wish to remove. For this purpose, we have a directory named “Test” which consists of five different text files. To display the contents of this directory, we will run the following command:
$ ls Test
The contents of our “Test” directory are shown in the image below. We have displayed these contents on the terminal so that we can verify it later on that all these files have been removed successfully.
Step # 2: Remove all the Files from the Target Directory:
Now, for removing all the files from our “Test” directory, we will execute the following command:
$ rm –v /home/system/Test/*
The “-v” flag used in this command will display the progress of the removal of each file from the target directory. The asterisk will tell this command that it has to remove all the files from the path that has been specified within this command.
The output of this command showing the removal of each file from the target directory is shown in the image below:
Step # 3: Check if all the Files have been successfully removed or not:
For verifying if all the files of our “Test” directory have been removed successfully or not, we will run the following command again:
$ ls Test
This time, no output will be displayed on the terminal because there are no files left in the “Test” directory as shown in the image below:
By using the method that has been shared in this article, you can easily remove all the files from any desired directory with a single command in Linux Mint 21. It will hardly take a few seconds for you to achieve this objective.