UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 5: Account Management |
|
||||||||||||||||||||||||||||||||||||
|
The alias command is available for users to create their own styles of shorthand to individual commands and to a series of commands.
Flavors: AT&T, BSD
Shells: bash, csh, ksh, tcsh
Syntax:
ksh: alias [name [=value]] All Others: alias [name [def]]
Aliases can take a rather lengthy command and shorten it to a single word. They are also helpful for turning difficult commands into single-word commands that are easy to understand. You can also pipe (or redirect) a series of commands through and alias to shorten your typing. Global environment variables such as $HOME and $PWD can be used with aliases to make the command more powerful. Here is a list of popular aliases that get used a lot:
alias . 'echo $cwd' # Display the current directory alias .. 'set dot=$cwd;cd ..' # Go up one level alias , 'cd $dot ' # Go back to previous directory alias cd 'cd \!*;pwd' # Change directories and display location
alias l 'ls -lg \!* | cut -c0-79' # ls that fits on one line of 80 col alias la "ls -alg" # long listing with groups included alias lf ls -CFa # mark executables and dirs w/ * & / alias lh "ls -lg .[a-zA-Z]*" # ls -lg HIDDEN (.*) files *only* alias lsd "ls -lgd" # ls -l this directory alias lsds "ls -lg | grep '^d'" # ls -lg all directories *only* alias lsf "ls -lg | grep -v '^d'" # ls -lg all files *only* (no dirs)
alias setvt 'set term=vt100' # Sets the terminal emulation to vt100 alias set220 'set term=vt220' # Sets the terminal emulation to vt220 alias bs "stty erase '^H'" # Set the backspace alias del "stty erase '^?'" # Set the backspace alias cls "clear" # Clear the screen alias ^l xlock -mode random # Lock the screen alias ^k "clear" # Clean the screen
alias a alias # Shorten the alias command alias s source # Source a startup file alias u unalias # Turn aliasing of on a file alias d date # The current time and date alias v vi # vi a file alias date "/bin/date '+DAY: %a, %h %d, 19%y%nHOUR: %r%nDATE: %m/%d/%y%nTIME: %H:%M:%S'" # The date explaned alias qn 'cat - >> /tmp/qn.`date +%y%m%d`' # Write a single line message alias qnl 'cat /tmp/qn.`date +%y%m%d`' # List current daily single line messages. alias h 'history \!* | more' # History command piped to more alias pd pushd # Pushd alias pp pushd #Pushd alias lman 'nroff -man \!* | more' # Display local man page alias mroe more # Displays more if misspelled alias m more # Abbreviated more alias lo exit # Logout alias mkae make # Misspelled Make alias mail /usr/bsd/Mail # To get BSD mail client alias less 'less -E \!*' # A less aliases alias lps '/usr/ucb/lpc stat $1' # status the BSD printer
alias df 'df -k' # Filesystem status alias du 'du -k' # Disk Usage Status alias psg 'ps -ax | grep \!* | grep -v grep' # grep the process table for a pattern alias punt kill # Kill a process
alias psg 'ps -ax | grep \!* | grep -v grep' # find a task by name alias findg 'find . -print | grep $1' # Grep a pattern out of a list of files alias ff 'find . -name \!* -print' # Fast find, list all the files alias rgrep 'find . -type f -print | xargs grep -i $1' # Recursive grep through the files alias open 'chmod go+r' # Open Read access to groups and others alias shut 'chmod go-r' # Deny Read access to groups and others alias +w 'chmod go+w' # Open Write access to groups and others alias -w 'chmod go-w' # Deny Write access to groups and others alias x 'chmod +x' # Add executable permissions
# Remote login to common machines
alias tnugu 'telnet ugu.com' # Telnet to a remote system alias tn911 'telnet UNIX911.com' # Telnet to another remote system alias ftp911 'ftp www.UNIX911.com' # FTP to a remote system alias rocket "rlogin rocket" # Remotely login to a remote system alias trocket "telnet rocket" # Telnet to a remote system alias archie "telnet quiche.cs.mcgill.ca" # Telnet to an application remotely alias r rlogin # Remotely login alias tn telnet # telnet
alias dir ls -l # Display the current directory alias copy cp # Copy a file alias rename mv # Rename a file alias del rm # Delete a file alias help man # Get help
# OpenWindows and X
alias openwin /usr/openwin/bin/openwin # open openwindows alias setrocket 'setenv DISPLAY rocket:0' # Display X back on rocket alias setsaucer 'setenv DISPLAY saucer:0' # Display X back on saucer alias xmail "rsh rocket 'setenv DISPLAY saucer:0; xmail'" # remotely run xmail displaying it back on saucer alias xterm 'xterm -ut' # brings up an exterm without loging it in utmp
# This command will nicely display all the user information NIS/YP knows about a user alias yff "ypmatch \!:* passwd | sed 's/\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^,]*\)[^:]*:\([^:]*\):\([^:]*\)/Login name: \1\\\ Real name: \5\\\ Home directory: \6\\\ Shell: \7\\\ (uid,gid): (\3,\4)\\\ /'"
Speed and ease is what it comes down to. Why type a long command when you can type three or four letters? In the beginning there was no such thing as a desktop, no cut and paste, no click of a mouse button. It was all hands on and the pioneers knew how to make it easier for everyone who enjoys working at the command prompt.
You have to be careful when you begin creating large number of aliases. When you run scripts from your account, some shells have the ability to inherit the variables and aliases that you might have set. You might have a script that wants to remove a series of temporary files that it created, but you have an alias to the rm command that is set up to prompt you for every file that gets removed. If this occurs you have to go through and unalias all the affected commands.
UNIX Hints & Hacks |
|||||||||||||||||||||||||||||||||||||
Chapter 5: Account Management |
|
||||||||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.