Whether you’re new to the Linux command-line or you’re a seasoned veteran, these tricks will help turn your text-based meanderings into full-blown marathons. Save time, speed up your productivity, and enhance your Linux-Fu, all at once!
Here is something we could have used a few times in the past, had we known it existed:
These are answers to frequently asked questions on channel #bash on the freenode IRC network. These answers are contributed by the regular members of the channel (originally heiner, and then others including greycat and r00t), and by users like you. If you find something inaccurate or simply misspelled, please feel free to correct it!
All the information here is presented without any warranty or guarantee of accuracy. Use it at your own risk. When in doubt, please consult the man pages or the GNU info pages as the authoritative references.
BASH is a BourneShell compatible shell, which adds many new features to its ancestor. Most of them are available in the KornShell, too. The answers given in this FAQ may be slanted toward Bash, or they may be slanted toward the lowest common denominator Bourne shell, depending on who wrote the answer. In most cases, an effort is made to provide both a portable (Bourne) and an efficient (Bash, where appropriate) answer. If a question is not strictly shell specific, but rather related to Unix, it may be in the UnixFaq.
This FAQ assumes a certain level of familiarity with basic shell script syntax. If you’re completely new to Bash or to the Bourne family of shells, you may wish to start with the (incomplete) BashGuide.
Over 100 questions are answered here. And in case you missed it above, this page only shows the questions – you have to click on the links that follow each question to see the answers.
People often don’t realize how powerful BASH really is. Very often people will try to write a program in a higher level language to do a simple task that could easily be done entirely in BASH. Look this page over and you might realize that you can do a lot more with BASH than you thought. And BASH is available in every version of Linux we’ve ever encountered (note we did not say “installed by default”, though it often is nowadays). Even small computers such as Raspberry Pis will usually have BASH installed as part of the operating system.
We love simple solutions to problems, and this falls into that category.
A Reddit user has posted a pair of scripts to switch between two displays (a monitor and a TV) in Ubuntu 12.04, but these should be usable in many other versions of Linux as well. He writes:
I currently have a 40″ TV on HDMI (we’ll call this HDMI) and a 22″ monitor (DVI). I don’t want to dual screen these, I simply want one on at a time.
After a bit of difficulty at the start, this is what he came up with.
To switch the monitor off and the TV on:
xrandr --output DVI --off
xrandr --output HDMI --auto
To switch the TV off and the monitor on:
xrandr --output HDMI --off
xrandr --output DVI --auto
Be sure to make the scripts executable before running them.
Here’s a program that may be useful for those of you who, like me, sometimes find ourselves at a Linux command prompt trying to recall the syntax of a command we use frequently (because, you know, it would never have occurred to the designers of Linux to actually implement commands with names that have a clear meaning in plain English):
Aliasare a great tool to help increment your productivity on the terminal with bash (or any shell program you’re using), but usually we are too lazy to think at what are the most common, or long commands that we use frequently and prepare an
And so someone has done a small piece of software to do this job: aliaser
Aliaser helps you identify frequently typed commands and creates bash aliases for them. Aliaser analyses your bash history and helps you identify commands that you use frequently.
One thing they forgot to mention is that once you’ve added an alias, it won’t actually be available for use until you log out and then log back in. Also, you can delete the aliaser file and temporary directory from your /tmp directory once installation is complete. If you ever want to uninstall aliaser, just remove the three lines added to your .bashrc file, remove the ~/.aliaser directory, and remove the /usr/bin/aliaser file.
One way I find this useful is to make commands I can’t remember into ones that that I can remember. For example, I did this:
aliaser add processes “ps awx”
The Linux purists are probably rushing to comment that I just turned a six character command into a nine character one. Yes, BUT, I can actually remember the word “processes”, whereas I cannot remember the options I need to use after “ps” to get the output I want. The designers of Linux seem to not realize that some of us users have really bad memories. Another use for this is turning arcane Linux commands into the equivalent Windows commands that you’re familiar with. You could do this:
aliaser add dir “ls -al”
So that when you type “dir”, you get a directory listing similar to what you are used to.
If you can’t even remember the aliases you’ve created (yeah, my memory really is that bad some days), just use aliaser show to see all the aliases you’ve added.