I am starting with a file containing a list of hundreds of files (full paths) in a random order. I would like to list the details of the ten latest files in that list. This
This worked for me:
xargs -d\\n ls -last < list-of-files.txt | head -10
I'm not sure whether this will work, but did you try escaping spaces with \
? Using sed or something. sed "s/ /\\\\ /g" list-of-files.txt
, for example.
Try this:
xargs -a list-of-files.txt ls -last | head -n 10
Instead of "one or more blank characters", you can force bash to use another field separator:
OIFS=$IFS
IFS=$'\n'
ls -las -t $(cat list-of-files.txt) | head -10
IFS=$OIFS
However, I don't think this code would be more efficient than doing a loop; in addition, that won't work if the number of files in list-of-files.txt exceeds the max number of arguments.