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
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.