Unix tip: Useful Unix aliases
It's easy to create aliases and some of them can save you a lot of time and trouble. Stored in one of your startup files (e.g., .profile), they can provide a modestly easier environment for your work. This week, we'll look at a bunch of especially useful aliases.
If you use functions, but lose track of what you've called them, you can use this handy alias for listing them:
boson# alias functions='set | grep "()"'
Type "functions" on your command line with this function in effect and you might see something like this:
boson# functions SHOW_ARGC=() SHOW_ARGV=() SHOW_LINENO=() SHOW_SOURCE=() STACK=() GROUPS=()
You can also set up aliases for helping you to move around in the file system and find your way back. Some of these just save you a bit of typing, but consider how often you type cd commands.
alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias back='cd $OLDPWD'
The last alias in the list above might prove particularly useful if you're working between two directories and just want to bounce back and forth between the two of them. Each time you move, $OLDPWD takes on the value of the directory you were just in.
There are a number of ways to get a listing of only the directories in your current file system location. This one seems the snappiest:
alias dirs='ls -d */'
To shorten what you have to type to get long listings or categorized listings, you might try these:
alias ll='ls -l' alias lf='ls -F' alias l='ls -al'
The "lf" alias will provide a file listing with / at the end of directory names and @ at the ends symbolic links. The "l" alias will, of course, provide a long listing of all files and with a nice savings on keystrokes.
A useful extension of the aliases shown above is to include a pipe to more so that you are sent one screenful of output at a time. This alias has been very nice to use:
alias lm="ls -al | more"
To be prompted before you remove files, you can use one of the following aliases. I generally don't want to have to type "y" for each and every file deletion, so I prefer leaving rm as is and using del when I want the extra check. Of course you can always just use "rm -i".
alias rm='rm -i' alias del='rm -i'
You can use the same idea with other aliases that return a lot of text. It's a good idea to use a consistent naming scheme (i.e., adding an "m") so the aliases are easier to remember. Here's an example with the history command:
alias h=history alias hm="history | more"
You can set up a case-insensitive grep command and save a little typing with this "gi" alias.
Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world
jfruh
Apple syncing patent can't come soon enough
pasmith
New Twitter features borrow from 3rd party clients
Esther Schindler
Open Source Changes the Software Acquisition Process
mikelgan
How to set up continuous podcast play on the new iTunes
David Strom
Five important Windows 7 mobility features
sjvn
Guard your Wi-Fi for your own sake
Sandra Henry-Stocker
Grepping on Whole Words
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.













Aliases etc.
Thanks - there were some useful aliases in your latest article. You might like this function, which I find very useful when looking for permission errors:lsdup() {
here=$(pwd)
while true
do
print "$(ls -ld) $PWD"
cd ..
[ $PWD = "/" ] && break
done
cd $here
}
moving to previous directory
To go back to the previous directory I just use "cd -". No special alias is required. But what if you're working amongst three directories? What's a good way to quickly set up shortcuts which allow to bounce between them?aliases
You may not want to aliase rm -i as rm, especially if you use rm to remove files, etc using a script in cron, using the next choice would be better.