-1

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?

Alderson
  • 103

1 Answers1

-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