Advanced Shell Scripts every Linux developers should know

CommandCommand Full nameExampleWork
psprocessesps -eflists all processes running including system processes.
grepglobal/regular expression/pintgrep “amazon”Searching plain text data set to match a regular expression.
awkMawk languageawk -F” “ ‘{print $1}’An interpreter of AWK language which is very useful in text data processing and a lot other things. For query, run man awk in terminal.
sudosubstitute user dosudo su -Switches as another user. su means superuser.

🚧 The “|” or pipe parameter sends the output of the first command into second command.

Example:

ps -ef | grep "amazon"

In this code, the first command lists all the processes running and the second command finds out all the processes that has the name “amazon” in it.

🚧 The pipe parameter (|) sends the output of the first command into the next command only if the first command doesn't send its output into stdin process.

date | echo "Date is" --> this command doesn't print the date as the date command sends the output into stdin process.

set command

set command is used to set some ground rules before executing a script.

  1. set -x : it runs the script in debug mode.

  2. set -e : it ends the script when any error occurs

  3. set -o pipefail : it ends the script in case of failure in the pipe parameter (|) data transfer.

curl vs wget

curl command executes an API and returns s response data where wget downloads the file from a network.