Linux compare

Five tips for a smoother Linux command-line experience

Many Linux users find the command line intimidating and avoid it like the plague. But these tricks and shortcuts can make the command line more manageable -- and downright useful.

When I talk to new (and some even not-so-new) Linux users about the command line, I sometimes get a fairly high cringe factor. This always surprises me, seeing as how the command line is not that difficult. Nevertheless, there it is: Many users simply do not want to use the command line. I get that. But the truth is, at some point, the command line might well be a necessity. And when it is, it's good to be comfortable using it.

Here are five tips to help make the Linux command-line experience much smoother. I'm not digging deeply into any specific command. These are just a few pointers that will help users understand what they are doing and how to make it easier.

1: Aliases

Certain commands can be ridiculously cumbersome to type. They go on and on and on with options, switches, addresses, and more. Not only are those command painful to type (over and over again), but they're also a challenge to remember. Fortunately, the Linux command line has a built-in ability to create aliases for those commands. Aliases are lines that are entered into the ~/.bashrc file under the "#some more aliases" section. The format of the alias looks like:

alias ALIAS=COMMAND

where ALIAS is the nickname of the alias and COMMAND is the full command of the alias. There may be instances where the full command must be placed in single quotes (if there are spaces in the command). The best way to test an alias is to do the following:

  1. Open a terminal window.
  2. Create the alias by editing the ~/.bashrc file.
  3. Save the ~/.bashrc file.
  4. Open another terminal.
  5. Test the alias. If the alias works, you're done. If not, go back and re-edit the file.

2: Terminal history

Open up a terminal window and hit the Up arrow on your keyboard. You should start seeing a list of previously issued commands. This is your bash history. The history keeps a list of the commands you have run and allows you to rerun them simply by locating them in the history (until the command you want shows up at the prompt) and hitting the Enter key. By default, at least in the Ubuntu distribution, the history will contain the latest 1,000 entries. You can change that in the ~/.bashrc file. Look for the line HISTSIZE=1000 and change the number to reflect whatever you require.

3: Tab completion

This is a great tip that always helps. If you are unsure of the exact name of a command, but you know the first couple of letters, type them and hit the Tab key. Bash will then attempt to complete the command for you. If there are multiple possible entries, it will ask whether you'd like to see all of them. This is a great way to locate commands when you can't remember the name or you simply don't want to type the entire command. For example, say you know there is a command-line way to start the GNOME Control Center, but you can't remember the command. You're sure it starts with gnome, so you type gnome and hit the Tab key. Bash will display a number of possible options, including gnome-control-center. There you go.

4: Running multiple commands at once

Running multiple commands is helpful when compiling applications. Instead of running ./configure, wait for that to complete, then make, wait for that to complete, and then make install, you could instead combine them together like so:

sudo ./compile && make && make install

Notice the use of sudo. It's needed because the make install command most always requires administrative rights, since this command is copying the executables into the correct directory (usually /usr/bin, /usr/sbin, or /usr/local/bin). Of course, if your compile or make requires any options, you can add them at the same time.

5: Running a second command with prior command arguments

This trick is great. Say you search for the directory ~/firewalls, only to find out that the directory does not exist. Instead of having to issue the command mkdir ~/firewalls, you can use a special trick to auto-magically create that directory. The trick in this case, would be

mkdir !*

The !* characters tell bash to run the new command using the previous command arguments. Here, the arguments are ~/firewalls. The mkdir command is run using the arguments from the previous command, so the full command is then mkdir ~/firewalls. Although this is a simplistic example, it illustrates how this tip can be useful.

Other tips?

These tips should make the Linux command line a bit easier and less intimidating. Do you have any of your own tips that might help other Linux users get more comfortable using the command line?

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

20 comments
oldmicro
oldmicro

I'll admit that I am lazy, but when moving files I find it safer to copy the destination from another terminal window and paste it into the command line where needed, adding quotes where needed. I also use this method to copy and paste commands I use a lot from a Mousepad file. I got a mercy C from typing, and I still have trouble at the keyboard, seems that even using a keyboard for 46 years has not helped me any.

brf531
brf531

It's easier to just key in the alias definition at the terminal prompt. No need to edit the .bashrc. Then you can copy-paste it into .bashrc after you get it to work the way you want. Here's one to try: alias visbel='echo -ne "\a\e[?5h";sleep 1;echo -ne "\a\e[?5l"'

jerang@
jerang@

:) you get a great looking machine that has an OS based on linux!

jkameleon
jkameleon

Nautilus, Dolphin etc, that is.

Alpha_Dog
Alpha_Dog

Guake terminal. Hitting F-12 for a command line and hitting it again to be back on GUI goodness has made life better for me except where I have a bunch of server sessions open.

SuhailS
SuhailS

Reverse command search. Hit Ctrl+r and then start typing, the last command that had those consecutive letters appears. VERY useful.

Orodreth
Orodreth

You do realize your sudo is in the wrong place, right? A typo missed in the edit, I do that all the time. ./configure && make && sudo make install Sometimes you need to specify the shell, sh ./configure && make && sudo make install As shown the ./compile? gets superuser privilege but not the make install where it's needed to install the libraries where the user or group does not have read/write access.

CharlieSpencer
CharlieSpencer

It's a keyboard-driven world, whether at the command line, creating an e-mail, editing a document, entering a search string, updating your social site. Sorry, Scotty, but voice command is still a warp jump down the timeline. Learn to type, especially if you're still in school and can sign up for a basic keyboarding class as an elective. Not only will it improve your efficiency in later classes and in the workplace, but being more comfortable around a keyboard will greatly reduce the fear of making a mistake when using a CLI. It's so much easier to enter a command string when you can look at the screen to see what you entered, instead of never lifting your eyes from the keyboard and then having to figure out which character is wrong. Public education should quit wasting time on the outdated dead-tree skill of cursive writing and use that time for the more relevant one of keyboarding.

Spitfire_Sysop
Spitfire_Sysop

I enjoy reading Linux commands out loud. It can help you remember things. Like !* for example; I might forget "!*" but it's easier to remember "Bang Everything".

Alpha_Dog
Alpha_Dog

Grab 5 or 6 off lease Dell laptops for the same price and install Ubuntu 10.10. You may even have enough left over for 17" screens for each of these.

Alpha_Dog
Alpha_Dog

Howindahell do ya do that in the CLI?

Neon Samurai
Neon Samurai

Baud how I love Checkinstall. It does the "make" and wraps the resulting program in a DEB package so I can install and uninstall with the native package management system instead of having to keep the build directory saved encase of a future "make uninstall" (when such an option exists).

NickNielsen
NickNielsen

Most SC school districts require only a single technology elective, and that's the one most students choose to take. It may have changed over the past 5 years, but Lexington 1 and Lexington 3 were two of only about 10 districts that required middle school students to take keyboarding.

jck
jck

Mine was gonna be titled "Learn to use the damn keyboard, clicky". :^0 I've been using a mouse 15 years...and a keyboard almost 30. I still am not used to a friggin mouse. And now, they want me to learn to do "squeeze" and "spread" and "squiggling"? HA! Windowkey-R, type cmd, hit enter...and I'm a happy man...and in Linux, I'm even happier...it's like...CLICK....prompt...ls -al hehehe :D

NickNielsen
NickNielsen

That's a Wile E. Coyote: Bang Splat! :D

seanferd
seanferd

"fsck" is so entertaining, yes?

jkameleon
jkameleon

You put a CLI window in the middle, and a couple of file managers around it, to drag stuff from. Very convenient. Hmmmm... I wonder... is there a way of configuring the Compiz Cube/Sphere to enable dragging from Nautilus across multiple desktops? That would be even more fancy.