Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recursively delete multiple files with different extensions?

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.

like image 371
Fiztban Avatar asked Jun 05 '14 11:06

Fiztban


People also ask

How do you delete all files with a specific extension in the working directory?

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.

How do I remove all files from a specific extension in Linux?

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 .

How do I remove multiple file extensions in Linux?

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.

How do you remove all recursive files from a directory?

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.


1 Answers

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
like image 195
Jayesh Bhoi Avatar answered Sep 20 '22 20:09

Jayesh Bhoi