4

What is the difference between -c and -t options for the ls Unix command? And how can I sort by date of creation with the ls command?

7

-t lists the file's modification time, which is the last time the file's content was modified (unless the modification time was explicitly set afterwards).

-c lists the file's inode change time, which is the last time the file's metadata was changed (ownership, permissions, etc.) or the file was moved.

Most unix systems do not track the creation date of a file, so most ls implementations don't offer a way to sort by this non-existent timestamp. Under OSX, use ls -tU.

See also How do I do a ls and then sort the results by date created? for more information.

  • Isn't the change of repertory of a file writen in the metadatas? – user3581976 Jul 19 '14 at 0:19
  • @user3581976 No, moving a file doesn't change any of its metadata as such. It only modifies the old directory and the new directory. But it's considered a metadata change anyway: the ctime is updated. – Gilles 'SO- stop being evil' Jul 19 '14 at 0:23
  • But the ctime is written in the ext2_inode struct, isn't it? – user3581976 Jul 19 '14 at 0:24
  • @user3581976 Yes, but what does this have to do with moving a file? – Gilles 'SO- stop being evil' Jul 19 '14 at 0:26
1

From the GNU manpage

-t     sort by modification time, newest first
-c     with -lt: sort by, and show, ctime (time of last modification of
          file  status  information)  with -l: show ctime and sort by name
          otherwise: sort by ctime, newest first

When -c is used with -lt, it will show and sort by file ctimes (instead of modification times). Whether or not your OS records file ctime's depends on the filesystem being used.

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.