I need to process a couple of thousand PDF files sorted alphabietically on their filename ideally from bash
. So from my simple perspective I need to walk a tree of files, stripping off path as I go and then do various grepping, sorting etc
Having seen an answer to a similar question I've tried doing a
tim@MERLIN:~/Documents/Scanned$ basename `find ./ -print`
but that gets messed up by some directory names which have spaces in them - e.g. there is one called General Letters
which acts like a chicken-bone in the works and results in
basename: extra operand ‘Letters’
Try 'basename --help' for more information.
I can't see a way to get find
to strip out the pathname and I would prefer to use find
given its plethora of options to filter on age, size etc. Nor can I see any way to get basename
to cope gracefully with spaces in this context.
I considered using cut
but I can't work out how to get cut
to give me the last field by doing something like cut -d/ <whatever>
I'm sure there must be an easy way to do it: some sort of in-line sed
or awk
script?
I don't particularly want the buggeration of writing a perl/Python script to do it for me as I know I should be able to do it from the command line.
So any simple tips or suggestions?
Updated/Solved
Many thanks to Cyrus the solution is
tim@MERLIN:~/Documents/Scanned$ find . -name *.pdf -printf '%f\n' | sort