|
|
| Author |
Message |
cross
|
|
Unix tool o' the day.
|
Sep 18 06:28 UTC 2010 |
Got a favorite Unix tool? Post about it here.
|
| 22 responses total. |
cross
|
|
response 1 of 22:
|
Sep 18 06:59 UTC 2010 |
Early versions of the Unix system were marked by an emphasis on what
came to be known as the tools philosophy: write small programs that
act as a filters, doing one thing and doing it well, and combining
these programs in pipelines in the shell.
It seems in recent years that that philosophy has fallen by the
wayside. As near as I can tell, this started with the introduction of
perl, which was a Swiss Army knife of a tool, capable of doing many
things (some very well, some, well, not so well). However, the basic
Unix tools still ship with almost every Unix (or derivitive) system,
and knowing how to use them effectively is worthwhile. Indeed, it is
possible to combine tools in surprising ways, creating complex yet
elegant systems entirely in shell: often programs that would take tens
or hundreds of lines of C or even Perl can be written in one or two
lines of shell. Often, new filters are prototyped this way.
In this item, talk about your favorite Unix tools: what they do, a
basic introduction to how to use them, and why you like them.
|
cross
|
|
response 2 of 22:
|
Sep 18 07:07 UTC 2010 |
To start, here's a list of some of the basic tools for manipulating
files:
ls - LiSt the files in the current directory (default)
Or as specified by command line arguments.
mv - Move a file to a new name; this is also used for renaming.
cp - Create a new copy of a file or files.
rm - Remove a file or files.
cat - ConCATenate files to the standard output. For each argument,
print its contents on stdout. Defaults to copying the standard
input stream to the standard output stream.
cd - Usually built into the shell, and sometimes called 'chdir'.
This changes the current working directory for the current
process to the specified directory. Defaults to changing
to the user's home directory.
chmod - CHange file MODe. Change the permissions of a file.
chown - CHange file OWNer. Change what user owns a file.
chgrp - CHange file GRouP. Change what group owns a file.
These, and a handful of others, are the basic tools for working with
files. Most of them take many and varied options, some of greater or
lesser utility. Indeed, a general proliferation of options to basic
Unix tools prompted Brian Kernighan and Rob Pike to write
the, "Program Design in the UNIX Environment" paper and given a
presentation at the 1983 Summer USENIX conference called, "UNIX Style,
or cat -v Considered Harmful."
|
tod
|
|
response 3 of 22:
|
Sep 18 20:39 UTC 2010 |
vi
The best editor out there. (Shut your EMACS moufs!) ;)
|
cross
|
|
response 4 of 22:
|
Sep 19 08:55 UTC 2010 |
Hey! There's already a text editor holy war item!
Today's tool of the day is: look(1).
Look takes a sorted file (which defaults to the system dictionary
file) and a prefix, and prints all the strings in the file that start
with that prefix. It does this using a binary search algorithm (hence
the reason the file be sorted. One of the preconditions of a binary
search is that the data be ordered in some meaningful way; since in
general look is looking things up lexiographically, it expects the
data to be sorted that way), and can be quite speedy. It's not so
much of a filter, but can be used at the beginning of a pipeline as a
data source.
|
remmers
|
|
response 5 of 22:
|
Sep 21 22:15 UTC 2010 |
I don't know if ssh is commonly considered a "tool" in the same way
that ls and cat are, but I know that it and its relative scp can be
used in pipelines and other Unixy constructs for processing remote
data locally, without establishing a remote "session" in the usual
sense. A few (probably silly) examples off the top of my
head of things I could do at a local shell prompt in a terminal
window on my laptop. (What the examples actually do is left as
an exercise for the reader.)
(1) ssh grex.org last | grep '\.msu\.edu ' | wc -l
(2) ssh grex.org cat '/bbs/agora50/_*'|grep '^,U.*,cross$'|wc -l
(3) for f in `ssh grex.org ls /bbs/agora33/_*`
do scp grex.org:$f .
done
Yes, I'm sure there are better ways of doing all the above (example 3
is particularly hideous), but I'm just illustrating a point here.
|