Delete File on a Specific File Extension in Ubuntu







To Delete a specific file extension in a directory like files *. doc, *. jpg and *. pdf with a single command by simply using the command :

$ find . -name “FILE-TO-FIND”-exec rm -rf {} \;

OR

$ find . -type f -name “FILE-TO-FIND” -exec rm -f {} \;

the difference between the two commands above is that the first command can delete files and directories, the command can only delete the files.

Example : you want to delete file extension .jpg by type :

$ find . -type f -name “*.jpg” -exec rm -f {} \;

Above command is to delete the files in a specified directory without confirmation, to delete a file with the confirmation user, use the following command:


$ find . -type f -name “*.jpg” -exec rm -i {} \;

Output :

rm: remove regular empty file `./0908.jpg’? y
rm: remove regular empty file `./memories.jpg’? y
rm: remove regular empty file `./important.jpg’? n


Happy Testing.....!!

No comments:

Post a Comment

Please Comment...!!