Shortcuts

Team-Fly    

Solaris™ Operating Environment Boot Camp
By David Rhodes, Dominic Butler
Table of Contents
Chapter 5.  Shells


This section looks at some more useful shortcuts that are available to users of the Korn Shell.

Home Directory

Instead of having to type in the full path of a user's home directory, you can just type a tilde (~) character followed by the user's login name:

 $ cd ~jgreen $ pwd /export/home/jgreen $ 

Previous Directory

The Korn Shell remembers which directory you where last in so you can move to it without needing to type it in. Just type "cd -":

 $ pwd /really/long/pathname/that/I/can/never/remember $ cd /tmp $ pwd /tmp $ cd - $ pwd /really/long/pathname/that/I/can/never/remember $ 

Aliases

The Korn Shell allows you to create shortcuts to commands. For example, the following will create an alias called ll which will run an ls -l.

 $ alias ll="ls -l" $ 

So now whenever you want to run ls -l you can type "ll" instead. If you type "alias" on its own, you will get a list of all the aliases you have set up within your shell. Creating an alias will only affect you and you can use the unalias command to remove an alias.

 $ unalias ll $ 

When you run alias by itself, you will notice that there are aliases in addition to the ones you set up. You may even notice that the number of aliases can change during a login session. This is because the Korn Shell creates its own aliases, which are called "tracked aliases."

The first time you run a command after logging in, the shell will search for it using your path. Once it has found the location of this command it will create a tracked alias. This means that the next time you run that command, because the tracked alias exists, the shell doesn't need to waste time finding it again using your path. If you change the value of $PATH during the session, all tracked aliases are unaliased to ensure your changes are acted upon. The hash command will display the tracked aliases and you can clear them yourself by running hash -r:

 $ hash ls=/usr/bin/ls $ cat /etc/passwd <lines removed for clarity> $ hash cat=/usr/bin/cat ls=/usr/bin/ls $ hash -r $ hash $ 

    Team-Fly    
    Top
     



    Solaris Operating Environment Boot Camp
    Solaris Operating Environment Boot Camp
    ISBN: 0130342874
    EAN: 2147483647
    Year: 2002
    Pages: 301

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net