OK. This is a new blog.
Here's where I talk about some
of my favorite Unix commands under
Linux.
One of my favorites is the sort
utility. Often, I use this one
with a pipe.
Here's an example:
ls -l | sort -k6
This one sorts the output of a
long listing by date.
Therefore, if I'm only interested
in files that have been worked on
recently, I will find these at the
end of the listing.
Note that the -k option for
sort picks a whitespace
separated field as the one to do
the sort on.
That is to say, whitespace is what
separates potential sort keys.
Let's see. The long form of the
ls command is ls -l.
ls -l has 8 fields.
Therefore, ls -l has 8
potential sort keys that you can
sort on.
A sort key is something to sort on.
A filename could be a sort key. A
date could be a sort key.
It is the sixth field that contains
the date. Therefore, -k6 means
sort on the sixth field which is the
date field.
Ok. Putting it all together, I'm taking
an ls command and sending
it to a sort command.
Putting the two commands, ls
and sort, together gives me
something greater than either command alone.
In many ways, that's what Unix is all about.
Putting commands together to make something
greater.
In this case, it is the pipe symbol, which lies
between the two commands, that allows me to put
them together to make something greater.
Make sense?
Here's a wonderful web page that describes in
detail many of the sort utility options:
More About Sort
Ed Abbott
No comments:
Post a Comment