whether we're using the A system or the B system:
Bash: alias inva='cd ~tal/projects/inventory/groupa ; export INVSTYLE=A' alias invb='cd ~tal/projects/inventory/groupb ; export INVSTYLE=B'
csh: alias inva 'cd ~tal/projects/inventory/groupa ; setenv INVSTYLE A' alias invb 'cd ~tal/projects/inventory/groupb ; setenv INVSTYLE B'
Instead of using a semicolon, use && to indicate 'Do this next command only if the first one succeeded.' This can be useful to protect against running a command while in the wrong directory. For example, you want to go to a particular directory and write a timestamp to a logfile. However, if the cd fails (the server is unavailable), you don't want to accidentally create a logfile in your current directory.
Bash: alias rank='cd /home/rank/data && date >>.log'
csh: alias rank 'cd /home/rank/data && date >>.log'
Warning
Don't try to turn one OS into another. Aliases are great, but don't overdo it. I've often seen people developing dozens of aliases so that they can type DOS commands in Unix. I think this is a bad idea. You're never going to learn Unix that way, and the next time you are on someone else's machine and don't have access to those aliases, you'll be stuck.
Hostname Shortcuts
If there are particular hostnames you type over and over, you can save some time by creating aliases. For example, if you are often dealing with a machine called ramanujan.company.com, you can create an alias (a DNS CNAME record) called ram.company.com. That's a little less typing.
The problem with this technique is that it can become a maintenance nightmare. If people start to depend on both names, you're stuck maintaining both names. So how can you create an alias that only you know about that won't bother other people?
Typically, if there is a machine I access a lot, I'm accessing it almost exclusively via Secure SHell (SSH). SSH is a secure (encrypted) replacement for
To affect only your SSH sessions, add aliases to the
Not only can I use ssh es where I used to type ssh www.everythingsysadmin.com , but the alias works for all SSH-related commands:
I need to use ssh es so often that I actually created a shell alias to reduce my typing further:
Bash: alias es='ssh es'
csh: alias es 'ssh es'
The result is that I can now type es on the command line to log into the machine, or I can use es to refer to the machine when using
It is tempting to create two-letter aliases for every server in the world. However, you will soon find yourself spending more time remembering your coding system than using it. Personally, I limit myself to a few common machines that I access via SSH.
The ssh_config(5) manpage lists many other configuration options. For example, there is one machine that I occasionally access that requires a very specific combination of options on the command line. (It's a home-grown version of the SSH server that not only doesn't implement all the features but gets confused if you try to negotiate anything it doesn't understand.) The command I have to type to get it just right is: $ ssh -x -o RSAAuthentication=yes -o PasswordAuthentication=yes -o ChallengeResponseAuthentication=no -1 peter.example.net
I could have set up a shell alias, but instead I can modify the SSH configuration, and all systems that use SSH will do the right thing. If a script that I can't modify uses SSH to reach that machine, these settings will still be used.