Bourne Again Shell (bash)
History
The Bourne Again Shell (Bash) is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne Shell (sh). First released in 1989, Bash has become the default shell on many Linux distributions and macOS.
Features
Command History: Allows users to recall and edit previous commands.
Tab Completion: Automatically completes file names and commands.
Scripting: Supports writing scripts to automate tasks.
Job Control: Manages multiple processes within a single shell session.
Aliases: Creates shortcuts for frequently used commands.
Basic Commands
Navigation
pwd
: Print the current working directory.cd [directory]
: Change the current directory to the specified directory.ls
: List the contents of the current directory.
File and Directory Management
touch [filename]
: Create a new empty file.mkdir [directory]
: Create a new directory.rm [filename]
: Remove a file.rmdir [directory]
: Remove an empty directory.cp [source] [destination]
: Copy a file or directory.mv [source] [destination]
: Move or rename a file or directory.
Scripting
Basic Script
Variables
Conditional Statements
Loops
For Loop
While Loop
Functions
File Operations
Creating a File
Reading a File
Deleting a File
Example: Backup Script
This script compresses the contents of the source directory into a tar.gz file and saves it in the backup directory with a timestamp.