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?
2 Answers
-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– user35819762014-07-19 00:19:21 +00:00Commented Jul 19, 2014 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'– Gilles 'SO- stop being evil'2014-07-19 00:23:00 +00:00Commented Jul 19, 2014 at 0:23
- But the ctime is written in the ext2_inode struct, isn't it?user3581976– user35819762014-07-19 00:24:24 +00:00Commented Jul 19, 2014 at 0:24
- @user3581976 Yes, but what does this have to do with moving a file?Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2014-07-19 00:26:03 +00:00Commented Jul 19, 2014 at 0:26
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.