Understanding Shell Scripting & Commands

Sai PrajothSai Prajoth
2 min read

Hello guys, guess who's back from a not-so-short break? It's Me.
๐˜ˆ๐˜ด ๐˜ข ๐˜ธ๐˜ช๐˜ด๐˜ฆ ๐˜ฎ๐˜ข๐˜ฏ ๐˜ด๐˜ข๐˜ช๐˜ฅ ๐˜ค๐˜ฐ๐˜ฎ๐˜ฆ ๐˜ธ๐˜ฉ๐˜ข๐˜ต ๐˜ฎ๐˜ข๐˜บ, ๐˜ฅ๐˜ฐ๐˜ฏ'๐˜ต ๐˜ด๐˜ต๐˜ฐ๐˜ฑ ๐˜ญ๐˜ฆ๐˜ข๐˜ณ๐˜ฏ๐˜ช๐˜ฏ๐˜จ ๐˜‹๐˜ฆ๐˜ท๐˜–๐˜ฑ๐˜ด ๐˜ข๐˜ฏ๐˜ฅ ๐˜ฑ๐˜ฐ๐˜ด๐˜ต๐˜ช๐˜ฏ๐˜จ ๐˜ช๐˜ต ๐˜ฐ๐˜ฏ Hashnode. Let's continue learning by discussing shell scripting and some important commands.

Shell scripting involves writing and executing a series of commands in a shell, which is a command-line interpreter or scripting language interpreter.

In DevOps, shell scripting is used for tasks like infrastructure maintenance, code management, and configuration management.

Here are some key commands:

1. ๐˜ต๐˜ฐ๐˜ถ๐˜ค๐˜ฉ ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ : Creates a file (e.g., a shell script named firstscript).
2. ๐˜ญ๐˜ด : Lists files in the current directory.
3. ๐˜ญ๐˜ด -๐˜ญ๐˜ต๐˜ณ : Lists files with additional information.
* You can add a suffix man to any command to know all its extensions.
4. ๐˜ฑ๐˜ธ๐˜ฅ : Checks the present working directory.
5. ๐˜ท๐˜ช/๐˜ท๐˜ช๐˜ฎ ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ : Edits the file; creates it if it doesn't exist.
6. :๐˜ธ๐˜ฒ! (๐˜ช๐˜ฏ ๐˜ท๐˜ช/๐˜ท๐˜ช๐˜ฎ) : Saves and exits the file.
7. :๐˜ฒ! (๐˜ช๐˜ฏ ๐˜ท๐˜ช/๐˜ท๐˜ช๐˜ฎ) : Exits the file without saving.
8. ๐˜ฉ๐˜ช๐˜ด๐˜ต๐˜ฐ๐˜ณ๐˜บ : Displays the list of entered commands.
9. ๐˜ต๐˜ฐ๐˜ฑ : Provides comprehensive node health information.

We write instructions and commands in the shell. The first line of a shell script should declare the executor, typically #!/๐˜ฃ๐˜ช๐˜ฏ/๐˜ฃ๐˜ข๐˜ด๐˜ฉ.

Other commands include ๐˜ฆ๐˜ค๐˜ฉ๐˜ฐ "๐˜'๐˜ฎ ๐˜ข ๐˜ฃ๐˜ฐ๐˜ต" to print the message, ๐˜ค๐˜ข๐˜ต ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ to print the content of the files, /. ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ or ๐˜ด๐˜ฉ ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ for execution, and ๐˜ณ๐˜ฎ -๐˜ณ๐˜ง ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ or ๐˜ณ๐˜ฎ -๐˜ณ๐˜ง * for file deletion and all files deletion in a directory.

Sometimes the /. ๐˜ง๐˜ช๐˜ญ๐˜ฆ๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ command can deny execution indicating permissions denial.
To grant permissions for executing a file, we use a command ๐˜ค๐˜ฉ๐˜ฎ๐˜ฐ๐˜ฅ ๐˜Ÿ๐˜ ๐˜ก, where X, Y, and Z indicate permissions for owner of the file (who created it), group, and others, respectively. Each permission is represented by 4, 2, or 1 (read, write, execute).
For example ๐˜ค๐˜ฉ๐˜ฎ๐˜ฐ๐˜ฅ 600 - will allow read and write permissions for the owner of the file but none of the permissions for the group and everyone.

Learning shell scripting is crucial for automation, a key aspect of DevOps. That's why we have a second part. Stay tuned for it!

Join our DevOps learning journey with hashtags:
#SaiProDevOpsLearning #DevOpsWithSaiPro

61
Subscribe to my newsletter

Read articles from Sai Prajoth directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sai Prajoth
Sai Prajoth

I am a Blockchain web developer and DevOps enthusiast, pursuing my B.Tech at IIT Hyderabad. I'm an open-source enthusiast. I write, I code, and write about the code.