APC Australia

Tips, tricks and timesavers

-

The more time you spend in Bash, the more you may feel that some aspects of it could have been much better optimised. However, this isn’t entirely true. Bash has been used in system administra­tion for 27 years, and it can be excellent when it comes to optimisati­on as long as you’re willing to put in a little effort to make it your own. Remember that Bash stores its settings in the ~/.bashrc file (individual­ly for each user), which you can populate with your own features. Let’s start by automating mkdir $dir and cd $dir with a single command. Add the following to .bashrc: mkcd() { mkdir $1; cd $1; } And then don’t forget to run $ source .bashrc to apply changes. After that when you run, say, $ mkcd build you will immediatel­y enter the newly created build directory. For easier navigation, you might want to add bookmarks for frequently used directorie­s. Use the CDPATH function in .bashrc for that:

$ echo CDPATH=/home/user/Documents/ subscripti­ons/LXF >> ~/.bashrc && source ~/.bashrc

Once done, try using $ cd LXF from anywhere in your system and you’ll be taken to the right place. CDPATH uses the last element in the path for the bookmark name.

Finally, the easiest and quickest way to save some time is to populate your .bashrc file with command aliases. You can assign an alias to a long command that’s tiresome to type, or simply because you don’t want to mix habits from another OS. Let’s add a couple of DOS commands as an example: alias dir=’ls-l’; alias del=’rm -rf’ This way, you can create a custom-tailored Bash that will work lightning-fast!

Newspapers in English

Newspapers from Australia