In the previous post, we went through some basic commands to navigate through the Linux filesystem but we just used these commands without understanding what actually commands are? How are they working? How do we define them? How do we use them?
So let us start with what are commands?
A command is an instruction given by a user telling a computer to do something, such a run a single program or a group of linked programs.
Okay so seems pretty straightforward anything we ask our Linux OS to do is a command.
So are all the commands the same or are they divided into different categories?
A command can be one of four different things :
An executable program such as small scripts written in Bash, Ruby, Python, or Perl or compiled binaries written in c, c++, python, etc.
The shell builtins. The commands that are built into the shell itself. The command
cdis an example of shell builtins.
A shell function. A group of commands clubbed together.
An alias. Aliases are commands that we can define ourselves, built from other commands.
Now we know what is the meaning of the command and what are different types of command. Now the next question that pops up is how do we write these commands?
The syntax for writing commands
command:- the name of the command(case-sensitive) i.e command & Command are not same.
options:- An option modifies the behavior of the command.
ls -a where -a changes the behavior of ls to show even the hidden files and folders.
Options are generally preceded by a hyphen (-).
arguments:- An argument indicates on what the command is to perform its action.
For example in
ls -a /home/Desktop the path "/home/Desktop" is an argument on which
ls -a is to be performed.
Now all the examples we have seen until now has been with one option and one argument so why does the syntax say option (s) and argument (s)
We can have 0 1 or more than 1 options and arguments in a command.Most of the options can be grouped together and multiple arguments can be passed in the form:
Let us take a real-life example that we want to list all the files and folders including the hidden ones from our desktop and downloads directory. Not only that we also want to sort them by last modified.
Now these are the type of conditions when the true power of command line is visible
Let's break down the above command:
ls means list
-at a means all the files and t means sort by last modified
/home/Desktop /home/Downloads path to our required directories
That's it, we now know what are commands, different types of commands , how do we define them and how do we use them.
I hope you understood the basics of commands in Linux. Please, let me know if there are any questions.