What is Command in Linux? [A Complete Overview]

Linux operating system has a graphical user interface (GUI) and a command line interface (CLI). The CLI is a text-based interface to your machine. Commands are written and executed in the Linux terminal. All the basic and advanced levels of work can be done by the command line. In this article, you will get to know what is command in Linux and their features with examples.

Syntax of Command in Linux

All commands will follow a particular pattern. A command can be represented like this:

command -options arguments

This can be described as:

  • At first, you will type a command name.
  • Then you will have options that modify the behavior of the command.
  • Finally, you can pass arguments to the command.

Now, I will give an elaborate discussion about the options and arguments in the command.

1. Options for Command in Linux

Most commands support single and multiple options that modify their behavior. You can decide which options to include when you execute a command. When you provide these options, they are going to be prefixed by a dash such as -j, -h, -3, etc.

1.1 Using Options Separately and Combinedly

You can use options separately and combinedly. Here, I will show you an example of that:

Steps to Follow >

➊  At first open the Ubuntu Terminal by pressing CTRL + ALT + T.

   Type the following command in the command prompt giving the options separately:

ncal -3 -M

➌ Finally, Press the ENTER button.

Output >

After that, you will be able to see that it displays the past, present, and next months of the calendar where the weeks starting with Monday. Output for the ncal -3 -M ➍ Now type another command in the command prompt combining both options:

ncal -3M

➎ Then, press the ENTER button.

Output >

You can see that the output is the exact same as the previous one. This ensures that options can be given separately and combinedly, it will not have any effect on the results.Output for the ncal command using options combinedly

1.2 Using Options in Short Forms and Long Forms

You can also use options in short forms and long forms, it will not hamper your output as shown in combinations. I will give another easy example of that.

Steps to Follow >

➊  At first open the Ubuntu Terminal.

   Type the following command in the command prompt:

date -u

➌ Now, press the ENTER button.

➍ Type another command in the command prompt:

date –universal

➎ Again press the ENTER button.

Output >

Finally, you will be able to see that both commands execute the same values.Using short and long form options for date command.

Note: You must use a double dash (–) sign while using the long form options.

2. Arguments for Command in Linux

Arguments are sometimes called parameters, operands, or values that you can give to the commands. These are the values that you give to the command to work with or operate on. I will show you an easy example of passing a value to the command. You can follow these given steps to see that on your own:

Steps to Follow >

➊  At first open the Ubuntu Terminal.

   Type the following command in the command prompt:

echo how are you?

This means I am giving “how are you?” as the value to the echo command.

➌ Finally, Press the ENTER button.

Output >

After that, you will be able to see that echo command executes the value.output for the echo command with argument

Synopsis of Command in Linux

From the man page, you can get a brief overview of any command, this is called command synopsis. Here I will show you a simple example of one command synopsis.

Steps to Follow >

➊  At first open the Ubuntu Terminal.

   Type the following command in the command prompt:

man ncal

➌ Now, press the ENTER button.Synopsis of ncalOutput >

You can see that manpage of the ncal displays on the screen. ncal command displays the calendar. In the synopsis, you can see the options and arguments this command can execute. I will describe some useful options for your better understanding.

Useful options 

  • -3  Prints 3 months of the calendar (current, previous, and next).
  • -h  Turns of the highlighting of the current date.
  • -j   Prints Julian’s calendar.
  • -M  Weeks start on Monday.
  • A number of months to add after the current one. If you give -A2, it will print 2 months after the current one.
  • B number of months to add before the current one. If you give -B2, it will print 2 months before the current one.

20 Most Used Bash Commands in Linux

I will give a short brief on the 20 most used bash commands in Linux. Those are given below:

1. alias

The alias command can be used to replace a command with user-modified instructions while running the command.

2. cat

Prints the contents of the file specified. Generally, cat (concatenates) reads the contents of the files fed to its arguments and prints them serially on the terminal.

3. cd

Change Directory(cd) allows one to change one’s current directory to the desired directory within the terminal.

4. cp

Cp is the abbreviation for a copy. As the name suggests it copies things from one place to another place. cp copies one or multiple files to the specified destination directory. If the directory doesn’t exist it just renames the files. cp can also be used to copy directories and their contents.

5. echo

The echo common is one of the simplest commands, it prints whatever we give to it.

6. find

The find command searches in real-time not like the locate command from an existing file.

7. grep

The grep command can be used to search patterns in specific files or each file. Then prints the entire line containing the match.

8. head

The head command prints the first(by default 10 lines) few lines of a file.

9. less

The less command is used to display the contents of a file on the terminal screen in a page-by-page manner.

10. locate

The locate command performs the search operation from an existing database and prints the results with the exact directory path.

11. ls

Lists the contents, both files and subdirectories of the current directory by default. It is one of the most used commands, as one can view the contents of a directory without exiting the terminal and perform their desired tasks on the specific contents.

12. man

You are whether a beginner or a professional Linux CLI(command line interface) user, the command you will interact with the most is certainly the man command. The man command enables the user to learn more about a specific command i.e. syntax, options, and arguments of that command.

13. mkdir

mkdir is the abbreviation for make directory. As the name suggests the mkdir command can be used to create one or more directories.

14. mv

mv is the abbreviation for the move. As the name suggests it moves things from one place to another place. mv moves one or multiple files to the specified destination directory. If the directory doesn’t exist it just renames the files. mv can also be used to move directories and their contents.

15. nano

nano is another text editor. It is a simple and intuitive text editor that has many different shortcuts and is very light. It comes with the basic Ubuntu install.

16. rm

rm is the abbreviation for remove. As the name suggests it removes things and the removal is permanent, so be cautious while using it. rm can also be used to remove directories and their contents permanently.

17. sudo

sudo can be referred to as the supreme command. It is the abbreviation for “Super User DO”. It allows a user to act as a superuser and run commands accordingly. One can run certain commands prefixed by sudo with boosted rights. It is considered analogous to the “run as administrator” process of Windows.

18. tail

The tail command prints the last(by default 10 lines) few lines of a file.

19. touch

The touch command allows us to update a file’s access or modification time. However, if the file doesn’t exist we can create that file. This ability to create files makes the touch command one of the most useful commands.

20. whoami

The whoami command simply displays the currently logged-in user.

Conclusion

After completing this article, you will have a vast knowledge of commands in Linux. I have described the command syntax, and synopsis with examples that will give a better understanding of the commands. I have given 20 most used bash commands in Linux that will help you to get better with practice.


Similar Readings

5/5 - (8 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Borhan Uddin

Hello, I am Borhan Uddin, a resident of Dhaka, Bangladesh. I have completed my undergraduate degree in Electrical and Electronic Engineering (EEE) from Chittagong University of Engineering and Technology (CUET). I love to spend my leisure by playing and watching various movies & dramas. Currently, I am working as a Linux Content Developer Executive here. I would like to learn more about Linux every day of the week and would be keen to share it with you rapidly. Read Full Bio

Leave a Comment