القائمة الرئيسية

الصفحات

Command types in Linux

How to know the type of a command in Linux?


Before we start learning some Linux commands, there are some point that should be clear to every Linux user


Types of commands


In Linux, commands can categorized into 2 types: internal commands and external commands


Internal command are built-in commands that are a part of the shell itself such as pwd, cd and so on


External commands are not built into the shell. they exist as separate executable files in the system. mkdir, mv, cp are examples of external commands


How to check the type of a command?


let us now see how to check the type of a command. is it a shell built-in command or is it an external command?


To check the type of a particular command, you can use the type command


The type command will tell you, weather a command is a shell built-in, or it's is an external command


for example here, let's very that pwd is an internal command. we do that by executing the type command followed by the name of the command which is pwd. So, as the output shows here, pwd is a shell built in command, so it is an internal command


Let's now check the type of the mkdir command. we execute again the type command, but this time followed by the mkdir command


And as we see in the output, mkdir is not a shell built-in command. It is an external command


Commands - options - arguments


In Linux, when you execute a command from the terminal, it typically consists of thee main parts: The command itself, a set of arguments arguments and some options


Understanding the difference between these components is very important, for effectively using the command-line interface


So let's first of all understand the first part which is the command part


The command is the actual program yo want to run. it is the action you want to perform. for example ls, cp, mkdir, they are all commands


Arguments are additional pieces of information, that you provide to the command. they are often the files, directories, or data that the command will work with. arguments follow the command and they are separated by a space.


For example in the command cp file1.txt file2.txt, file1.txt and file2.txt are the arguments. and cp is the command being told to copy file1.txt to file2.txt


Some commands may accept multiple arguments to perform their tasks


-Finally, let us see what are options?


Options, known also as flags or switches, are used to modify the behavior of a command


They are preceded by a hyphen or double hyphen, followed by a single character or a meaningful word.


They are used to provide additional instructions to the command, and they can enable or disable specific features, or change the way the command works


Options are often optional, so not all commands require them


For example, in the command ls -l, the -l is an option for the ls command which tells it to display the list of files in a long format, with detailed information


And for the last example, ls -al /etc: here ls is the command, a and l are options provided to the ls command and /etc is the argument used by this command


Aliases in Linux


Finally, we will talk about aliases.


Aliases provide a way to create shorthand or alternative names for commonly used commands.


But, how we can create an alias?


To create an alias, we use the alias command, followed by the alias name followed by an equal sign followed by the command that you want to shorten


Let's see an example of that. let's say that we want to give an alias called la to the command "ls -a". So we want instead of typing ls -a, we type just la and we get the same result


So how we can do something like that?


We can do that using the alias command followed by the alias name, which is la in our case, followed by an equal sign, and finally ls -a


Once you've defined an alias, you can use it immediately in the current terminal session.


For example in our case, we have defined the alias la for the command ls -a, so now we will get the same result by running either ls -a or la


So that is it for this lecture. I hope every thing is clear, and see you in the upcoming lectures


Comments