Linux ls to show only filename date and size

2018-06-24 18:30:17

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?

Why not use stat instead of ls?

stat -c "%y %s %n" *

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.

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 i

  • Why not use stat instead of ls?

    stat -c "%y %s %n" *

    2018-06-24 18:30:33
  • 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.

    2018-06-24 18:41:55
  • 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...

    2018-06-24 18:46:36
  • You can also use the 'date' command. It is very easy to use:

    date -r [file name]

    2018-06-24 18:50:35
  • where space is defined as the separator and f6 means field 6

    ls -lt | cut -d" " -f6-

    2018-06-24 18:53:55
  • If you wish to use ls, but preserve proper size, you can use:

    ls -Ss1pq --block-size=1

    2018-06-24 19:08:46
  • You can pipeline two commands

    ls -l|cut -d" " -f5

    2018-06-24 19:26:07
  • The simplest answer is to use

    ls -1

    notice that it is a one not an l. This works on Ubuntu, showing only the name of the times.

    2018-06-24 19:32:20
  • ls -s1 returns file size and name only on AIX, not sure about Linux

    2018-06-24 19:32:29