White Hat Institute

Linux basics

Command-line interface (part 5)

Control operators

In this section, we will mention control operator commands and briefly discuss related parameters such as “$?”, “&,” etc.

  • “semicolon (;)”: Basic compound commands, for example, hanging a few commands together in a grouping on the command-line, are used frequently. Such commands need to be isolated by semicolons, which characterize the finish of a command. To make a necessary arrangement of shell commands on a single line, separate each command utilizing a semicolon.

          Ex: (kali@kali:~/Downloads$ cal ; ls)

Linux basics 40
  • “ampersand (&)”: It is one of the most valuable control operators in Linux. At the point when any command in the shell ends with “&,” it begins to execute in the background. Therefore you’ll not have to wait for the command to finish. You will get your terminal window for another operation while the previous one is executing in the background.

          Ex: (kali@kali:~/Downloads$ apt install time &)

Linux basics 41
  • “a double ampersand (&&)”: The shell uses this operator as the logical “AND.” It empowers the execution of the second command only if the first command succeeds.

           Ex: (kali@kali:~/Downloads$ touch file1 && mkdir file)

Linux basics 42
  • “double pipe (||)”: The shell uses it as the logical “OR.” It enables the execution of the second command only if the first command fails.

           Ex: (kali@kali:~/Downloads$ touch file1 || file2 ; touch file3)

Linux basics 43
  • “the pound sign (#)”: It is one of the most as often as possible utilized control operators in Linux. It is utilized to compose shell comments. Shell overlooks everything written after the “$” sign, and it doesn’t play any role in command execution or shell expansion.

           Ex: (kali@kali:~/Downloads$ ls # We use ls command to list the contents of the directory)

Linux basics 44
  • “escaping special characters with (\)”: It empowers the utilization of control characters, like “;” and “@” yet without the shell interpreting it.

           Ex: (kali@kali:~/Downloads$ echo @ \# \$ \% \*)

  • “end of line backslash”: Lines finishing in a backslash proceed to the following line. The shell doesn’t decipher the newline character and will look out for shell extension and execution of the command-line until a newline without backslash encountered.

          Ex: (kali@kali:~/Downloads$ echo Kali Linux was founded upon the belief\

       > that to arrive at the best defensive strategy\

       > requires testers to put themselves in the\

       > shoes of potential attackers.)

Linux basics 45