Listing files in date order with spaces in filenames

前端 未结 4 1069
一整个雨季
一整个雨季 2020-12-10 23:00

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

相关标签:
4条回答
  • 2020-12-10 23:32

    This worked for me:

    xargs -d\\n ls -last < list-of-files.txt | head -10
    
    0 讨论(0)
  • 2020-12-10 23:45

    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.

    0 讨论(0)
  • 2020-12-10 23:48

    Try this:

    xargs -a list-of-files.txt ls -last | head -n 10
    
    0 讨论(0)
  • 2020-12-10 23:49

    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.

    0 讨论(0)
提交回复
热议问题