If you use the Terminal window a lot in Ubuntu, here are three tips for improving your productivity when using the Terminal window.

Assigning a Hotkey to Open a Terminal Window

Here’s an easy way to quickly open a Terminal window.

Ubuntu has a built-in ability for assigning shortcut keys to tasks. To assign a shortcut key to the task of opening a Terminal window, select Keyboard Shortcuts from the System | Preferences menu.

Selecting Keyboard Shortcuts

The Keyboard Shortcuts dialog box displays. In the Shortcut column, next to Run a terminal, the initial setting is Disabled. To define a new shortcut, click in the Shortcut column until it says New shortcut.

Defining a new shortcut

Now, just type in the key sequence you want to use to open a Terminal window. In our example, we chose Ctrl + Shift + X.

Shortcut sequence set

If you change your mind and want a different key sequence, click in the Shortcut column again to clear the setting. The column for Run a terminal displays New shortcut again.

Accessing the Most Recently Typed Commands

When you type a command in the Terminal window it is added to a file called .bash_history in your /home directory that stores up to the last 1,000 commands used. If you want to reuse a command you recently typed, you can access this history and select the desired command.

If this list is very long, it will scroll off the end of the Terminal window. Therefore, we should use the less command so we can view the list page by page. For more information about the less command, see View Text Files Quickly in Linux.

Use the key command you defined above to open a Terminal window and type the following command.

$ history | less

A list displays of all the commands you have typed into any Terminal window.

History of commands in the Terminal window

To reuse one of the commands in the list, type an exclamation mark (!) and then the number beside the command entry in the list. To reuse a command you just used, type two exclamation marks (!!).

To move through your command history directly at the prompt, press Ctrl + r and then start typing the command you want to reuse. The prompt will “autocomplete” the command as you type. Once you have found the desired command, press Enter to use it. If you want to edit it before using it, press Esc, make your changes, and then press Enter.

You can also use the up and down arrows to scroll through your history of commands. When you come across the one you want, just press Enter to execute it. This is useful if the command you want is not far back in the history.

Creating an Alias to Avoid Typing in Long Commands

If there is a long chain of commands that you use often, creating a bash alias can help. An alias allows you to specify a single word of your choosing to run a long chain of commands.

For example, there is a command that allows you to instantly view all the images in a particular directory as a slideshow. The following command use Eye of GNOME (the default image viewer, eog) to view images of types jpg, tif, bmp, gif, and png (using brace expansion) in full screen mode (using the –f command option).

$ eog –f *.{jpg,tif,bmp,gif,png}

To make this command easier to type every time you want to view all images of the specified types in a directory, let’s turn it into an alias.

To create an alias, we need to add the alias command to the .bashrc file in your /home directory. The .bashrc file determines the behavior of the Terminal window.

The .bashrc file

To create the alias, type the following command in a Terminal window to open the .bashrc file in gedit.

$ gedit ~/.bashrc

Add the following new line to the bottom of the file and save the file.

$ alias slideshow=”eog –f *.{jpg,tif,bmp,gif,png}”

Basically, you are telling the alias command that the new command is called slideshow and the command in quotation marks is the command that should be run when slideshow is entered. The command to be run must be in quotation marks because of the spaces in it.

NOTE: You must exit the Terminal window and start a new one before using the command. The Terminal window must be able to read the updated .bashrc file before you can use the new command.

In a new Terminal window, type slideshow. Eye of GNOME displays the first image in the directory. Use the arrow keys on the toolbar to navigate among the images. To stop the full screen slideshow, press Esc and exit Eye of GNOME.

These are just some of the useful commands and settings we use in the Terminal window in Ubuntu to make our lives easier.

by Lori Kaufman