Bash Commands
Bash shell scripting commands, syntax, and shortcuts.
File Operations
ls -laList all files with details including hidden files
cp -r source destCopy directory recursively
mv file1 file2Move or rename file
rm -rf directoryRemove directory and contents recursively
find . -name "*.txt"Find files by name pattern
locate filenameQuick file search using database
touch file.txtCreate empty file or update timestamp
mkdir -p path/to/dirCreate directory with parent directories
Text Processing
cat file.txtDisplay file contents
head -n 10 file.txtShow first 10 lines of file
tail -f /var/log/syslogFollow log file in real-time
grep "pattern" file.txtSearch for pattern in file
grep -r "text" /pathRecursively search for text in directory
wc -l file.txtCount lines in file
sort file.txtSort lines alphabetically
uniq file.txtRemove duplicate adjacent lines
cut -d"," -f1,3 file.csvExtract fields from CSV
tr "[:lower:]" "[:upper:]"Translate lowercase to uppercase
Process Management
ps auxList all running processes
topDisplay dynamic real-time process information
htopInteractive process viewer
kill -9 PIDForce kill process by PID
killall process_nameKill all processes by name
bgResume suspended job in background
fgBring background job to foreground
jobsList active jobs
nohup command &Run command immune to hangups
pkill -f patternKill processes matching pattern
Permissions & Ownership
chmod 755 file.shSet file permissions (rwxr-xr-x)
chmod +x script.shMake file executable
chown user:group fileChange file owner and group
chown -R user:group dirChange ownership recursively
umask 022Set default file creation permissions
stat file.txtDisplay detailed file status
Disk & System Info
df -hShow disk space usage in human-readable format
du -sh /pathShow directory size summary
du -h --max-depth=1Show size of subdirectories
free -hDisplay memory usage
uname -aShow system information
uptimeShow system uptime and load
whoamiDisplay current username
idShow user and group IDs
Networking
ping -c 4 hostSend 4 ICMP echo requests
curl -O https://url/fileDownload file from URL
wget https://url/fileDownload file using wget
netstat -tulnShow listening ports
ss -tulnDisplay socket statistics
ifconfigShow network interface configuration
ip addr showDisplay IP addresses
traceroute hostTrace route to host
Archiving & Compression
tar -czf archive.tar.gz /pathCreate gzipped tar archive
tar -xzf archive.tar.gzExtract gzipped tar archive
tar -tzf archive.tar.gzList contents of tar archive
zip -r archive.zip /pathCreate zip archive
unzip archive.zipExtract zip archive
gzip file.txtCompress file with gzip
gunzip file.txt.gzDecompress gzip file
Variables & Environment
export VAR=valueSet environment variable
echo $VARDisplay variable value
envShow all environment variables
printenv VARPrint specific environment variable
unset VARRemove variable
readonly VAR=valueCreate read-only variable
Command History
historyShow command history
!!Execute last command
!nExecute command number n from history
!stringExecute most recent command starting with string
Ctrl+RSearch command history interactively
history -cClear command history
Redirection & Pipes
command > fileRedirect output to file (overwrite)
command >> fileRedirect output to file (append)
command 2> fileRedirect stderr to file
command &> fileRedirect both stdout and stderr
command1 | command2Pipe output to another command
command < fileRead input from file
command1 && command2Execute command2 if command1 succeeds
command1 || command2Execute command2 if command1 fails