Grasping the basics of Bash
Where and Who?
If you get lost in the directory structure while in the command line, you can use pwd, which is short for "present working directory" to get your bearings. If you have been switching accounts and want to be sure, for example, that you are not running a dangerous command as root, then the whoami command will tell you the name of the account that you are currently using. If, however, you find yourself continually forgetting the current account name, you might want to research how to add it to your command prompt (Figure 2).
As you enter commands, Bash also has several ways to save time and reduce typing. Unless a full path is given, any files or sub-directories that you type are assumed to be in the present directory. However, if you want to be absolutely sure (which is never a bad idea), you can use ./ to indicate the present directory. For instance, if you are in a user account named bruce, then typing /home/bruce/download is the same as typing ./download. If your sub-directories are several levels deep, then this piece of shorthand can significantly reduce your typing.
There are also several different shortcuts that you can use with the cd (change directory) command:
- cd .. – Moves you to the directory directly above the current one.
- cd - – Returns you to the previous directory.
- cd ~ – Returns you to the home directory for the current account.
- cd ~[directory name] – Changes to the directory specified within the home directory for the current account.
These last two shortcuts explain why you often see references to the home directory reduced to a tilde. For example, if you see a reference to ~/.bashrc, it is indicating the .bashrc configuration file in your home directory.
Finding Command Help
As you work at the command line, you will undoubtedly come across unfamiliar commands, many with more options than you can easily remember. If all you want is a quick explanation of a command, you can use apropos or what is. The only trouble is that, while these commands can serve as reminders for veteran users, their output is often cryptic to the less experienced. For example, if you enter apropos chmod, the definition you receive is "change file mode bits," which is geeky enough to scare off most beginners (Figure 3).
You can get more detailed information by typing man followed by the name of the command. However, the quality of so-called man pages varies wildly. Although some pages, especially more recent ones, read easily enough, others are written for an expert audience. In fact, some may have remained almost unchanged for a decade or more.
In theory, info pages – the explanatory notes you receive when you enter info followed by a command name – are more user-friendly than man pages. And, in practice, they often are. However, they are sometimes little better than the worst man pages and can vary almost as much. Moreover, the original impetus to help info pages evolve into a replacement for man pages seems to have weakened in recent years, and the quality varies.
Often, the most useful help you can find is to use the -h or --help option for a command, which produces a short summary of options. What is missing, however, is any sort of built-in help that allows you to enter a description of the action you would like to perform and receive a list of possible commands. Unfortunately, the options here are the only ones available to you without searching on the web.
Powerful man-in-the-middle attack is now targeting online shopping.
Another high-profile coder says the kernel team needs a kinder, gentler culture.
Bug database has a bug of its own that could allow an intruder to create an unauthorized account.
Report focuses federal resources on achieving universal Internet access.
Leading browser makers say “no” to porous encryption algorithm
Report from the X-Force group says attackers are using TOR to hide their crimes
Future Firefox extensions will be compatible with Chrome.
Better read this if you bought your computer before 2011
Users should upgrade to the new version as soon as possible
Xen project announces a privilege escalation problem for Qemu host systems