Monday, November 5, 2007

Using ls to look at files by the date they were added to your system

The ls -l command displays fairly detailed information about the files in the directory you are in. It displays the date the file was last modified -- which is known in Unix as the mtime of the file. However, there are other date/time attributes on the file that might be more useful. The mtime doesn't necessarily apply to the file's last modification time on your system -- so if you've deployed an install package, it will probably show you the last time the files were modified on the system on which the package was built. This is sometimes useful for telling how old a version you have, but not really useful for much else.

The ctime is the change time, but this is not the same as the file's modification time (mtime). The ctime is the last time the file's status was changed. So, oftentimes this will be the date the file was added to your system. Very useful indeed!

This command will display the file's ctime in the date spot instead of the file's mtime:

ls -lc filename

This will show you the directory sorted by the ctime:

ls -lct

This will show you the directory sorted reverse by the ctime:

ls -lctr

No comments: