![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
Modern operating systems, like Linux, macOS, and Windows, include efficient, aesthetically pleasing user interfaces, so it may seem odd to encourage administrators to return to the “old fashioned” command line. In reality, command-line environments are critical to administrators on any platform, especially Linux.
Command line interfaces (CLI) have several advantages over graphical user interfaces (GUI). These advantages include the following:
Linux users may not access the CLI daily, but Linux administrators surely will. Achieving a certain amount of comfort at the command prompt is a crucial step in an administrator’s journey.
The default CLI or shell in Linux is called Bash, or the Bourne Again SHell. Operating systems have different shells, which vary by syntax, available commands, customization, etc. Linux supports many shells, but the only one you need to worry about early on is Bash.
Most users access Bash by using a terminal program that runs in the GUI. This article begins with accessing the terminal before covering the syntax of Bash commands and a series of command examples.
Using Bash is critical for anyone following The New Stack Linux Repository article series. I suggest setting up a home lab environment to practice the commands referenced in this article.
Linux distributions make it easy to open the terminal. Most distributions today install with a GUI, though production servers often only include a CLI. Linux GUI environments vary a lot, but typically, there’ll be a shortcut bar along the edge of the desktop. This bar may have an icon for the terminal.
If not, select an Activities menu, find the search bar, and type terminal.
The terminal window opens just like any other program. It prompts you to enter commands.
I tend to leave the settings alone on most Linux boxes, but I do sometimes customize the interface. Standard changes include increasing the font size or setting a preferred background color for easier reading.
Select the Preferences menu in the shell window to set font, font color, font size, background colors, and other preferred settings. The following image includes a default terminal and another with a blue background. The terminal Preferences window is also open.
If you’re setting up a Linux home lab, making this environment comfortable for you is important — Linux users spend a lot of time at the command line.
So, the terminal prompts you to enter a command — now what? Before you begin entering Linux commands, you need to understand command syntax or how commands are structured.
But just for fun, since you have the terminal open, try a couple of easy and self-explanatory commands:
date
whoami
echo "Hello, World!"
Remember in school when you were told about structuring sentences? Your sentences needed a noun and verb, plus the first character of the sentence should be upper case and the sentence, must end with a punctuation mark. That’s syntax — rules for written communication.
You must type in commands correctly. In addition, commands and filenames are case-sensitive. This often trips up new users, so be careful.
The Linux command line also has rules for communication, and they’re pretty different from standard sentences. There are two basic ways of issuing commands to your Linux system.
The traditional command syntax consists of three parts: An actual command, one or more options, and an argument.
Arguments represent what you want the command to act on. For example, you can’t just type the command to delete a file (which is rm, by the way). You must specify what file you want deleted.
Here’s an example:
rm file1
In this example, rm is the command — you want something deleted. The argument is file1 — that’s what you want deleted.
In this second example, you want to display the contents of a directory named /home:
ls /home
The command is ls — you want to list the contents of a directory. The argument is /home — the directory you want to list the contents of. This directory contains home folders for all standard users on the system.
Some Linux commands allow a great amount of focus. For example, the command to display the system’s IP address is ip. However, it also uses a series of objects or subcommands to allow the command to target specific functions.
Here are examples of using the ip command with two different objects:
ip addr
ip link show
The ip addr example displays IP address information for each network interface. The ip link show command displays detailed information about each interface (and it happens to include the IP address assigned to that link).
Try both commands on your system.
Options change how a command works. For example, I can modify the list of the music directory contents to show permissions and file ownership:
ls -l music
You’ve already seen the ls command and the music argument. The -l option lists the contents in long format — modifying the command to display a little more information about the files in that directory.
Most commands have many options, and often you can combine these options. The ls command has another option that displays all files in a directory, even if they would normally be hidden (Linux hides files to declutter the output). What if I want to see all (-a) files in long (-l) format?
ls -al music
Unfortunately, options are not consistent among commands. The -l option is “long format” for the ls command, but it means something different for commands like du, df, and cp. Like commands, options are case-sensitive, meaning that some commands use both -l and -L.
Note: The point is not understanding these four commands yet but recognizing that -l means something different for each.
So, if there are many options for every command, and if they don’t mean the same thing with various commands, how do Linux administrators remember them? There are two answers to this question:
Manual or man pages are extremely useful and need to be one of the first things you learn to work with on a Linux system. Fortunately, the syntax is very simple. The command is man, and the argument is the command for which you want help.
For example, to get help with ls, type:
man ls
To see the man page for the rm command, type:
man rm
The man page displays the command name, a brief description of its function, a synopsis of command options, and a more detailed description. Most importantly, it lists each available option with a brief explanation.
Once the man page opens, use the up and down arrows or page up and page down keys to navigate through the entry. You can search for keywords by typing a forward slash (/) before the keyword. For example, to search for the string directory in a man page, type:
/directory
To exit the man page when you’re done, type q. That will place you back at the Linux command prompt.
If you have a Linux system available, here are a few more commands to get you started.
The whoami command displays the username of the current user:
whoami
Display the current date and time on the system with the date command:
date
List all files in the /etc directory in long format using the ls command:
ls -al /etc
Try it with the /home and /boot directories.
To see what directory you’re currently in, type pwd (“print working directory”):
pwd
Once you know what directory you’re in, you can begin to change to other directories using the cd command.
Type cd with the /etc argument to change to the /etc directory. Use pwd to confirm the change and ls to see its contents.
cd
To return to the home directory for your user account, type:
cd ~
That character is called a tilde, and you can find it in the upper left corner of your keyboard. Use pwd to see that your location is your home directory.
You can create and delete your own directories using the mkdir (make directory) and rmdir (remove directory). Try the following commands to create folders to organize your study materials:
mkdir books
mkdir articles
mkdir references
mkdir distractions
Well, it’s probably best not to have distractions, so use the following command to remove that directory:
rmdir distractions
Practice the cd, ls, and pwd commands by navigating these directories.
You can cause Linux to print text to the screen using the echo command. While this may not seem useful as a standalone command, it’s frequently integrated into scripts to provide information to users. Type the following to display “Good morning!” on the screen:
echo "Good morning!"
Finally, gather some information on your computer. To view your Linux version and other hardware information, type the uname command:
uname
To display your system’s IP address using the ip command, type:
ip addr
Command line environments are critical to administrators on any platform, especially Linux. The command line allows administrators to be quicker, is less of a strain on system resources, and can be automated via scripting.
Linux command line users will use two syntaxes to interact with their systems:
Linux systems ship with man pages for each command. These pages remind users of command syntax and options. When in doubt, type man and the command you’re working with to see the related man page.
man ls
Practice the command examples in this article. Deliberately think of using them for your daily tasks. Remember that command line administration is also useful on Windows and macOS platforms. If you’re following along with The New Stack Linux Repository article series, you’ll find yourself using these and other commands regularly.