Essential Bash commands for file ops, navigation, search, processes, networking, and permissions
ls # current directoryls -la # all files with detailsls -lh # human-readable sizesls *.txt # pattern match-a shows hidden files. -l long format. -h with -l for readable sizes.cp file.txt dest/ # copy filecp -r dir/ dest/ # recursive copy directorycp -i file.txt bak/ # prompt before overwrite-r for directories. -v verbose. -i interactive (safe). -p preserve attributes.mv file.txt newname.txt # renamemv file.txt /path/dir/ # movemv -i *.txt backup/ # interactive bulk-i (interactive) or -n (no-clobber) to prevent.rm file.txt # remove filerm -r dir/ # remove directory recursivelyrm -rf dir/ # force, no prompts (DANGEROUS)rm -i *.log # prompt before each removalrm -rf is irreversible. Triple-check path. Use trash-cli for safer deletion.mkdir newdirmkdir -p a/b/c # create nested
rmdir emptydirrmdir -p a/b # remove parents if empty
touch newfile.txt # create emptytouch file1 file2 file3 # multiple files-t option sets explicit timestamp.cat file.txtcat f1 f2 > combined.txt
less longfile.logj/k scroll, q quit, /search
more file.txtspace next, Enter line
less for large files. cat is best for small files or piping.pwd
cd /path/to/dircd .. # parentcd ~ # homecd - # previous dir
grep "pattern" file.txtgrep -r "TODO" . # recursive in current dirgrep -i "error" log.txt # case-insensitivegrep -n "fn" file.js # show line numbersgrep -v "debug" code.js # invert: exclude lines-r recursive. -i case-insensitive. -n line numbers. -v invert match (exclude).find . -name "*.txt" # by name patternfind /var/log -type f # only filesfind . -size +10M # larger than 10 MBfind . -mtime -7 # modified in last 7 daysfind . -exec rm {} \; # execute on each result-name (case-sensitive), -iname (case-insensitive). -exec runs command on matches. {} is placeholder.which nodewhich -a python # all matches
whereis gcc
ps aux # all processesps -ef | grep node # filter
topq to quit, M sort by mem
htop(install: apt/brew)
kill 1234 # SIGTERMkill -9 1234 # SIGKILL (force)
pkill -f "node app.js"
killall chrome
kill -9 (SIGKILL) does not allow graceful shutdown. Try kill (SIGTERM) first.command & # start in backgroundjobs # list background jobsfg %1 # bring job 1 to foregroundbg %1 # resume job in backgroundCtrl+Z to suspend current foreground job, then bg or fg to resume.chmod +x script.sh # add executechmod 755 app.js # rwxr-xr-xchmod 644 config.json # rw-r--r--chmod -R 755 dir/ # recursive755 = rwx (7) r-x (5) r-x (5)644 = rw- (6) r-- (4) r-- (4)
chown alice file.txt # change ownerchown alice:staff file.txt # owner and groupchown -R www-data:www-data /var/www # recursivecurl -O https://url/file.zipcurl -I https://site.com # headers only
wget URLwget -c file.zip # continue partial
ping google.comping -c 4 host # count=4
traceroute google.com
nslookup example.com
ss -tulpn # listening portsnetstat -tulpn # traditional (older)ss is modern replacement for netstat on Linux. -t TCP, -u UDP, -l listening, -p process.df -h # human-readabledf -i # inode usage
du -sh dir/ # summary human-readabledu -h --max-depth=1 # per-subdir
free -h
uname -a # all detailsuname -r # kernel version
tar -cvf archive.tar dir/ # create tartar -xvf archive.tar # extracttar -czvf archive.tar.gz dir/ # create gzippedtar -xzvf archive.tar.gz # extract gzippedtar -tjvf archive.tar # list contents-c create, -x extract, -v verbose, -f file, -z gzip, -j bzip2.tar -zcvf = tar -czvf.
gzip file.txtgunzip file.txt.gz
zip -r out.zip dir/
unzip out.zip
gzip compresses files in-place (replaces original with .gz). Use tar for directories.echo "text"echo $PATH # variable
head file.txthead -n 20 # 20 lines
tail -f logfile # follow livetail -n 50 # last 50 lines
wc file.txt # lines words byteswc -l file.txt # line count onlywc -w file.txt # word countls -1 | wc -l # count files in dirsort file.txtsort -r # reversesort -n # numeric
uniq sorted.txtsort file | uniq -c # count per value
uniq only removes adjacent duplicates. Pipe through sort first for full deduplication.sed 's/old/new/g' file.txtsed -i 's/foo/bar/g' file # in-place
awk '{print $1}' fileawk -F: '{print $1}' /etc/passwd
sed 's/old/new/' replaces first occurrence. g flag = global (all). -i edits file in-place.The Linux Terminal Cheat Sheet is a quick reference for essential Bash and shell commands. It covers the most commonly used commands across file operations, navigation, process management, networking, permissions, and text processing. Each command includes brief explanations and copy-ready examples.
-la) or long (--all). Combine shorts: -la = -l -a.* (any chars), ? (single char), [...] (set).cmd1 | cmd2 sends output of first as input to second. > out.txt (overwrite), >> out.txt (append), 2> err.txt (stderr).cmd1 && cmd2 runs second if first succeeds. cmd1; cmd2 runs regardless.Use ls -a to show all files including dotfiles (starting with .). For detailed view: ls -la.
chmod 755 mean?755 sets permissions: user = rwx (7), group = r-x (5), others = r-x (5). Commonly used for scripts and public executables. Read=4, write=2, execute=1. Sum them per class.
First try kill PID (SIGTERM — graceful shutdown). If it doesn't respond, use kill -9 PID (SIGKILL — forced, no cleanup). Find PID with ps aux | grep name or pgrep name.
-z uses gzip (fast, moderate compression). -J uses xz (slower, higher compression). -j uses bzip2 (middle ground).
Yes, completely free with no sign-up required.