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?
Difference between `ls -c` and `ls -t`
fileslstimestamps
Related Solutions
The attributes as handled by lsattr
/chattr
on Linux and some of which can be stored by quite a few file systems (ext2/3/4, reiserfs, JFS, OCFS2, btrfs, XFS, nilfs2, hfsplus...) and even queried over CIFS/SMB (when with POSIX extensions) are flags. Just bits than can be turned on or off to disable or enable an attribute (like immutable or archive...). How they are stored is file system specific, but generally as a 16/32/64 bit record in the inode.
The full list of flags is found on Linux native filesystems (ext2/3/4, btrfs...) though not all of the flags apply to all of FS, and for other non-native FS, Linux tries to map them to equivalent features in the corresponding file system. For instance the simmutable flag as stored by OSX on HFS+ file systems is mapped to the corresponding immutable flag in Linux chattr
. What flag is supported by what file system is hardly documented at all. Often, reading the kernel source code is the only option.
Extended attributes on the other hand, as set with setfattr
or attr
on Linux store more than flags. They are attached to a file as well, and are key/value pairs that can be (both key and value) arbitrary arrays of bytes (though with limitation of size on some file systems).
The key can be for instance: system.posix_acl_access
or user.rsync.%stat
. The system
namespace is reserved for the system (you wouldn't change the POSIX ACLs with setfattr
, but more with setfacl
, POSIX ACLs just happen to be stored as extended attributes at least on some file systems), while the user
namespace can be used by applications (here rsync
uses it for its --fake-super
option, to store information about ownership or permissions when you're not superuser).
Again, how they are stored is filesystem specific. See WikiPedia for more information.
For files, ls -l file
shows (among other things) the size of file
in bytes, while du -k file
shows the space occupied by file
on disk (in units of 1 kB = 1024 bytes). Since disk space is allocated in blocks, the size indicated by du -k
is always slightly larger than the space indicated by ls -kl
(which is the same as ls -l
, but in 1 kB units).
For directories, ls -ld dir
shows (among other things) the size of the list of filenames (together with a number of attributes) of the files and subdirectories in dir
. This is just the list of filenames, not the files' or subdirectories' contents. So this size increases when you add files to dir
(even when files are empty), but it stays unchanged when one of the files in dir
grows.
However, when you delete files from dir
the space from the list is not reclaimed immediately, but rather the entries for deleted files are marked as unused, and are later recycled (this is actually implementation-dependent, but what I described is pretty much the universal behavior these days). That's why you may not see any changes in ls -ld
output when you delete files until much later, if ever.
Finally, du -ks dir
shows (an estimate of) the space occupied on disk by all files in dir
, together with all files in all of dir
's subdirectories, in 1 kB = 1024 bytes units. Taking into account the description above, this has no relation whatsoever with the output of ls -kld dir
.
Best Answer
-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, usels -tU
.See also How do I do a ls and then sort the results by date created? for more information.