TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
Linux / Tech Careers

Linux: Understand the Linux Command Line

Command-line environments are critical to administrators on any platform, especially Linux. Here's how to get started.
Mar 14th, 2024 10:15am by
Featued image for: Linux: Understand the Linux Command Line
Feature image by Markus De Nitto from Pixabay

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:

  • Speed: Knowledgeable administrators often accomplish tasks far more quickly at the command line than through a GUI.
  • Performance: Running a CLI takes fewer system resources than running a GUI. This is especially important with servers.
  • Flexibility: Command line commands often offer more options than the GUI interface, which usually only supports the most common functions.
  • Scripting and automation: You can write a series of commands into a text file called a script and execute it on a schedule. You cannot usually automate GUI tasks in the same way.

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.

Access the Linux command line

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.

Figure 1: The Ubuntu desktop with the terminal icon selected.

If not, select an Activities menu, find the search bar, and type terminal.

Figure 2: Searching for the terminal application.

The terminal window opens just like any other program. It prompts you to enter commands.

Modify Terminal Settings

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.

Figure 4: Two terminal windows, each with different preferences.

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:




Figure 5: Command examples.

What Does ‘Syntax’ Mean?

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.

Command Syntax

The traditional command syntax consists of three parts: An actual command, one or more options, and an argument.

  • Command: What you want the system to do.
  • Option: Slight modification to how the command works.
  • Argument: What you want the command to act on.

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:


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:


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.

Command and Subcommand Syntax

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.

  • Command: What you want the system to do.
  • Object/subcommand: Additional detailed focus for the command.
  • Argument: What you want the command to act on.

Here are examples of using the ip command with two different objects:



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.

Explore Your Options

Options change how a command works. For example, I can modify the list of the music directory contents to show permissions and file ownership:


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?


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.

  • ls -l: List directory contents in long format (shows permissions).
  • du -l: Displays disk utilization information, including links.
  • df -l: Displays disk utilization information, but only for local file systems.
  • cp -l: Creates hard links to files rather than creating a copy.

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:

  1. Repetition: If you use a particular command and its options regularly, you’ll probably memorize it.
  2. The manual: Linux commands include documentation collectively known as the manual. It provides a quick reference to command options.

Read the Manual

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:


To see the man page for the rm command, type:


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.


Figure 6: man page for the rm command, including synopsis and description.

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:


To exit the man page when you’re done, type q. That will place you back at the Linux command prompt.

Ten Commands to Know and Practice

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:


Display the current date and time on the system with the date command:


List all files in the /etc directory in long format using the ls command:


Try it with the /home and /boot directories.

To see what directory you’re currently in, type pwd (“print working directory”):


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.


To return to the home directory for your user account, type:


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:





Well, it’s probably best not to have distractions, so use the following command to remove that directory:


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:


Finally, gather some information on your computer. To view your Linux version and other hardware information, type the uname command:


To display your system’s IP address using the ip command, type:

Wrap up

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:

  • command option argument
  • command subcommand argument

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.


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.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.