Unix How-To: Time-Saving Aliases

By  

Unix users are always looking for ways to make their systems a little easier to use or themselves more productive. In today's column, we'll look at a series of helpful aliases that might preserve a few of those brain cells for harder tasks.

The first alias, which I am just calling "today", displays the current date in another format. While it's easy to type "date" anytime you wanted to be reminded whether it happens to be a Thursday or a Friday, it's a bit more painful to print the date in your favorite format whether to remind yourself or to write into various log files.

alias today="date +'%d %B %Y'"

This alias displays the date in the "21 July 2010" format, but read the man page for the date command and you can rebuild the command to use the format that you prefer.

Another alias that I have found useful over the decades is one I like to call "ruler". It just displays column positions for me on those occasions when I really need to know what column a particular character falls in or I want to gauge the length of a few lines of text.

alias ruler="echo .........1.........2.........3.........4.........5.........6.........7.........8"

An alias I often suggest to other admins as well as to Unix users is one that removes world permissions from directories.

alias fixdirs="find . -type d -exec chmod o-rwx {} \;"

This alias uses find to locate directories within the current directory and uses the chmod command to remove read, write and execute permissions from the "other" group.

Getting the right netstat command can take a few passes over the man page or you can just create an easy alias. One or both of the following might work for you. The first (Linux version) lists open ports. The second displays listening ports on both Linux and Solaris systems.

alias openports="netstat -nape --inet"
alias listening="netstat -an | grep LISTEN | awk '{print $1}' | sort -n"

The next alias lists files on a Linux system with color coding to differentiate file types.

alias ls='/bin/ls --color -F'

This next alias, which I call "again" but you might think of a much better name for, will open the most recently updated file in a directory using vim.

alias again="vim `ls -t | head -1`"

If you just want to quickly list the most recently updated file, you can use this alias.

alias prev="ls -t | head -1"

The following alias has helped a lot of people track down the data hogs in their own files. It uses a mix of find, le, sort and head to list the five largest files in a particular directory.

alias findbig="find . -type f -exec ls -s {} \; | sort -n -r | head -5"

/u/faculty/shs> findbig
484 ./tmp/.temp.txt.swp
196 ./CSI135files.tar.gz
156 ./tmp/.file.swp
76 ./dumdir/passwd
60 ./date

The next alias is not a big time saver, but might just tickle someone's fancy.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Ask a Question