18

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?

12

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

  • Just note that stat -c '%w %x %y %z' filename.txt gives you creation, access, data modification, status change. In human-readable format. – meridius Nov 13 '18 at 11:45
15

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
  • 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. – Mads Skjern Jul 28 '15 at 12:49
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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