Aliases for ls and Other Common Commands 2

Posted by JD 02/04/2012 at 04:00

As I watch someone else using a shell on Linux or OSX, I’m amazed that they haven’t customized the most important command, ls, in any way. ls seems like a pretty easy command, but there are subtle things that you can ask it to do which will provide much more useful information for zero extra work.

root@mail:/etc# ls
default                 localtime            resolv.conf
defoma                  logcheck             rmt
deluser.conf            login.defs           rpc
depmod.d                logrotate.d          sasldb2
dhcp3                   logwatch             securetty
dpkg                    lsb-base             security
e2fsck.conf             lsb-base-logging.sh  services
environment             lsb-release          shadow
esound                  lynx.cfg             shadow-
event.d                 lynx.lss             shells
fonts                   magic                skel

Ok, fine. That’s useful, but hardly informative.

d

root@mail:/etc# ls -F
default/ localtime resolv.conf
defoma/ logcheck/ rmt*
deluser.conf login.defs rpc
depmod.d/ logrotate.d/ sasldb2
dhcp3/ logwatch/ securetty
dpkg/ lsb-base/ security/
e2fsck.conf lsb-base-logging.sh services
environment lsb-release shadow
esound/ lynx.cfg shadow
event.d/ lynx.lss shells
fonts/ magic skel/

See how that provides more information? We can easily see directories, executable programs, soft-linked files, named pipes and other special files. That’s really handy.

I prefer ls -F to be my default and I have a few other ls aliases to make information easier to access. Here they are:


alias ls=‘ls -F’
alias ll=‘ls -l’
alias lm=‘ll |more ’
alias ltm=’ls -alt| more’

Order is important, so the first ls is used for the next ll and the next lm and the last ltm .

A few other aliases that I like are:


alias df=‘df -k’
alias du=‘du -k’
alias h=‘history’
alias moer=‘more’
alias mroe=‘more’
alias psg=‘ps -eaf | grep $*’
alias lp2pg=‘lp -d laser -o number-up=2’

Simple and effective. Yes, I mistype more a lot. I know what I meant, so I let the computer do what I meant. If you ever want to use the non-aliased command, just put use

\ls

That is handy when you’re shoving a list of files into a script, for example.

  1. Gerardo 02/21/2012 at 14:58

    I have to look at log file lists multiple times a day (usually the last one created) so I have ls -ltr aliased to just l. Gotta save those keystrokes.

  2. heynow 03/25/2012 at 22:55

    I like this one:

    alias l=‘ls -lha’