Linux skills are a common requirement for job applicants in many IT fields. In 2023, the role of this OS has grown significantly, so it's crucial to at least understand the basics of administration. Linux skills mean using the command line to solve problems. Today, we'll talk about how to stop executing commands one by one. This is part of the Linux operating system lecture course in Almaty . It will help you become an IT specialist in Kazakhstan in 2023.
Combining commands into sequences using the ampersand (&), Linux operating system lecture course Almaty
First, let's look at how to configure sequential execution of multiple commands entered into the terminal on a single line, separated by a delimiter. In this case, the ampersand " & " is used as the delimiter. This metacharacter has special meaning in the context of the Linux command shell. Our Linux security course in Almaty will explain in more detail what metacharacters are and what they do. It allows you to quickly find a job in IT in Kazakhstan.
Now let's look at how to use the ampersand to chain commands together. Let's say you want to create a new file and then immediately list the contents of the folder. Of course, you can do this one at a time:
- first enter the command touch file1;
- then - enter the command lsto make sure that the newly created file exists.
However, you can perform the same actions in one line: touch file1 & ls . As a result, after pressing Enter, you will immediately see a list of the folder's contents. Among them, you will see a file named file1.
But what happens if the shell can't execute the first command? For example, if you are denied access when you try to create a file? In this example, the command combination will still try to list the contents, which will not include the new document. That is, the second command is executed regardless of whether the first one succeeds.
It's worth noting that users often want to not just execute all commands one by one, but also execute the next command if the previous one completes successfully. In this case, it's enough to replace the single ampersand with a double ampersand—" && ". Then, if any command in the queue fails, further execution will also be interrupted. Our Linux torrent Almaty courses will cover this in more detail. However, in practice, this method is used, for example, when executing the apt update and apt upgrade commands in a single line.
We combine commands into a pipeline using the vertical bar (|)
It's worth noting that in some cases, simply executing a chain of commands one after the other isn't enough . Sometimes you need to process the output of one command by another. Fortunately, UNIX-like operating systems use pipes specifically for this purpose. Commands in a Linux pipeline are separated by the vertical bar ( | ) and are executed in the order they are listed on the command line.
Unlike simple ampersand and double ampersand concatenation, the pipeline works differently:
- the first command is executed taking into account the arguments and options entered by the user;
- the received output of the first command is passed to the input of the second command;
- the second command is executed with the options specified by the user, and so on.
A typical example is filtering command output using the grep utility , as well as sorting using the sort utility . Using a pipeline reduces the time spent on routine operations and helps extract important information from large data sets, eliminating the need for text editors with file search. Furthermore, this allows processing data generated in real time without saving it to disk. Learn more about this in the Linux online courses in Almaty on the SEDICOMM University platform.
SEDICOMM University Team : Cisco Academy , Linux Professional Institute , Python Institute.

