Why can't I use a command like this to find all the pdf files in a directory and subdirectories? How do I do it? (I'm using bash in ubuntu)
ls -R *.pdf
How would I then go about deleting all these files?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Why can't I use a command like this to find all the pdf files in a directory and subdirectories?
bash to all matching files in the current directory, before executing
How do I do it? (I'm using bash in ubuntu)
find is your answer.
find . -name \*.pdf
is recursive listing of pdf files.
-iname is case insensitive match, so
find . -iname \*.pdf
lists all .pdf files, including for example
Also, you can use ls for limited number of subfolders, for example
ls *.pdf */*.pdf
to find all pdf files in subfolders (matches to bar/foo.pdf, not to bar/foo/asdf.pdf, and not to foo.PDF).
If you want to remove files found with find, you can use
find . -iname \*.pdf -delete