Kyle Pott

Click to viewWhile the command line isn't the most intuitive place to work, terminal lovers know it can be the most productive point of entry into your system - if you've got it configured well.

It's easy to customize the command line to your particular needs. Today I've got a few tweaks that will ramp up your command line productivity so you can spend less time frackin' around in the terminal and more time getting things done. The holy grail of the terminal lies in a configuration file located in home/username/.bashrc. Let's transform .bashrc from a couch potato into a productivity monster.

Note: The commands and suggestions in this tutorial are aimed at Debian-based Linux distros (including Ubuntu). The concepts and installation commands will work well in all distros, however you may need to change some small things (like apt-get to yum, for instance).

Advertisement

Safety first!

Before you go tweaking the hell out of your terminal, back up .bashrc in case something goes wrong. Open a terminal and enter the following command:

cd ~

cp ~/.bashrc ~/.bashrc.bak

Keep it simple

Conveniently, you don't need to edit .bashrc directly. Instead, you can add the following lines to direct .bashrc to use an additional configuration file that we are going to create called .LifehackerTerminalTweaks. Since we like to keep things tidy around here, open ~/.bashrc with your favorite text editor and append the following lines:

if [ -f ~/.bashrc ]; then

source ~/.LifehackerTerminalTweaks

fi

As mentioned above, you will be adding all the configuration tricks to a separate file titled .LifehackerTerminalTweaks. If you want to skip ahead and apply all the tips we mention, just download the completed LifehackerTerminalTweaks.txt file, save it in your home directory, and - IMPORTANT! - rename it to .LifehackerTerminalTweaks. (You can use the command mv LifehackerTerminalTweaks.txt .LifehackerTerminalTweaks to do so.) Manual tweakers, read on.

Let's go shortcut crazy!

A good starting point for adding shortcuts (more commonly known as aliases) for your common commands is to take a look at your ten most commonly used commands — this way you'll know which commands are good candidates to be turned into shortcuts. Enter the following command (no line breaks) into the terminal and you'll see your ten most commonly used terminal commands:

If you're running Ubuntu, I'm willing to bet sudo is number one by a long shot and ls and cd are high on the list, too. Since sudo is most often used when installing and removing software, it makes an excellent candidate.

Note: The following section includes shortcuts that require super user (sudo) privileges. Depending on your security preferences, you may not want to create aliases for commands that require super user privileges — the choice is yours.

Open a blank file and save it in your home directory named .LifehackerTerminalTweaks (don't forget the preceding period). My package manager of choice is aptitude — if you prefer apt-get, replace "aptitude" with "apt-get." Add the following lines to .LifehackerTerminalTweaks and you'll be able to use the commands inst and remp to install and remove software as opposed to typing the lengthy commands. Also, the -y switch has been added to the first command in order to suppress the installation confirmation prompt.

alias inst="sudo aptitude install -y"

alias remp="sudo aptitude purge"

Now that you've got the hang of it, lets rattle off a bunch:

Search for a package:

alias search="apt-cache search"

List all the folders/files in column view, sorted by name, including time and date modified, owner, and permissions. — hidden folders and files are included in this view:

alias ls="ls -al"

Clear the screen contents:

alias c="clear"

Navigate up one directory:

alias up="cd .."

Navigate back to your home directory:

alias home="cd ~"

Navigate to root file system:

alias disk="cd /"

Empty trash:

alias trash="rm -fr ~/.Trash"

History

If you hit the up arrow in a terminal, your previous commands are displayed one at a time. For privacy reasons, some people prefer to have a very short history (or no history at all). Personally, I constantly think to myself "What was that command again?" Since I use a computer with no other users and I often refer to my history, I prefer to store a lot of history. In order to expand the amount of history saved, append the following line to .LifehackerTerminalTweaks.

HISTFILESIZE=100000000

HISTSIZE=100000

Alternatively, if you would like to block any history from being stored:

HISTFILESIZE=0

HISTSIZE=0

Completion

In most distributions, completion is enabled by default. When you start typing a directory or file name and hit tab, the remainder of the file/directory name is automatically entered. To ensure that completion is enabled, append the following lines. Don't worry if completion is already enabled, you won't cause any harm by enabling it twice.

if [ -f /etc/bash_completion ]; then

. /etc/bash_completion

fi

Encryption and decryption

You can quickly encrypt and decrypt files by adding functions to accomplish this task. You must have gpg installed. Append the following lines to .LifehackerTerminalTweaks.

encrypt ()

{

gpg -ac --no-options "$1"

}

decrypt ()

{

gpg --no-options "$1"

}

When you enter encrypt filename or decrypt filename you will be prompted for a password and an encrypted/decryption version of the file will be created.

Welcome message

You can customize the first message that is shown when you first open the terminal. This command will display the current username, the date and time, a calendar of the current month, the amount of users on the system, and the system's uptime.

clear

echo -e "Lifehacker, the Productivity and Software Guide"

echo -e ""

echo -ne "Today is "; date

echo -e ""; cal ;

echo -ne "Uptime:";uptime | awk /'up/

{print $3,$4}'

Customized navigation prompt

Whenever you dig into a set of nested folders, navigation becomes somewhat distracting since the terminal appends all open directories to your prompt. In order to display only the current directory (preceded by the time), append the following line: