0% found this document useful (0 votes)
6 views1 page

Essential Shell Commands Guide

This document provides a concise overview of essential shell commands, including basic commands, file and directory commands, command-line arguments, file test operators, arithmetic operations, and special commands. It outlines the syntax and purpose of each command, making it a useful reference for users working with Bash scripts. The notes cover a range of functionalities from displaying information to manipulating files and directories.

Uploaded by

abca46881
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Essential Shell Commands Guide

This document provides a concise overview of essential shell commands, including basic commands, file and directory commands, command-line arguments, file test operators, arithmetic operations, and special commands. It outlines the syntax and purpose of each command, making it a useful reference for users working with Bash scripts. The notes cover a range of functionalities from displaying information to manipulating files and directories.

Uploaded by

abca46881
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like