Cheatsheet

Introduction to Linux

CommandSyntaxDescriptionExample
Listls [OPTIONS] [FILE/DIRECTORY]List files and directories at pathls /home/user/documents
Print Working DirectorypwdPrint present working directorypwd
Change Directorycd [DIRECTORY]Change current directorycd /home/user/documents
Super user dosudo [COMMAND]Run command with superuser privilegessudo apt update
Text Editornano [FILE]Open file with Nano text editornano myfile.txt

Introduction to Linux Commands

Informational, Navigational, & Management Commands

CommandSyntaxDescriptionExample
Who Am IwhoamiReturn usernamewhoami
User IDidReturn current user or group IDid
System Informationuname [OPTIONS]Display system informationuname -a
Manual Pagesman [COMMAND]Display manual page for a commandman ls
Curlcurl [OPTIONS] [URL]Transfer data from or to servercurl https://some_website.com
Datedate [OPTIONS]Display current date and timedate
Findfind [DIRECTORY] [OPTIONS]Find files and directories at specified pathfind /home/user -name '*.txt'
Make Directorymkdir [DIRECTORY]Create new directorymkdir myfolder
Remove Directoryrmdir [DIRECTORY]Remove empty directoryrmdir myfolder
Process Statusps [OPTIONS]Display process status informationps -ef
Table of ProcessestopDisplay live system resource usagetop
Disk Usagedf [OPTIONS] [FILESYSTEM]Display disk space usagedf -h
Create Empty Filetouch [FILE]Create new file or update timestamptouch myfile.txt
Copycp [OPTIONS] [SOURCE] [DESTINATION]Copy files or directories from source to destinationcp myfile.txt /home/user/documents
Movemv [OPTIONS] [SOURCE] [DESTINATION]Move or rename files and directoriesmv myfile.txt /home/user/documents
Removerm [OPTIONS] [FILE/DIRECTORY]Remove filesrm my_scratch_file.txt
Remove nonempty directoryrm -r path_to_temp_directory
rmdir [OPTIONS] [DIRECTORY]Remove empty directoryrmdir path_to_my_directory
Change Modechmod [OPTIONS] [MODE] [FILE]Change file or directory permissionschmod u+x myfile.txt

Working with Text Files, Networking & Archiving Commands

CommandSyntaxDescriptionExample
Concatenatecat [FILE]Display the contents of a filecat myfile.txt
Concatentate and display contents of multiple filescat file1 file2
Moremore [FILE]Display file one screen at a timemore myfile.txt
Headhead [OPTIONS] [FILE]Display first N lines of filehead -5 myfile.txt
Tailtail [OPTIONS] [FILE]Display last N lines of filetail -5 myfile.txt
Echoecho [ARGUMENTS]Display arguments in consoleecho Hello, World!
Sortsort [OPTIONS] [FILE]Alphanumerically sort file contentssort file.txt
Uniqueuniq [OPTIONS] [FILE]Report or remove consecutively repeated lines in fileuniq file.txt
Word Countwc [OPTIONS] [FILE]Print the number of lines, words, and characters in a filewc file.txt
Grepgrep [OPTIONS] PATTERN [FILE]Search for a specified pattern in a filegrep "hello" file.txt
Pastepaste [OPTIONS] [FILE1] [FILE2]Merge lines of files side by sidepaste file1.txt file2.txt
Cutcut [OPTIONS] [FILE]Remove sections from each line of a filecut -d":" -f1 /etc/passwd
Tartar [OPTIONS] [FILE]Archive files together into a single filetar -czvf archive.tar.gz /directory
Zipzip [OPTIONS] [FILE]Compress files into a zip archivezip archive.zip file1.txt file2.txt
Unzipunzip [OPTIONS] [FILE]Uncompress files from a zip archiveunzip archive.zip
HostnamehostnamePrint the name of the current host systemhostname
Pingping [OPTIONS] HOSTNAME/IPSend ICMP ECHO_REQUEST packets to a network hostping google.com
Ifconfigifconfig [INTERFACE]Display or configure network interface parametersifconfig
IPip [OPTIONS]Show or manipulate routing, devices, policy routing, and tunnelsip addr
Curlcurl [OPTIONS] URLTransfer data from or to a servercurl https://some_website.com
Wgetwget [OPTIONS] URLDownload files from the webwget https://some_website.com/some_file.txt

Introduction to Shell Scripting

CommandSyntaxDescriptionExample
Shebang#!/bin/[shell]First line of shell script#!/bin/bash
Pipefilter1 | filter2Chain any number of filters`ls
Locate executablewhich [EXECUTABLE]Display location of bash executablewhich bash
Bashbash [SCRIPT]Interpret and run script using Bash shellbash script.txt
Setset [OPTION]List all shell variablesset
Define variable[VARIABLE_NAME]=[VALUE]Define shell variable by name and assign valuename="John"
Readread [VARIABLE]Read from standard input and store result in variableread name
EnvenvPrint all environment variables and their valuesenv
Exportexport [VARIABLE]Extend scope of local variable to all child processesexport name
Crontabcrontab [OPTIONS]Open crontab default editorcrontab -e
List all cron jobscrontab -l
Schedule tasks to run at specified times using cron daemonm h dom mon dow commandAppend date/time to file every Sunday at 6:15 pm15 18 * * 0 date >> sundays.txt
Back up home directory every Monday at 3:00 am0 3 * * 1 tar -cvf my_backup_path\my_archive.tar.gz $HOME\
Run shell script first minute of first day of each month1 0 1 * * ./My_Script.sh