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
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.