In Linux there is possibility to make your own commands based on your needs. Commands could be created in the form of applications, scripts or combining other available commands to create new commands. In order to create command from scratch you need to do programming, for example, implement your own commands with C programming language. Regarding the second type, you could manipulate a command with applying some changes via scripting such as bash script, Perl or other languages. In the last type which is easiest one, you just need to combine some commands to create a new command or even you can assign a new name to available command. This is possible with using alias command in Linux. In this post, I will demonstrate about using alias command.
If you want to create your own customized commands, you could do it via using alias command easily, This command allows you to define new commands or assign new names to exist commands. For instance, imagine that you want to create command name ‘cls’ which clears screen content in the console. For doing it, you just need to assign a new name to ‘clear’ command in Linux since, clear command exactly does the task which is expected from cls to do but in different name. Therefore, you should write below command in terminal.
$ alias cls="clear"
Now, cls is defined as a new command which clear the screen. Another example could be assign a new name to a command with some parameters which is used widely and you do not want to type the parameters of the command every time and memorize its arguments. For instance, you want to use ls in color to print different file types, folders in various color. In order to reach to it you could use ls with â€“color. Now you could assign this to ls command and replace it with original ls which does not print list in color via following command.
$ alias ls="ls --color"
After executing above line, ls will be replaced with ls –color.
The only problem of alias command is that, its effects are not permanent. This means that if you logout or reboot the system, all of you defined commands will be removed. In order to solve the issue and make the results of alias permanent you just need to edit ‘.bashrc’ file which is located in your home directory and add you own commands there.
In addition, for getting list of defined aliases in the system, just use alias command without any parameter to return list of current aliases.
Finally, for removing alias or your defined command, just use unalias command like below,
$ unalias MyCustomizedCommand
send your idea and information to firstname.lastname@example.org