I have a folder that consists of other folders (whose names are unknown), .tar archives and JPEG images. How can I remove everything except .jpeg files?
Asked
Active
Viewed 832 times
-1
Alderson
- 103
- 2
-
1Essentially the same as [Delete all files except files with the extension pdf in a directory](http://askubuntu.com/questions/555318/delete-all-files-except-files-with-the-extension-pdf-in-a-directory) – steeldriver Mar 15 '17 at 14:20
1 Answers
-1
use below command :
ls -1 | grep -v "jpeg" | xargs -I {} rm -rf {}.
ls -1 show all content of your directory -1 will show each file in one line .
grep -v "jpeg" work in reverse mode means just only those file that's not end with "jpeg" .
and last command xargs accept each file name from previous command and pass it to rm command to delete those file.
Bahram
- 73
- 1
- 11