8.10. Useful ls Aliases
Because ls is one of
the most commonly used Unix commands and provides numerous options,
it's a good idea to create aliases for the display
formats that best suit your needs. For example, many users
always want to know about their
"hidden" files.
That's reasonable -- they're
just as important as any other files you have. In some cases, they
can grow to take up lots of room (for example, some editors hide
backup files), so it's worth being aware of them.
Rather than typing ls -a every time, you can
create a convenient alias that supplies the -a
or -A option (Section 8.9)
automatically:
$ alias la="ls -aF"
% alias la ls -aF
or:
$ alias la="ls -AF"
% alias la ls -AF
Two things to note here. First, I recommend using
la as the name of the alias, rather than just
renaming ls. I personally think
it's dangerous to hide the pure, unadulterated
command underneath an alias; it's better to pick a
new name and get used to using that name. If you ever need the
original ls for some reason,
you'll be able to get at it without problems.
Second, what's
with the -F option? I just threw it in to see if you
were paying attention. It's actually quite useful;
many users add it to their ls aliases. The
-F option shows you the
type
of file in each directory by printing an extra character after each
filename. Table 8-1 lists what the extra character
can be.
Table 8-1. Filename types listed by ls -F
Character
|
Definition
|
(nothing)
|
The file is a regular file.
|
*
|
The file is an executable.
|
/
|
The file is a directory.
|
@
|
The file is a symbolic link (Section 10.4).
|
|
|
The file is a FIFO (named pipe)
Section 43.11).
|
=
|
The file is a socket.
|
For example:
% la Alias includes -F functionality
.cshrc .login Mail/ performance/
.emacs .mailrc mail.txt powertools@
This says that Mail and
performance are directories.
powertools is a symbolic link (ls
-l will show you what it's linked to).
There are no executables, FIFOs, or sockets in
this directory.
[If you use tcsh, it has a built-in
ls called ls -F, which not only
prints this extra information, but also supports color (Section 8.6) and
caching of filesystem information for speed. I generally put
alias ls ls -F in my
.cshrc. -- DH]
You may want this version instead:
$ alias la="ls -aFC"
% alias la ls -aFC
The -C option lists the files in
multiple columns. This option isn't needed with
ls versions where multicolumn output is the normal
behavior. Note, however, that when piped to another command,
ls output is single-column unless
-C is used. For example, use ls -C |
less to preserve multiple columns with a paged listing.
Finally, if you often need the full
listing, use the alias:
$ alias ll="ls -l"
% alias ll ls -l
This alias may not seem like much of a
shortcut until after you've typed it a dozen times.
In addition, it's easy to remember as
"long listing." Some Unix systems
even include ll as a regular command.
--DG and ML
 |  |  | 8.9. Showing Hidden Files with ls -A and -a |  | 8.11. Can't Access a File? Look for Spaces in the Name |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|