awk '{print $9}' the last ls -l column including any spaces in the file name

后端 未结 7 1331
星月不相逢
星月不相逢 2020-12-29 08:13

How would I get awk to output the whole file name in ls -l if some of the files have spaces in them. Usually, I can run this command:



        
7条回答
  •  萌比男神i
    2020-12-29 08:16

    If you still insist on the ls -l instead of find or other tools, here is my solution. It is not pretty and destructive:

    1. Destroy $1 .. $8 by setting them to "" via a for loop
    2. That leaves a bunch of spaces preceding $9, remove them using the sub() command
    3. Print out the remaining
    ls -l | awk '{for (i = 1; i < 9; i++) $i = ""; sub(/^ */, ""); print}'
    

提交回复
热议问题