Shell Commands - Short Notes
Basic Commands
• `#!/bin/bash` - Declares the shell type (Bash)
• `echo` - Prints text or messages to the screen
• `pwd` - Displays current working directory
• `ls -la` - Lists all files (including hidden) with details
• `date` - Displays current date and time
• `read` - Takes user input
• `exit` - Stops the script execution
File and Directory Commands
• `mkdir` - Creates a new directory
• `mkdir -p` - Creates directory with parent directories
• `cp` - Copies files or directories
• `find` - Searches for files or directories
• `wc -l` - Counts number of lines (used for counting files)
Command-line Arguments and Variables
• `$0` - Script name
• `$1`, `$2` - First and second command-line arguments
• `$#` - Number of arguments passed
• `$@` - All arguments
• `=` - Assigns value to a variable
File Test Operators
• `-e` - Checks if file exists
• `-d` - Checks if directory exists
• `-r` - File is readable
• `-w` - File is writable
• `-x` - File is executable
• `-eq`, `-ne` - Compare numbers (equal/not equal)
Arithmetic and Conditions
• `$(( ... ))` - Performs arithmetic operations
• `if [ condition ]; then ... fi` - Conditional statement
• `[[ ... ]]` - Used for string or pattern matching
• `=~` - Regex match inside [[ ]]
• `%` - Modulus operator (used to check even/odd)
Special Commands
• `stat -c "%a" ` - Displays numeric file permissions
• `echo -e` - Enables escape characters like \n for newline