Little big man

Unix Insider |  Operating Systems

My series on "small fry" Unix commands did, I admit, overlook perhaps the smallest and also the most used command of them all.

The humble ls command is known by most users as ls, or ls -l. Some even know
ls -F, but the ls command is much more powerful than
these few options. This simple command provides several versions of listing
functionality, at least a few of which you'll surely want to add to your arsenal after
you've read this month's column.

The basic ls command will list the contents of a directory in alphabetical
order and in four columns (usually), as in the following listing:

romany|mjb $ ls
PERSONALITY      copyxp           listen.tar       smit.log
Personly.dat     dwksave          lamage.cpio.Z    smit.script
Power.dt         ezcomp           log.txt          src.224
STARTUP          eztree           mbox             trash
acutime.cbl      fax              mftime.cbl       wisperr.log
alpha_port       holdit.c         mjb.grodin       xerox
amerc            junk.txt         necesito
bin              justio.c         open9ktrack.log
contest.txt      listen           setdwks

So far so good, but this command overlooks a few files that should be on the list.
By default, any file that starts with a period (.) is not displayed.
To get these files to display, use the -a option. A command-line option that is
preceded by a dash (-) is often called a switch. The following is the output of
ls -a:

romany|mjb $ ls -a
.                acutime.cbl      holdit.c         necesito
..               alpha_port       junk.txt         open9ktrack.log
.exrc            amerc            justio.c         setdwks
.profile         bin              listen           smit.log
.profile.031996  contest.txt      listen.tar       smit.script
.sh_history      copyxp           lamage.cpio.Z    src.224
PERSONALITY      dwksave          log.txt          trash
Personly.dat     ezcomp           mbox             wisperr.log
Power.dt         eztree           mftime.cbl       xerox
STARTUP          fax              mjb.grodin
romany|mjb $

This listing includes the dot (.) and double-dot (..) entries, representative of
the current directory and the parent directory, which are part of any
directory, as well as four new files that begin with a period.

The dot (.) and double-dot (..) entries are rarely wanted in a directory
listing. They can be eliminated by using the ls -A option, which does the same
job as ls -a, but skips the dot and double-dot entries, as in the following
listing:

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Operating SystemsWhite Papers & Webcasts

See more White Papers | Webcasts

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness