Grasping the basics of Bash
BASH Bootcamp
Even experts forget the fundamentals. Learn more about – or get a refresher on – the basics of Bash.
One disadvantage of the modern emphasis on the desktop is that people learn about the command line only when they need it. As a result, their knowledge of is often haphazard and full of gaps. For example, for years I've been using the su - command several times a day to log in as root from a virtual terminal on the desktop of my everyday account. I always thought that when you were finished as root, you couldn't return to the everyday account in the same terminal; instead, you had to close the window and open another one. Then I learned, purely by accident, that all I really needed to do was type exit.
Since then, I've discovered that, if pressed, even experts would confess to a similar gap in their knowledge at one time or the other.
Back to the Basics
In this article, I'll discuss a topic I should have covered months ago: the basics of Bash, the command line used by most GNU/Linux distributions. I'll discuss the basic tools and sources for information, as well as the basics of navigation. Even if you know some of this information, a systematic discussion might fill in gaps in your knowledge. If not, you can always pass on the information to a desktop user to further their education.
The command line is one of the most basic interfaces ever invented. All you have to do is enter the correct string of characters to get the results you need. Right?
Well, not entirely.
This approach works if you approach the command line like a series of magical spells, each of which you must carefully copy before pressing the Enter key; however, if you add any of your own input, even the name to call a saved file, you frequently need to know more.
Case-Sensitive
For one thing, you need to know that, unlike the Windows command line, Bash is case sensitive, treating uppercase letters differently from lowercase letters. For this reason, experienced users tend to avoid capitalizing anything; they don't want to bother dealing with the extra keystrokes.
More importantly, this also means that a file called taxsummary is not the same as one called Taxsummary; if you forget this basic fact, you can waste time trying to locate a file.
Character Choice
Additionally, certain characters are not allowed in the command line in order to avoid confusion. Prohibited characters include a space, which separates out parts of a command; the forward slash, which separates out directory names in a file path (not a backward slash, as in Windows); and characters such as a question mark or asterisk, which are used in regular expressions or wild cards.
These restrictions can cause some conflicts with the desktop, which has more relaxed rules, especially about the use of spaces in file names. However, you can get around these restrictions in several ways. The easiest way is simply to avoid using anything more exotic than a period in the file name and to use an underscore or hyphen instead of a space, the way that old Unix hands do. Almost as easily, you can use single or double quotation marks around file names with spaces or restricted characters in them as a signal that the names should not be read as they normally would.
Or, if you prefer, you can do what is called escaping and place a forward slash in front of a character. The forward slash is a signal that the next character – and only the next character – is not to be read normally. For instance, if you entered Grocery\ list, you would be telling Bash to read the space between the two words as part of a continuous file name. Without the forward slash, Bash would read your entry as two files, Grocery and list.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs