Skip to content
Go back

Linux Command Line and Shell Scripting Cheat Sheet for Beginners and Practitioner

Published:

📄 Cheat Sheet: Introduction to Linux Commands and Shell Scripting

This cheat sheet provides a quick reference for the most commonly used Linux commands and shell scripting concepts covered in this course.

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
Terminal ClearclearClear terminal screenclear
HistoryhistoryShow command historyhistory
Execute Previous!!Run last command again!!

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
CalcalDisplay calendarcal
Findfind [DIRECTORY] [OPTIONS]Find files and directories at pathfind /home/user -name ‘*.txt’
Locatelocate [FILENAME]Quickly find files in indexed dblocate bashrc
Make Directorymkdir [DIRECTORY]Create new directorymkdir myfolder
Remove Directoryrmdir [DIRECTORY]Remove empty directoryrmdir myfolder
Process Statusps [OPTIONS]Display process statusps -ef
Table of ProcessestopLive system resource usagetop
Disk Usagedf [OPTIONS] [FILESYSTEM]Display disk space usagedf -h
Create Empty Filetouch [FILE]Create file or update timestamptouch myfile.txt
Copycp [SOURCE] [DESTINATION]Copy files/directoriescp file.txt /tmp
Movemv [SOURCE] [DESTINATION]Move/rename files/directoriesmv file.txt /tmp
Removerm [OPTIONS] [FILE/DIR]Remove files/directoriesrm -r temp_folder
Change Modechmod [MODE] [FILE]Change permissionschmod u+x script.sh
Change Ownerchown [USER]:[GROUP] [FILE]Change file owner/groupchown root:root config.cfg
Kill Processkill [PID]Terminate a processkill 1234
Background Processcommand &Run process in backgroundsleep 10 &
Bring ForegroundfgBring background job to foregroundfg

Working with Text Files, Networking & Archiving Commands

CommandSyntaxDescriptionExample
Concatenatecat [FILE]Show file contentscat file.txt
Moremore [FILE]Display file one screen at timemore file.txt
Lessless [FILE]Enhanced paginatorless largefile.log
Headhead -n [N] [FILE]First N lines of filehead -5 file.txt
Tailtail -n [N] [FILE]Last N lines of filetail -5 file.txt
Tail Followtail -f [FILE]Follow file changes livetail -f /var/log/syslog
Echoecho [STRING]Print message to consoleecho “Hello”
Sortsort [FILE]Sort file linessort file.txt
Uniqueuniq [FILE]Remove duplicate adjacent linesuniq sorted.txt
Word Countwc [OPTIONS] [FILE]Count lines/words/charswc -l file.txt
Grepgrep “PATTERN” [FILE]Search pattern in filegrep “error” logfile.log
Pastepaste file1 file2Merge files side-by-sidepaste file1.txt file2.txt
Cutcut -d’:’ -f1 [FILE]Remove sections of linescut -d’:’ -f1 /etc/passwd
Tartar -czvf [ARCHIVE] [DIR]Compress directory as tar.gztar -czvf archive.tar.gz dir/
Untartar -xzvf [ARCHIVE]Extract tar.gz archivetar -xzvf archive.tar.gz
Zipzip [ARCHIVE.zip] [FILES]Create zip archivezip backup.zip file1 file2
Unzipunzip [ARCHIVE.zip]Extract zip archiveunzip backup.zip
HostnamehostnamePrint system hostnamehostname
Pingping [HOST]Check host connectivityping google.com
IP Addressingip addrDisplay IP addressesip addr
Curlcurl [URL]Download datacurl https://example.com
Wgetwget [URL]Download filewget https://example.com/file
Nslookupnslookup [DOMAIN]Query DNSnslookup google.com
Netstatnetstat -tulnShow open portsnetstat -tuln

Introduction to Shell Scripting

CommandSyntaxDescriptionExample
Shebang#!/bin/bashDeclare shell interpreter#!/bin/bash
Pipecommand1 | command2Send output to next commandls | grep “.sh”
Redirect Outcommand > fileRedirect stdoutecho “Hello” > hello.txt
Append Outcommand >> fileAppend stdoutecho “Again” >> hello.txt
Redirect Errorcommand 2> error.txtRedirect stderrls x 2> err.txt
Redirect Bothcommand > out.txt 2>&1Redirect both stdout and stderr./script.sh > all.log 2>&1
Whichwhich bashPath of executablewhich bash
Bashbash script.shRun Bash scriptbash script.sh
Set VariablesVAR=valueAssign variablename=“Janak”
Readread VARRead inputread name
Exportexport VARExport variableexport name
Test conditiontest conditionEvaluate conditiontest -f file.txt
If statementif [ condition ]; then … fiConditional executionif [ -f file ]; then echo yes; fi
Loops (for)for var in list; do … doneLoop through listfor i in 1 2 3; do echo $i; done
Loops (while)while [ cond ]; do … doneRepeat while condition truewhile true; do echo Hi; done
Crontab Editorcrontab -eOpen cron editorcrontab -e
List Cron Jobscrontab -lList user cron jobscrontab -l


Suggest Changes

Previous Post
Zsh Setup with Auto-Suggestions, Syntax-highlighting & Themes
Next Post
Containers and Containerization - Docker