Bash is a popular shell or command-line interface that runs on Unix-based operating systems like Linux and macOS. It provides a way for users to interact with the system by executing commands and scripts in a text-based interface. Bash is a powerful tool that can be used for tasks ranging from simple file manipulation to complex system administration.
Bash works by interpreting commands entered by the user and executing them. When a command is entered, Bash looks for the corresponding executable file on the system and runs it. Bash also provides a number of built-in commands that can be used to perform common tasks like navigating the file system, managing processes, and manipulating text.
The Bash cheat sheet you provided is a helpful resource for users who are just getting started with Bash or who want a quick reference for common commands and syntax. The cheat sheet covers a range of topics including navigation, file management, process management, and input/output redirection.
One of the key features of Bash is its use of command-line arguments, which allow users to pass options and arguments to commands. The cheat sheet provides examples of how to use common options like -a, -f, and -r, as well as how to specify file names and directories.
Another important feature of Bash is its support for shell scripting, which allows users to automate tasks and create complex workflows using a series of commands and logical statements. The cheat sheet provides examples of how to create and run scripts, as well as how to use variables and control structures like if/else statements and loops.
Cheat Sheet
Navigation Commands
Command
Description
cd directory
Change the current directory to the specified directory
cd ..
Move up one directory level
pwd
Print the current directory
File Commands
Command
Description
ls
List files and directories in the current directory
ls -a
List all files and directories (including hidden files) in the current directory
ls -l
List files and directories in the current directory with detailed information
touch filename
Create an empty file with the specified filename
mkdir directoryname
Create a new directory with the specified directoryname
rm filename
Remove the file with the specified filename
rm -r directoryname
Remove the directory and its contents recursively
mv source destination
Move or rename a file or directory from the source to the destination
cp source destination
Copy a file or directory from the source to the destination
Text Processing Commands
Command
Description
cat filename
Display the contents of the file
less filename
Display the contents of the file one page at a time
head filename
Display the first 10 lines of the file
tail filename
Display the last 10 lines of the file
grep pattern filename
Search for lines in the file that match the specified pattern
sed ‘s/oldstring/newstring/g’ filename
Replace all occurrences of oldstring with newstring in the file
Permission Commands
Command
Description
chmod permissions filename
Change the permissions of the file to the specified permissions
chown owner:group filename
Change the owner and group of the file to the specified owner and group
Process Management Commands
Command
Description
ps
Display a list of running processes
ps -ef
Display a detailed list of all running processes
kill pid
Send a signal to the process with the specified process ID (pid)
killall processname
Send a signal to all processes with the specified process name (processname)
System Information Commands
Command
Description
uname -a
Display information about the operating system
df
Display information about disk space usage
free
Display information about memory usage
top
Display information about system processes and resource usage
Networking Commands
Command
Description
ping hostname
Send a packet to the specified hostname to test connectivity
traceroute hostname
Display the route that packets take to reach the specified hostname
netstat
Display network connections, routing tables, and interface statistics
ifconfig
Display network interface configuration
Shell Scripting Commands
Command
Description
echo string
Display a message on the terminal
read variable
Read input from the user and store it in the specified variable
for variable in list; do commands; done
Loop through a list of items and execute commands for each item
while condition; do commands; done
Loop through commands as long as the specified condition is true
if condition; then commands; elif condition; then commands; else commands; fi
Execute different commands based on different conditions
case variable in pattern1) commands;; pattern2) commands;; *) commands;; esac
Execute different commands based on the value of the variable
functionname() { commands; }
Define a function that can be called later in the script
source filename
Execute the commands in the specified file in the current shell environment
./filename
Execute the commands in the specified file as a new shell process
User Management Commands
Command
Description
useradd username
Create a new user account
usermod -aG groupname username
Add a user to a specific group
userdel username
Delete a user account
passwd
Change the password for the current user
chpasswd
Change the passwords for multiple users at once, using a text file
chown username:groupname filename
Change the ownership of a file or directory to a specific user and group
chmod permissions filename
Change the permissions on a file or directory
File Transfer Commands
Command
Description
scp source destination
Copy a file or directory from the source to the destination over a secure shell (SSH) connection
rsync source destination
Synchronize files and directories between two locations, either locally or over a network connection
sftp username@hostname
Start an interactive secure file transfer protocol (SFTP) session with a remote server
Compression and Archiving Commands
Command
Description
tar -czvf filename.tar.gz directory
Create a compressed tar archive of the specified directory
tar -xzvf filename.tar.gz
Extract the contents of a compressed tar archive
gzip filename
Compress a file using gzip compression
gunzip filename.gz
Decompress a file that has been compressed using gzip
Text Editing Commands
Command
Description
vi filename
Open the specified file in the Vi text editor
vim filename
Open the specified file in the Vim text editor
nano filename
Open the specified file in the Nano text editor
emacs filename
Open the specified file in the Emacs text editor
System Maintenance Commands
Command
Description
apt-get install packagename
Install the specified package using the Advanced Packaging Tool (APT)
apt-get update
Update the local package index to ensure that the latest package versions are available
apt-get upgrade
Upgrade all installed packages to their latest versions
dpkg –list
Display a list of all installed packages
dpkg –configure packagename
Configure the specified package if it was not properly installed
shutdown now
Shut down the system immediately
reboot
Restart the system
SSH Commands
Command
Description
ssh username@hostname
Start an interactive SSH session with a remote server
ssh-copy-id username@hostname
Copy the public key to a remote server’s authorized_keys file for passwordless SSH authentication