Sure! Here’s a comprehensive Bash cheatsheet covering essential commands and features:
Bash Cheatsheet
Basic Commands
pwd
– Print Working Directoryls
– List directory contentsls -l
– Long formatls -a
– Include hidden filesls -lh
– Human-readable sizescd
– Change Directorycd ..
– Move up one directorycd ~
– Go to home directoryecho
– Display a line of textecho "Hello, World!"
File Operations
touch filename
– Create an empty filecat filename
– View file contentcp source destination
– Copy filemv source destination
– Move/Rename filerm filename
– Remove filerm -r directory
– Remove directory and its contentsmkdir directory
– Create a directoryrmdir directory
– Remove an empty directory
Viewing and Editing Files
cat filename
– Display file contentless filename
– View file content page by pagemore filename
– View file content page by pagehead filename
– View the first few lines of a filehead -n 5 filename
– View the first 5 linestail filename
– View the last few lines of a filetail -n 5 filename
– View the last 5 linesnano filename
– Edit file using Nano editorvim filename
– Edit file using Vim editor
File Permissions
chmod permissions filename
– Change file permissionschmod 755 filename
– Set read, write, execute for owner; read, execute for group and otherschown user:group filename
– Change file owner and group
Searching
grep 'pattern' filename
– Search for a pattern in a filegrep -r 'pattern' directory
– Recursively search in a directorygrep -i 'pattern' filename
– Case-insensitive searchgrep -n 'pattern' filename
– Show line numbers with matchesfind /path -name filename
– Find files by namefind /path -type d -name dirname
– Find directories by namefind /path -mtime -1
– Find files modified in the last day
Process Management
ps
– Display current processesps aux
– Detailed view of all processestop
– Real-time process monitoringkill PID
– Terminate process with given PIDkill -9 PID
– Force terminate process
Networking
ping hostname
– Test network connectivityifconfig
– Display network configurationwget URL
– Download files from the internetcurl URL
– Transfer data from/to a server
Disk Usage
df
– Display disk space usagedf -h
– Human-readable formatdu
– Estimate file space usagedu -sh directory
– Summary of directory size
Package Management (Debian/Ubuntu)
sudo apt-get update
– Update package listssudo apt-get upgrade
– Upgrade installed packagessudo apt-get install package
– Install a packagesudo apt-get remove package
– Remove a package
Scripting Basics
- Create a script file:
#!/bin/bash
echo "Hello, World!"
- Make the script executable:
chmod +x script.sh
- Run the script:
./script.sh
Environment Variables
export VAR=value
– Set an environment variableecho $VAR
– Access an environment variableenv
– Display all environment variables
Miscellaneous
alias name='command'
– Create an aliasalias ll='ls -lah'
history
– Show command history!!
– Repeat last command!n
– Run nth command from historyclear
– Clear the terminal screen
This should cover most of the common Bash commands and operations you might need. Feel free to ask if you need more detailed information on any specific command or topic!