I'm running ls -l
which brings the following output:
-rw-r----- 1 webadm webgrp 168 Jul 19 16:00 SYNCHRO_20120719_1600.csv
Is there a way to have just get the last two fields? i.e:
16:00 SYNCHRO_20120719_1600.csv
I'm running ls -l
which brings the following output:
-rw-r----- 1 webadm webgrp 168 Jul 19 16:00 SYNCHRO_20120719_1600.csv
Is there a way to have just get the last two fields? i.e:
16:00 SYNCHRO_20120719_1600.csv
try this:
ls -l | awk '{print $(NF-1), " ", $NF}'
It will display the next-to-last and last fields on the line, which is the time and the name of the directory entry and is not dependent on a specific number for a field.
May create problems with names that contains blanks however.
See this page regarding use of 'ls'
for processing, provided by @CharlesDuffy which somewhat undermines the approach above :-) .. so the quick solution presented ought to be viewed in that context.
This should do what you want:
ls -l | awk '{print $8" "$9}'
On a system with GNU date:
for f in *; do
printf '%s %s\n' "$(date +%H:%M -r "$f")" "$f"
done
This will work correctly with filenames with spaces -- or even filenames with newlines, though it won't be possible to distinguish between filename-embedded newlines and record-separated ones. (Use null delimiters if this is important).