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?

user3581976
  • 3,155

2 Answers2

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.

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.

Sepero
  • 1,599