Introduction to Shell Scripting Commands
You must have read a lot about how important UNIX based systems are in our day to day lives. You are expected to like Unix based systems more than Window-based systems especially if you belong to the technology domain. Linux has been a very popular operating system because of its efficient file system, robust structure and less prone to attacks. An operating system is made up of mainly two things Kernel and Shell. Let’s talk about shell scripting a bit. In this article, we will discuss shell scripting commands in detail.
Shell scripting is the set of commands to be executed such that the shell can execute them. It is said to be the combination of long and repeatable command sequences into one script so that it can be executed as and when required. The main idea behind creating a shell script is to lessen the load of the end-user. Let us understand the shell script with the help of an example. Suppose we have to use arguments in a particular script then we just need to create a shell script starting from #!/bin/bash and then echo the text you want to print by parameterizing with a $ sign. The number of arguments can be written in the form of $1, $2 and so on.
Basic Shell Scripting Commands
- Echo command: The echo command is used for printing.
- Using a variable: A variable is used to store in some value so that the whole value does not need to be repeated and instead variables can be used.
- Cat: This Shell Scripting command is used to show the file contents. It is one of the very important commands used in Linux.
- Grep: Another very important command which is used to search for a particular text within the file and generate the output for you related to the pattern being matched.
- Greater than symbol (>): This is used if you want to save the text written on the console to be saved into the file.
- Ls: As the name suggests, ls is the command which is responsible for listing the folders and files present in a particular directory. This shell scripting command is often appended with other commands such as –ltr or –lrt, etc. depending upon the need.
- Piping ( | ): This is another very basic command of Linux based operating system which is used to fetch the output received from one command straight away into another. This symbol called pipe can most often be seen along with the grepping command. At some places, this piping can also be said to be chaining.
- Lesser than symbol (<): If you wish to take the input from files directly then < symbol will be used.
- Pwd: This is another very basic Linux command which is used to tell the present working directory and hence the name pwd. It is most essential when you need to know which subfolder you are in, of a folder.
- Mkdir and cd: These two commands go hand in hand. Mkdir, on one hand, is responsible to create or make a directory, on the other hand, a cd is used to change a directory by traversing in it. These commands only work for directory/folders and not on files.
Intermediate Shell Scripting Commands
- Ifconfig: It is used to know the kernel-based interface for networks. This command is mainly used at the boot time to know and set up interfaces as and when necessary. Otherwise, ifconfig command only comes into a role when some system tuning or some debugging is needed.
- Netstat: This is one major command which tops the list of shell scripting commands. Netstat is used to display the network-related information like those of routing tables, network connections, masquerade connections, interface statistics, multicast memberships, etc. the suffix –a in the screenshot below is used to list all network ports.
- Nslookup: This shell scripting command is mainly used by infra management and techOps/DevOps team as they are required to deal with a deep level of networking. It is a network utility-based command which displays the information of internet servers. It queries Domain Name Server and thereby fetches the result related to server name information.
- Dig: This is another Intermediate command of shell scripting which is used to query the Domain name servers and provide information about the host addresses, nameservers, mail exchanges, etc. related information. It is mostly used to query a single given host.
Advanced Shell Scripting Commands
- Uptime: This is a command which is used to keep a track of any malicious or any unusual activity that might be affecting your system. Uptime is used to know what actually happened when the server was left unattended.
- Wall: This is one of the most essential shell scripting commands, especially for an administrator as this can be used to broadcast a message to n number of people, to all those who have their mesg permission set to yes. The message is then provided as the argument to a wall or it is also sent as standard input for a wall.
- Mesg: This command lets you take the control that whether the people can make use of the “write” by providing an option of y|n.
- w: This command is though just a one letter command can make wonders possible as it is a combination of who and uptime commands which are given in a sequence immediately after the other.
- top: It is used to display all the processes of a CPU. This command is best known as it refreshes itself and continuously displays all the CPU processes which are up and running at one point of time until and unless an interrupt command is given.
- Rename: As the name suggests, this command is used to rename a file name.
Tips and Tricks to Use Shell Scripting Commands
The tip to use a shell scripting command is that it should be used where the action is redundant such that it can be automated as the main idea behind creating a shell script is to lessen the load of the end-user. Another trick would be to make use of Tab key while writing the command so as to complete the command.
There are possibly endless commands in Unix for shell scripting and mastering all of them is not possible. The focus should be on strengthening the basic commands and work with the rest as and when time permits. With daily practice, you would surely remember all these commands and a lot more. I hope you liked this Shell Scripting Commands article, Keep reading our articles.
This was a guide for shell scripting commands. We discussed basic and advanced shell scripting commands and some immediate shell scripting commands here. You can also look at the following article to learn more –