In this article, we will be deleting all .txt files from our target directory and all sub-directories below it.
- From the desktop, press Alt+F2 to launch the Run Application window.
- Type: gnome-terminal then press Enter. This will launch a user terminal (similar to Windows command prompt).
- Navigate to the parent directory that contains the files you wish to remove by typing:cd <directory> Press Enter to execute the command.
- Verify that you are in the correct directory by typing:ls -al then press Enter. You should see the target files. The
-aloption is used to display any hidden files. - The next step will completely and irrevocably delete ALL files (in our example, all .txt files) in the current or working directory. Be absolutely certain that this is what you intend to do.
- At the terminal prompt, type:find . -name "*.txt" -exec rm {} \; then press Enter. All .txt files have been removed.
- Type:ls -al then press Enter to confirm that all .txt files were removed.
- This procedure can be used to remove files of any type (assuming that you are the owner of said files). For example, to remove all .html files, you would simply change the statement to:find . -name "*.html" -exec rm {} \; then press Enter.