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).
Save Time
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.
« Previous 1 2 3 4 Next »
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.