Post

A Comprehensive Shell Scripting Guide

Hello Pentesters! Welcome, I’m 0x1df. If you have any questions or need assistance with pentesting, cybersecurity, or anything else, feel free to ask!

cat Introduction

In this blog, you’re going to learn about shell scripting basics. For now, I’ll provide an introduction, and I’ll update it with more content as soon as possible.Stay tuned for more valuable insights into the world of shell scripting and cybersecurity!

Hey folks, ever wonder what we mean by ‘shell’? No, we’re not talking about the kind you crack open to find pearls (though that would be quite the discovery!).A shell is basically a program that takes your commands from the keyboard and sends them to the operating system to perform (like youre best friend of youre girl )

If you’ve ever used a graphical user interface (GUI), chances are you’ve encountered programs like “Terminal” or “Console.” These programs simply serve as gateways to the shell.

In this course, we’ll be diving deep into the world of the shell. Throughout our journey, we’ll primarily use the bash shell (short for Bourne Again shell), which is the default for most Linux distributions. While other shells like ksh, zsh, and tsch exist, we’ll stick to bash for simplicity. Let’s embark on this exploration of the shell’s wonders together!

Let’s dive right in! Depending on your distribution, your shell prompt might vary, but it usually follows this format:

1
2
3
username@hostname:current_directory

x1df@kn1ghts:/home/x1df $

See that sneaky $ at the end? That’s your cue in Bash, Bourne, or Korn shell that you’re a normal user. No need to type it when you’re issuing commands—just keep it in mind.

Now, onto our first command: echo. This little guy simply prints out the text arguments to the display.

And just like that, you’ve made your mark on the command line. Let’s keep unraveling the mysteries of the shell! 🚀

1. pwd (Print Working Directory)

As you delve further into Linux, you’ll come to appreciate the concept that “Everything in Linux is a file.” While this may seem abstract at first, it’s a fundamental principle of the Linux operating system.

In Linux, everything, from your documents to your hardware, is treated like a file. This might seem strange, but it’s what makes Linux so powerful.

Think of your files and folders as a tree. At the very top is the “root” directory, like the main trunk of the tree. From there, you have branches (folders) and leaves (files).

For example, imagine you have a folder named “Documents.” Inside that folder, you might have another folder called “Photos” and a file named “Report.txt.” Each of these is like a branch or a leaf on the tree.


/

|-- bin

|   |-- file1

|   |-- file2

|-- etc

|   |-- file3

|   `-- directory1

|       |-- file4

|       `-- file5

|-- home

|-- var

Paths refer to the locations of files and directories within a filesystem. For example, if you have a folder named “home” containing a subfolder named “x1df,” and within that, another folder named “rabbit” the path would be: /home/x1df/rabbit.

Just like navigating in real life, understanding your location in the filesystem is crucial. You can determine your current location using the “pwd” command, which stands for “print working directory.” This command displays the directory you’re currently in, starting from the root directory.

you can use the pwd command in your terminal to find out your current directory. It stands for “print working directory.” Simply type pwd and hit enter, and it will display the directory you’re currently in. Give it a try in your terminal!

cd (change Directory)

Now that you’ve familiarized yourself with your current location, let’s explore navigating through the filesystem. We primarily utilize two types of paths: absolute and relative.

Absolute path: This originates from the root directory, denoted by a slash (/). It signifies the complete path starting from the root. For instance, /home/x1df/Desktop.

Relative path: This stems from your current location in the filesystem. If, for example, you’re at /home/x1df/Documents and wish to access a directory named taxes within Documents, you can simply specify taxes/ instead of the entire path like /home/x1df/Documents/taxes.

Now, armed with an understanding of how paths operate, let’s utilize the “change directory” command, or cd, to navigate to our desired locations.

This post is licensed under CC BY 4.0 by the author.