Cheet sheet
Checking the Type of a Command
Use
typeto see if a command is built-in or external:type cd type calAdd
-ato show all possible locations for a command:type -a echo
Finding Where a Command Is Located
whichlooks through yourPATHto find where a command is:which ls which calwhereisgives you the path to the binary, source, and man pages:whereis lslocatesearches a pre-built database of files on your system:locate gshadow
Creating Aliases and Functions
Set a quick alias:
alias today="date" todayDefine a simple function:
my_func() { command1 command2 }Example:
show_home() { ls -l /home echo "Done" } show_home
Combining Commands
;runs multiple commands in sequence, regardless of success:cal 1 2030 ; cal 2 2030 ; cal 3 2030|(pipe) passes the output of one command to another:cal 1 2030 | cal 2 2030&&runs the second command only if the first one works:ls /etc/ppp/ && echo "Success"||runs the second command only if the first one fails:ls /etc/ppp/ || echo "ls failed"
📚 Getting Help and Documentation
manopens the manual for a command:man lswhatisgives a short description and man section:whatis lsinfoopens a more detailed help system:info ls--helpgives a brief overview of how to use a command:cat --helpREADME files (docs):
ls /usr/share/doc
Navigation and Wildcards
pwd: Shows your current directory.Wildcards:
*= any number of characters?= exactly one character[ab]= any character listed between brackets
Examples:
echo /etc/s* # Starts with "s" echo /etc/t??????? # Starts with "t" + 7 characters echo /etc/[gu]* # Starts with "g" or "u"
Working with Files
Copy with verbose output:
cp -v file1 file2Create an archive using
tar:tar -cf archive.tar file.png
Viewing File Content
Use
lessto scroll through large files (Hfor help).headshows the top lines of a file:head /etc/sysctl.conftailshows the bottom lines:tail -5 /etc/sysctl.conf
Text Processing Tools
sort: Orders lines alphabetically:sort /etc/sysctl.confwc: Counts lines, words, and characters:wc /etc/sysctl.confcut: Extracts fields from a file using a delimiter:cut -d: -f1,5-7 mypasswdgrep: Filters lines based on a matching pattern:grep bash /etc/passwd grep 'r..f' red.txt # Matches words with r, any 2 chars, then f