24

Can I get both ctime and atime in ls output? Seems I can only pass one --time=ctime or --time=atime argument (the second is ignored). Is there any other way?

3 Answers 3

13

You could run stat -c '%x %z' filename.txt

2
  • Just note that stat -c '%w %x %y %z' filename.txt gives you creation, access, data modification, status change. In human-readable format.
    – meridius
    Commented Nov 13, 2018 at 11:45
  • On a Mac this would look more like stat -f "%c %a %N" filename.txt (change it to %Sc %Sa for human readable).
    – Noumenon
    Commented Mar 6, 2023 at 18:42
20

If you are only parsing values out of ls, you can use stat instead:

# stat -c %x,%z,%n *
2011-01-11 06:09:04.000000000 -0500,2011-01-11 02:43:52.000000000 -0500,sqlupdate.sh
2011-01-11 06:09:04.000000000 -0500,2011-01-12 02:43:55.000000000 -0500,file.tar.gz
2011-01-11 06:09:04.000000000 -0500,2011-01-11 02:43:52.000000000 -0500,mysql_password.txt
2011-01-17 02:43:49.000000000 -0500,2011-01-12 13:40:48.000000000 -0500,public_html

Where:

 %x     Time of last access
 %z     Time of last change
 %n     Name of file
1
  • Just to be sure I understand the answers here. It is possible with ls to display any of access, modified and change time, but not more than one at a time. Because that is both really surprising, and very annoying. Commented Jul 28, 2015 at 12:49
6

with findyou get very close to what ls -lprovides:

# find . -maxdepth 1 \
     -printf "%M %u %g %s\t%Ab %Ad %AH:%AM\t%Cb %Cd %CH:%CM\t%P\n"

you have access to ctime (%C), atime(%A) and modification time (%T). read man find to find more info.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .