Annexure A: Command Line Cheat Sheet

Below is a quick reference for commonly used Linux commands. Use it as a handy guide for your day-to-day tasks.


File And Directory Operations

CommandDescription
lsList files and directories.
cdChange directory.
pwdPrint the current working directory.
mkdirCreate a directory.
rmdirRemove an empty directory.
rmRemove files or directories.
cpCopy files or directories.
mvMove or rename files or directories.
touchCreate an empty file or update timestamps.
catDisplay file contents.
lessView file contents page by page.
headDisplay the first few lines of a file.
tailDisplay the last few lines of a file.
findSearch for files and directories.
grepSearch text using patterns.

System Information

CommandDescription
uname -aDisplay system information.
df -hShow disk usage in human-readable format.
du -shShow directory size in human-readable format.
free -hDisplay memory usage.
topDisplay real-time system statistics.
htopInteractive system monitor.
psDisplay running processes.
killTerminate a process by PID.

Networking

CommandDescription
pingTest network connectivity.
ifconfigConfigure and display network interfaces.
ip addr showDisplay IP addresses.
netstatDisplay network connections and statistics.
ssDisplay socket statistics.
curlTransfer data from URLs.
wgetDownload files from the web.
sshSecurely connect to a remote system.
scpSecurely copy files between systems.
rsyncSynchronize files and directories.

Package Management

CommandDescription
apt updateUpdate package lists (Debian/Ubuntu).
apt upgradeUpgrade installed packages (Debian/Ubuntu).
apt installInstall a package (Debian/Ubuntu).
apt removeRemove a package (Debian/Ubuntu).
dnf updateUpdate packages (Red Hat/Fedora).
dnf installInstall a package (Red Hat/Fedora).
dnf removeRemove a package (Red Hat/Fedora).

Text Processing

CommandDescription
cutExtract columns from text.
sortSort lines of text.
uniqRemove duplicate lines.
wcCount lines, words, and characters.
sedStream editor for text manipulation.
awkPattern scanning and processing language.

Permissions And Ownership

CommandDescription
chmodChange file permissions.
chownChange file ownership.
chgrpChange file group ownership.

Compression And Archiving

CommandDescription
tarArchive files.
gzipCompress files.
gunzipDecompress files.
zipCreate a ZIP archive.
unzipExtract files from a ZIP archive.

System Management

CommandDescription
shutdownShut down the system.
rebootReboot the system.
systemctlManage system services.
journalctlView system logs.

User Management

CommandDescription
useraddAdd a new user.
userdelDelete a user.
passwdChange a user’s password.
suSwitch user.
sudoExecute commands as another user.

File Transfer

CommandDescription
scpSecurely copy files between systems.
rsyncSynchronize files and directories.
lftpAdvanced FTP client.
ncftpUser-friendly FTP client.

Basic Terminal Commands

date: Displays the current date and time. date For formatting, you can use flags like: 
$ date +”%Y-%m-%d %H:%M:%S”

cal: Shows a calendar of the current month. cal To see a year: $ cal 2025

man: Manual pages for commands. Very useful for detailed information. man [command] Example: $ man ls

history: Lists previously executed commands. history To rerun a command from history, use ! followed by the command number: $ !5

clear: Clears the terminal screen. $ clear

Navigation and Exploration System Commands

pwd: Prints the current working directory. $ pwd

cd: Change directory.

  • To go to home directory: $ cd ~
  • To go to a specific directory: $ cd /path/to/directory

To go back one directory: $ cd ..

ls: List directory contents.

  • Basic usage: $ ls
  • With options:
  • -l for long listing format: $ ls -l
  • -a to show hidden files: $ ls -a
  • -h for human-readable sizes: $ ls -lh

File Administration Commands

mkdir: Make directories. $ mkdir new_directory 
To create nested directories: 
$ mkdir -p new_directory/sub_directory

cp: Copy files or directories. 
$ cp source_file destination_file 
To copy directories recursively: 
$ cp -r source_directory destination_directory

mv: Move or rename files/directories.  $ mv old_file new_file 
Or to move: $ mv file /new/location/

rm: Remove files or directories. $ rm file.txt 
To remove directories and their contents: 
$ rm -r directory_name 
Be cautious as this command is permanent; use -ifor interactive deletion: 
$ rm -i file.txt

find: Search for files in a directory hierarchy. 
$ find /path/to/search -name “pattern”
Example to find all .txt files: $ find . -name “*.txt”

locate: Quickly find files by name, using a database (needs to be updated with updatedb). locate pattern

Wildcards: Use in commands like ls, cp, mv, etc., for pattern matching.

  • * for any number of characters: ls *.txt
  • ? for a single character: ls file?.txt

File Content Commands

cat: Concatenate and display files. $ cat file.txt
To display multiple files: $ cat file1.txt file2.txt

head: Output the first part of files. $ head file.txt 
To see the first 10 lines: $ head -n 10 file.txt

tail: Output the last part of files. $ tail file.txt 
To follow the file for updates: $ tail -f file.txt

less: View file contents with scroll capabilities. $ less file.txt
Use arrow keys to navigate, q to quit.

touch: Create a new empty file or update the timestamp of an existing file. 
$ touch new_file.txt

nano: Simple text editor for the command line. $ nano file.txt 
Common commands: ^O to save, ^X to exit.

grep: Search text using patterns. $ grep ‘pattern’ file.txt
To search recursively: $ grep -r ‘pattern’ /directory/

Process Commands

top: Interactive process viewer. top Use q to quit.

ps: Report a snapshot of current processes. $ ps aux 
To find processes by name: $ ps aux | grep process_name

kill: Send signal to a process. 
$ kill [PID] To force terminate: $ kill -9 [PID]

Network Commands

ifconfig: Configure network interfaces 
$ ifconfig Or better use: ip addr show
(note: modern Debian uses ip command more commonly). 

ping: Check if a network host is reachable. 
$ ping google.com
To limit to 4 pings: $ ping -c 4 google.com

wget: Retrieve files from the web. 
$ wget http://example.com/file.zip 
To download in background: 
$ wget -b http://example.com/file.zip


Prev: Conclusion | Next: Annexure B