Friday, September 11, 2015

I'm an Alias, I'm a Legal Alias

Useful Command Aliases

When working from the command line I like to cut down on the amount of typing that I do because a) I get in a hurry, and b) I fat-finger the things I’m trying to type, so c) I end up doing things over to get them right. I use aliases to take some common tasks and shorten them up so that I can save time and face.
If you look at my *nix systems you’ll find several aliases for various incarnations of ls:
alias l='ls -F'
alias la='ls -a'
alias ll='ls -lh'
The first of these, -F, appends a character to the end of the file name to identify the file type: * for executable files; @ for symbolic links; and / for directories. Regular files don’t have any special character following their names. While most Linuxes and BSDs use a colorized ls command these days, this is useful if you need to work from a terminal or remote session that doesn’t support color.
The second alias lists all files, including hidden ones, and the third displays a detailed listing with file sizes in “human readable” format: gigabytes or megabytes instead of bytes.
Aliases can be more sophisticated, standing for piped output. When I use the df command to check free disk space, usually I just want to see mounted logical volumes and not pseudo-filesystems and LVM disks. I pipe the output of df to grep to get what I want:
alias dfh='df -h | grep -v "^[[:alpha:]]"'
And to see a sorted list of details about my own processes:
alias myps='ps aux | grep ^$(whoami) | sort -k 2b'
An alias can also contain several commands—a mini-script, if you will:
alias sched='echo ""; cal; echo ""; calendar -w 3; echo ""'
Perhaps I have inspired you to experiment with aliases and discover some of the cool things you can do with them.
Be seeing you.

No comments:

Post a Comment