Listing files in date order with spaces in filenames

房东的猫 提交于 2019-11-28 11:50:22

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.

Try this:

xargs -a list-of-files.txt ls -last | head -n 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.

This worked for me:

xargs -d\\n ls -last < list-of-files.txt | head -10
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!