Bash / Shell Command Reference

Navigation

CommandWhat it doesExample
cdChange directorycd /path/to/directory
pwdPrint working directorypwd

Files & Directories

CommandWhat it doesExample
lsList directory contentsls
ls -laList all files, including hidden onesls -la
mkdirCreate a directorymkdir new_directory
mkdir -pCreate a directory and its parent directoriesmkdir -p /path/to/new_directory
rmdirRemove an empty directoryrmdir empty_directory

Viewing & Searching

CommandWhat it doesExample
catDisplay the contents of a filecat file.txt
lessView a file page by pageless file.txt
headDisplay the first few lines of a filehead file.txt
tailDisplay the last few lines of a filetail file.txt
tail -fFollow the end of a file as it growstail -f log.txt
grepSearch for text in filesgrep "search_term" file.txt
grep -rRecursively search for text in filesgrep -r "search_term" /path/to/directory
findFind files and directoriesfind /path/to/search -name "filename"
wcCount lines, words, and characters in fileswc file.txt

Permissions

CommandWhat it doesExample
chmodChange file permissionschmod 755 file.txt
chmod +xMake a file executablechmod +x script.sh
chownChange file ownershipchown user:group file.txt
umaskSet default file permissionsumask 022

Processes

CommandWhat it doesExample
ps auxList all running processesps aux
topDisplay real-time process informationtop
killTerminate a processkill 1234
kill -9Forcefully terminate a processkill -9 1234
jobsList background jobsjobs
bgResume a background jobbg %1
fgResume a foreground jobfg %1
nohupRun a command immune to hangupsnohup command &

Pipes & Redirection

CommandWhat it doesExample
|Pipe output to another commandcommand1 | command2
>Redirect output to a filecommand > file.txt
>>Append output to a filecommand >> file.txt
<Redirect input from a filecommand < file.txt
2>&1Redirect stderr to stdoutcommand 2>&1
/dev/nullDiscard outputcommand > /dev/null

Text Processing

CommandWhat it doesExample
sedStream editor for filtering and transforming textsed 's/old/new/' file.txt
awkPattern scanning and processing languageawk '{print $1}' file.txt
cutRemove sections from each line of filescut -d',' -f1 file.txt
sortSort lines of text filessort file.txt
uniqReport or omit repeated linesuniq file.txt
trTranslate or delete characterstr 'a-z' 'A-Z' file.txt
xargsBuild and execute command lines from standard inputfind /path/to/search -name "*.txt" | xargs rm

Archives & Transfer

CommandWhat it doesExample
tar -czfCreate a compressed tar archivetar -czf archive.tar.gz /path/to/directory
tar -xzfExtract a compressed tar archivetar -xzf archive.tar.gz
scpSecure copy files between hostsscp file.txt user@remote_host:/path/to/destination
rsyncSynchronize files and directoriesrsync -av /path/to/source user@remote_host:/path/to/destination
curlTransfer data with URLscurl -O http://example.com/file.txt
wgetNon-interactive network downloaderwget http://example.com/file.txt