Thursday, January 14, 2010

The Unix ls Command Sorted by Date

In the past, I've written
about using the sort
command
to sort long
listings by date.

There's an easier way, I've
just learned.

The ls command has a
-t option. You
can use this to sort files by
timestamp.

It looks like this:

ls -t

If you wish to confirm that
the files are really being
sorted by date, you could
turn it into a long listing:

ls -lt

A long listing will not tell
you if files that are more
than 6 months old are in
precise date order to the
minute and to the second.

Here's yet another way to do
it:

ls -t --full-time

The above command will give a
long listing, but with the
modification time in hours,
minutes and seconds included.

Of course, it is the -t that
sorts the listing in timestamp
order.

I believe that the --full-time
option is of recent vintage. I don't
think we ever had it in the old days.

In fact, the only ls that I know
of that has a --full-time option
is GNU ls.

However, since I use Linux currently,
this is not a problem for me. I suspect
that the ls command under Linux is,
in most cases, GNU ls.

What's the lesson in all of this?
Orderliness and Godliness are related.
Commonplace things take on a Godly nature
when then are put into good order.

Just the other day, I used ls -t
on a directory of sub-directories. I was
trying to find the directory I had most
recently worked on. I could not find it.

I was so confused. What could possibly be
wrong? I thought maybe the ls -t was
broken.

Turned out I was logged into linux as
another user and had forgotten that fact.
I had forgotten I was logged into an
account other than my normal user account.

As it turns out, both user accounts have a directory
tree that is a mirror in terms of directory names but
not in terms of file content. However, to all
appearances, the name of the directory and the names
of the sub-directories are the same.

The confusion I felt had over the ls -t not
working later cleared up when I realized I was in
the wrong file hierarchy entirely.

This is what I mean by orderliness and Godliness being
related. A clear mental vision and a clear spiritual
vision often are the result of living an orderly life.

While the ls -t cannot order my entire life,
it can take the chaos out of a small corner of it.

Ed Abbott

No comments:

Post a Comment