"DevOps Odyssey": Day2.1 - Basic Linux Commands

Linux:
Linux is an open-source operating system that originated from Unix.
It provides a robust and stable platform for running various applications and services.
Linux is highly customizable and offers a wide range of distributions (e.g., Ubuntu, CentOS, Fedora) to suit different needs.
Shell:
A shell is a command-line interpreter that acts as a user interface to interact with the operating system.
The shell processes commands and executes programs or scripts.
In Linux, the default shell is typically Bash (Bourne Again Shell), but there are others like Zsh and Fish.
Shell Scripting:
Shell scripting involves writing a series of commands in a file (script) that the shell can execute.
Shell scripts are written in plain text using a text editor.
They can automate repetitive tasks, execute system commands, and combine multiple commands into complex workflows.
Script Execution:
Variables:
Shell scripts use variables to store data. Variable names are case-sensitive and typically uppercase by convention.
You can assign values to variables using the assignment operator (e.g.,
name="John").Access the value of a variable using the
$symbol followed by the variable name (e.g.,$name).
Control Structures:
Shell scripts support control structures like conditional statements (if-else) and loops (for, while).
Conditional statements help make decisions based on certain conditions.
Loops allow executing a set of commands repeatedly until a condition is met.
Input/Output:
Shell scripts can read input from users using the
readcommand.Output can be displayed on the terminal using the
echocommand.You can redirect input/output using special characters, such as
>(output to a file) and|(pipe output to another command).
Command Substitution:
Command substitution allows capturing the output of a command and using it as a value.
It can be done using the
$()syntax or backticks () (e.g., result=$(command) or result=command).
Functions:
Shell scripts can define functions to group a set of commands and reuse them.
Functions are declared using the
functionkeyword or just the function name.They can accept arguments and return values.
Debugging:
You can enable debugging mode in a shell script by adding
set -xat the beginning.Debugging mode displays each executed command, which helps in troubleshooting issues.
Basic Commands

Listing Commands
ls - List the subdirectories and files available in the present working directory.
ls -l - List the files and directories in long list format with extra information, such as permissions, owner, group, size, and modification date.
ls -a - List all files and directories, including hidden files and directories (those whose names begin with a dot '.')

- ls *.sh - List all the files having a .sh extension in the present working directory.

ls -i - List the files and directories along with their index numbers (inodes).
ls -d */ - List only directories in the present working directory, using a specific pattern to filter them.

Directory Commands
- pwd - Print the present working directory, i.e., the directory you are currently in.

- cd path_to_directory - Change the current directory to the specified path.

- cd ~ or just cd - Change the current directory to the home directory.

- cd - - Go to the last working directory (the directory you were in before the last cd command).

- cd .. - Move up one level in the directory hierarchy (change to the parent directory).

- cd ../.. - Move up two levels in the directory hierarchy (change to the grandparent directory).

- mkdir directoryName - Make a new directory with the given name in the present working directory.

- mkdir .NewFolder - Make a hidden directory (beginning with a dot) in the present working directory.

- mkdir A B C D - Make multiple directories with the names 'A', 'B', 'C', and 'D' in the present working directory.

- mkdir /home/user/Mydirectory - Make a new directory named 'Mydirectory' in the specified location (/home/user/ in this example).

mkdir -p A/B/C/D - Make a nested directory structure (create directories 'A', 'A/B', 'A/B/C', and 'A/B/C/D') even if the parent directories don't exist.



