Can anyone write a shell script that deletes all the files in the folder except those with pdf
extension?
$ ls -1 | grep -v '.pdf$' | xargs -I {} rm -i {}
Or, if you are confident:
$ ls -1 | grep -v '.pdf$' | xargs -I {} rm {}
Or, the bulletproof version:
$ find . -maxdepth 1 -type f ! -iname '*.pdf' -delete
This will include all subdirectories:
find . -type f ! -iname '*.pdf' -delete
This will act only in the current directory:
find . -maxdepth 1 -type f ! -iname '*.pdf' -delete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With