Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


LPI Linux Essentials Exam 010-160 - 2.1 Basic Shell - Command Line Syntax

What is a Command?

A command in Linux is a specific instruction given to the operating system to perform a particular task. It can be a built-in command provided by the shell or an external command available as a separate executable file. Commands can range from simple tasks like listing files in a directory to complex operations like configuring network settings or installing software.

Command Options

Command options, also known as flags or switches, modify the behavior of a command. They provide additional instructions or parameters to customize the command's functionality. Options are usually preceded by a single hyphen (-) or a double hyphen (--).

Command Arguments

Command arguments are the inputs provided to a command to specify the resources or targets the command should operate on. Arguments can be file names, directory paths, user names, IP addresses, or any other data required by the command to complete its task. The number and type of arguments expected by a command may vary.

Issuing a Command

Using the ls command, we can demonstrate using commands with & without, options & arguments.

Exercise: Use the ls command with no options or arguments:

ls

Assuming you have run the ls command from your home directory, the ls command on its own will display the names of the files and directories in that folder in alphabetical order.

Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

Exercise: Use the ls command with -l option to provide a long listing format on the /usr directory:

ls -l /usr

The long listing format from option -l give us file permission, ownership, size and date information.

drwxr-xr-x   2 root root 69632 Sep 29 08:01 bin
drwxr-xr-x   2 root root  4096 Jul  7 07:45 games
drwxr-xr-x  44 root root 20480 Sep 29 08:01 include
drwxr-xr-x 123 root root  4096 Sep 29 08:01 lib
drwxr-xr-x   2 root root  4096 Feb 17  2023 lib32
drwxr-xr-x   2 root root  4096 Sep 29 08:01 lib64
drwxr-xr-x  23 root root 12288 Aug 26 10:17 libexec
drwxr-xr-x   2 root root  4096 Feb 17  2023 libx32
drwxr-xr-x  10 root root  4096 Feb 17  2023 local
drwxr-xr-x   2 root root 20480 Oct  9 07:28 sbin
drwxr-xr-x 285 root root 12288 Sep 28 08:42 share
drwxr-xr-x   7 root root  4096 Sep 28 08:21 src

Exercise: Use the ls command with -l option to provide a long listing format on the /usr directory. Also use the --recursive option to reverse the order files and directories get listed on screen:

ls -l --recursive /usr

The output is the same as the previous exercise, however as the --recursive option was used, the output is in reverse alphabetical order.

drwxr-xr-x   7 root root  4096 Sep 28 08:21 src
drwxr-xr-x 285 root root 12288 Sep 28 08:42 share
drwxr-xr-x   2 root root 20480 Oct  9 07:28 sbin
drwxr-xr-x  10 root root  4096 Feb 17  2023 local
drwxr-xr-x   2 root root  4096 Feb 17  2023 libx32
drwxr-xr-x  23 root root 12288 Aug 26 10:17 libexec
drwxr-xr-x   2 root root  4096 Sep 29 08:01 lib64
drwxr-xr-x   2 root root  4096 Feb 17  2023 lib32
drwxr-xr-x 123 root root  4096 Sep 29 08:01 lib
drwxr-xr-x  44 root root 20480 Sep 29 08:01 include
drwxr-xr-x   2 root root  4096 Jul  7 07:45 games
drwxr-xr-x   2 root root 69632 Sep 29 08:01 bin

Exercise: Use the ls command with -l option to provide a long listing format on the file argument /etc/hosts:

ls -l /etc/hosts

The command argument /etc/hosts tells the ls command that it is the only file it should display information on.

-rw-r--r-- 1 root adm 255 Mar 26  2023 /etc/hosts

By understanding the structure of a command, including options and arguments, and practicing their usage, you will be able to issue commands with correct syntax and achieve desired outcomes efficiently in the Linux environment.


Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.