Monday, April 29, 2024
61
rated 0 times [  61] [ 0]  / answers: 1 / hits: 89309  / 3 Years ago, sat, may 8, 2021, 2:05:04

My goal is deceptively simple (at least to me). I wish to take the output of ls -l or ls -lh and select just one field.



I am looking for this to be as bulletproof as possible, by which I mean, assume that filenames can have a variable number of spaces, not everything in the field has the same length, etc.



Bonus points for having a script that will take the name of the the field (or even just a field number), and then return the contents of the field.



I want to turn



enter image description here



into:



enter image description here


More From » command-line

 Answers
3

Try ls -l | awk '{print $7}'.



awk selects columns so it's perfect for this task.


[#36967] Sunday, May 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rowbris

Total Points: 419
Total Questions: 122
Total Answers: 101

Location: Norway
Member since Mon, May 23, 2022
2 Years ago
;