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 894 times
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
- 83