CS 326 Operating Systems

Creating a Shell Alias

You can create small shortcuts or aliases in your shell to make remembering/typing commands easier. Add them to your ~/.bashrc (or ~/.zshrc if you use zsh) to make them persist across sessions:

# This alias will ssh into gojira and forward both the VNC port
# and ssh port to my local machine:
# NOTE: Change the IP address and ports to your own!
alias vm-forward="ssh gojira -L 2222:192.168.122.103:22 -L 10282:localhost:10282 'echo \"Forward Successful\nPress ^C to stop\"; cat'"

# Now I can just run 'vm-forward':
$ vm-forward
Forward Successful
Press ^C to stop

# Another common alias is 'll', which maps to ls -l:
alias ll='ls -l'
$ ll
(a long-format listing of the directory appears)

# Or you could even make 'll' show hidden files too with the -a flag:
alias ll='ls -l -a'

# Here's another one. Maybe you don't like having to type 'man' to get help on
# the various commands and functions:
alias huh='man'

# or even:
alias wtf='man'

# Then you can do:
$ wtf 3 printf