I'm trying to list only non-image files, searching only in the most recent 500 files. So I run
ls -t | head -500 | file | grep -v 'image'
which isn't right: it displays a help message. Changing it to
ls -t | head -500 | xargs file | grep -v 'image'
I now sometimes get the output I want, but if the filename has spaces in it—for example Plutonian\ Nights\ -\ Sun\ Ra.mp3
—then xargs
will run file Plutonian
, file Nights
, etc.
How do I either help xargs
see the spaces, or otherwise accomplish what I'm trying to accomplish?
Best Answer
Using
xargs
, it can be done in this way:But
xargs
is so yesterday. The cool kids useparallel
today. Using parallel, it would be:See. No use of -print0 and -0.
parallel
is really smart by itself.UPDATE
For listing only the most recent 500 files, your command would be:
Important
In case your parallel is old and above syntax doesn't work, then install the new version of parallel as explained here: http://www.gnu.org/software/parallel/parallel_tutorial.html