Can someone write a shell script that will delete all files in the folder except those that have the pdf extension?
pdf
This will include all subdirectories:
find . -type f ! -iname '*.pdf' -delete
This will only work in the current directory:
find . -maxdepth 1 -type f ! -iname '*.pdf' -delete
$ ls -1 | grep -v '.pdf$' | xargs -I {} rm -i {}
Or, if you are sure:
$ ls -1 | grep -v '.pdf$' | xargs -I {} rm {}
Or a bulletproof version:
$ find . -maxdepth 1 -type f ! -iname '*.pdf' -delete
This should do the trick:
shopt -s extglob rm !(*.pdf)
ls | grep -v '.pdf$' | xargs rm
This will filter all files that do not end in PDF, and execute RM on them.
Source: https://habr.com/ru/post/1335691/More articles:Sync SVN repo (svnsync) with encoding errors - svnrspec and plugin generation - ruby-on-railsHow to access rdf list members using rdflib (or plain sparql) - pythonHow to increase Solr relevance by contacting a surveyor () - luceneUnable to move li items from one unrelated list to another - jqueryWriting a generic function that Writer can accept, as well as OutputStream - scalaImage of Shard SVG in pieces - imageHow to prevent overwriting jQuery $ .ajaxSetup () parameters? - jqueryHow do I manage when Emacs creates backup files? - emacsChange gradient transparency for transparent arc on HTML5 Canvas - html5All Articles