Below is a Bash cheat sheet covering common commands and syntax:
Navigation
List Files:
ls
Change Directory:
cd directory_name
Go to Home Directory:
cd ~
Go to Previous Directory:
cd -
Present Working Directory:
pwd
File Operations
Create Empty File:
touch filename
Create Directory:
mkdir directory_name
Copy File/Directory:
cp source destination
Move/Rename File/Directory:
mv old_name new_name
Remove File:
rm filename
Remove Directory:
rm -r directory_name
Text Manipulation
View Text File:
cat filename
Display Page by Page:
less filename
Search in Text File:
grep pattern filename
Count Lines/Words/Characters:
wc filename
Process Management
List Processes:
ps
Kill Process:
kill process_id
Background Execution:
command &
Foreground Execution:
fg
Environment Variables
Set Variable:
variable_name=value
Display Variable:
echo $variable_name
PATH Variable:
echo $PATH
Permissions
Change Permissions:
chmod permissions filename
Change Owner:
chown new_owner:new_group filename
Networking
Ping:
ping host
Traceroute:
traceroute host
Check Network Connectivity:
nc -zv host port
Archives and Compression
Create Tar Archive:
tar -cvf archive.tar files
Extract Tar Archive:
tar -xvf archive.tar
Compress with gzip:
gzip filename
Decompress with gzip:
gzip -d filename.gz
Shell Scripting
Shebang (Script Header):
#!/bin/bash
Variable Assignment:
variable_name=value
Conditionals:
if [ condition ]; then
# commands
fi
Loops:
for item in list; do
# commands
done
Functions:
function_name() {
# commands
}
This cheat sheet covers basic Bash commands.