Understanding Shell Scripting & Commands
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
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.