⚡ BashQuick

Bash command reference · Always at your fingertips

Navigation

pwdPrint working directory
ls -laList all files with details
cd ~Go to home directory
cd -Go to previous directory
find . -name "*.txt"Find files by name
locate filenameFind file in database

File Operations

cp -r src/ dst/Copy directory recursively
mv file newnameMove or rename file
rm -rf dir/Remove directory forcefully
mkdir -p a/b/cCreate nested directories
ln -s target linkCreate symbolic link
chmod 755 fileSet file permissions
chown user:group fChange file ownership

Text & Search

cat filePrint file contents
less filePage through file
head -n 20 fileFirst 20 lines
tail -f fileFollow file updates
grep -r "text" .Search text recursively
grep -v "text"Exclude matching lines
sed 's/old/new/g'Replace text in stream
awk '{print $1}'Print first column

Process Management

ps auxList all processes
topInteractive process viewer
htopBetter process viewer
kill -9 PIDForce kill process
pkill nameKill by name
nohup cmd &Run in background
jobsList background jobs
fg %1Bring job to foreground

Networking

curl -I urlHTTP headers only
wget -c urlDownload with resume
ss -tunlpShow open ports
ping -c 4 hostPing 4 times
traceroute hostTrace network path
dig domainDNS lookup
nmap -p 80 hostScan specific port
ssh -p 22 user@hostSSH connection

System Info

uname -aKernel information
df -hDisk space usage
du -sh dir/Directory size
free -hMemory usage
uptimeSystem uptime & load
lscpuCPU information
lsblkBlock devices list
envList environment vars

Redirects & Pipes

cmd > fileRedirect stdout to file
cmd >> fileAppend stdout to file
cmd 2>&1Redirect stderr to stdout
cmd1 | cmd2Pipe output
cmd1 && cmd2Run if previous succeeded
cmd1 || cmd2Run if previous failed
tee fileOutput to file and stdout
xargsBuild args from stdin

Archives

tar -czf a.tar.gz dir/Create gzip archive
tar -xzf a.tar.gzExtract gzip archive
tar -tf a.tar.gzList archive contents
zip -r a.zip dir/Create zip archive
unzip a.zipExtract zip archive
gzip fileCompress single file

Variables & Scripts

VAR="value"Set variable
echo $VARPrint variable
export VARExport to environment
$(command)Command substitution
${VAR:-default}Default if unset
if [ -f file ]Check file exists
for i in {1..5}Loop 1 to 5
while read lineRead lines from stdin

Keyboard Shortcuts

Ctrl+CInterrupt current process
Ctrl+ZSuspend process
Ctrl+DEnd of input / logout
Ctrl+LClear screen
Ctrl+RSearch command history
Ctrl+AMove to line start
Ctrl+EMove to line end
!!Repeat last command