I am trying to write a command to remove recursively several files with different extensions (*.extension1, *.extension2 etc) from the current directory and all its related sub-directories.
So far I got this command from another post but I couldn't workout how to adapt it to more than one file in the same command line:
find . -name "*.extension1" -type f -delete
Is it as simple as below?
find . -name "*.extension1";"*.extension2" -type f -delete
Just as a side note, these are all output files that I do not need, but not all are necessarily always output so some of the extensions might not be present. This is just as a general clean-up command.
To remove files with a specific extension, we use the 'rm' (Remove) command, which is a basic command-line utility for removing system files, directories, symbolic links, device nodes, pipes, and sockets in Linux. Here, 'filename1', 'filename2', etc. are the names of the files including full path.
Deleting files of a certain file type If you have a folder that contains different file types and want to delete all the files of a certain type - for example, . pdf or . odt - simply enter the command “rm” followed by an asterisk and the file type. In this case, you'll delete all files with the ending .
In Unix-like operating systems such as Linux, you can use the mv command to rename a single file or directory. To rename multiple files, you can use the rename utility. To rename files recursively across subdirectories, you can use the find and rename commands together.
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
find . \( -name "*.extension1" -o -name "*.extension2" \) -type f -delete
find Documents ( -name ".py" -o -name ".html" ) -exec file {} \;
OR
find . -regextype posix-egrep -regex ".*\.(extension1|extension2)$" -type f -delete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With