Linux Bash type and aliases

Something I learnt today about aliases in Linux Bash shell. I use plenty of aliases in bash. Sometimes I forget what a particular alias stands for. Apparently the which command doesn’t work for this purpose. As explained here: bash-aliases, you can certainly do alias <alias-name> to check what it does. However, this doesn’t work for any custom functions we define in bash. The command type works in all cases and is the best utility to use for this purpose.

type <alias/function> will list out the exact command in all cases.

 

Bash shell tricks

The bash shell has so many nifty tricks. They can come in handy in order to save time with repeated tasks, recover data, etc.

1. My set of customizations for bash can be found on github. With those customizations, you can make find easier, colorize diff, man and prevent clobbering when using output redirection. I especially love the colored man pages.

2. If you want to sudo-ize the previous command, use;

sudo !!

3. rename utility: I never knew this! It makes renaming multiple files using regex patterns so much easier!

4. In scripts, instead of the awkard test command ‘[‘, use ‘(( … ))’ and ‘[[ … ]]’ in its place. It makes logical and string comparison so much easier. (ref: modern bash test operators)

Some more examples can be found here: bash trick commands

There are also some intricacies like the difference between rm and unlinkrm vs unlink

Feel free to suggest more in your comments.

Note: The file .bashrc is not loaded by bash at startup, by default. So it must be included in either the file .profile or .bash_profile.