Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I use ls in linux to get a listing of filenames date and size only. I don't need to see the other info such as owner or permission. Is this possible?

share|improve this question
add comment

5 Answers 5

up vote 17 down vote accepted

Why not use stat instead of ls?

stat -c "%y %s %n" *
share|improve this answer
1  
This is nice, but it does have the "environment too large" /"argument list too long" problem potentially. –  Mat Oct 7 '11 at 7:02
1  
:-) Just a proof of concept. In Real Life[tm] this will be a find . -type f -print0 | xargs -0 stat -c "%y %s %n" –  f4m8 Oct 13 '11 at 7:27
1  
To format the output of stat, you can add width information to the format string like C printf function, e.g. "%y %8s %n", it's not documented, but seems works (coreutils 8.17, Fedora 18) –  LiuYan 刘研 Apr 7 '13 at 7:47
add comment

You can also use the 'date' command. It is very easy to use:

date -r [file name]

share|improve this answer
add comment

where space is defined as the separator and f6 means field 6

ls -lt | cut -d" " -f6-
share|improve this answer
add comment

You could always use another utility like awk to format the output of ls1:

/bin/ls -ls | awk '{print $7,$8,$9}'


1.Yes, generally, you shouldn't parse the output of ls but in this case the question specifically calls for it...

share|improve this answer
    
That doesn't print the file size though. And it only prints the first part of filenames with whitespace in them. And it can fail if ls is aliased (say alias ls='ls -i'). You really should take a lot of care if you want to go about parsing ls output. –  Mat Oct 7 '11 at 6:16
    
I had the file size in there and then edited it out (vague moment) - I'll restore it. And I agree about all the caveats re parsing ls, but that is what the OP wanted... –  jasonwryan Oct 7 '11 at 6:31
    
I disagree, the OP wants the filenames, not the first part of filenames if the filename happens to have whitespace. (Using /bin/ls would avoid the alias problem.) –  Mat Oct 7 '11 at 6:34
    
That is understood implicitly: what is stated explicitly is that OP wants a solution with ls which we both agree is not going to satisfy the whitespace requirement. The /bin/ls suggestion is a good one. –  jasonwryan Oct 7 '11 at 6:44
add comment

You can get a lot of control about how you list files with the find utility. ls doesn't really let you specify the columns you want.

For example:

$ find . -maxdepth 1 -printf '%CY%Cm%Cd.%CH%CM\t%s\t%f\n'
20111007.0601   4096    .
20111007.0601   2   b
20111001.1322   4096    a

The argument to the printf action is a detailed in the manpage. You can choose different time information, what size you want (file size or disk blocks used), etc. You can also make this safe for unusual file names if further processing is needed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.