I thought it would be useful to break away from all the GUI-goodness and offer up a few command line tips and tricks. Why? No matter how powerful, user-friendly, and modern the Linux desktop becomes, there may come a time when you want to step up your game and get down and dirty with the command line interface. When you do, you will want your command-fu to be strong. And whether you are brand new to the command line, or have any level of familiarity with this tool, there are tips and tricks out there to make your life easier. This article should at least offer one or two of those tips...no matter your level of skill.
This tip is for the novice. There are a lot of commands on the Linux operating system (in my /usr/bin directory there is 1736 commands). Hard to remember all of them. Or sometimes a command will have a number of variations (like in the case of beagle) And sometimes, it's just tiring typing all of those commands. Fortunately the Tab key is there to help you out. Open up your terminal window and do the following:
You should see a complete listing of all commands that start with beagle. Say you want to run beagle-index-info. You can do this by typing beagle-ind and then hitting the Tab key one time.
Run second command with first commands arguments
Say you need to find out what the directory /home/jlwallen/.e16/themes contains, but when you run the command ls /home/jlwallen/.e16/themes you see that the directory doesn't exist. Looks like you will have to create that directory. Normally you would do this by typing mkdir /home/jlwallen/.e16/themes (or mkdir ~/.e16/themes). You can use a neat little trick to take the arguments from the previous command and add them to a new command like so:
The above command would be the equivalent of (in our example above) mkdir /home/jlwallen/.e16/themes).
Search your bash history
If you can't remember how you ran a specific command, you can use your bash history to help you. If you hit <Ctrl>r you will be in a special bash search prompt that looks like:
From this prompt you can enter a portion of the command and immediately see a command that contains what you type. If the command is the one you are looking for, hit the Enter key to execute that command.
Another method of searching bash history
This one is simple. If you can't remember the last few commands you entered, just hit the up arrow on your keyboard to look through the list. When you find the command you want to run, hit Enter.
Create recursive directories with one command
Have you ever had to create entire directory trees and did so like:
You create all of these subdirectories with a single command:
mkdir -p ~/test/test1/test2/test3
Run a second command only if first command succeeds
You can string two commands together in such a way that the second of the two commands will work if (and only if) the first command succeeds. Let's say you are going to use the wget command to download a tar file and then you want to immediately unpack that file. You could do so with this:
wget http://ADDRESS_OF_SERVER/filename.tgz && tar xvzf filename.tgz
The above would unpack filename.tgz if (and only if) it is successfully downloaded.
That should get you going for a bit. I'll revisit this topic in the future so you can keep your command-fu skills sharp. And, by all means, if you have a cool command-line tip you want to share, please do so.
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.