Linux Command Cheatsheet

Quick reference for essential Linux commands covered in this course. Keep this page handy as you work through the modules!

Pro Tip: Most commands have a --help option that shows usage information. Try command --help to learn more about any command.

Navigation Commands

pwd

Print working directory - shows your current location

cd [directory]

Change directory - navigate to a different location

cd ..

Move up one directory level

cd ~

Go to your home directory

cd -

Go to the previous directory

File and Directory Operations

ls

List directory contents

ls -l

List with detailed information (permissions, owner, size, date)

ls -a

List all files including hidden ones (starting with .)

mkdir [name]

Create a new directory

touch [filename]

Create an empty file or update timestamp

cp [source] [destination]

Copy files or directories

mv [source] [destination]

Move or rename files and directories

rm [filename]

Remove files

rm -r [directory]

Remove directories and their contents

File Content Commands

cat [filename]

Display file contents

less [filename]

View file contents with pagination (scrollable)

head [filename]

Show first 10 lines of a file

tail [filename]

Show last 10 lines of a file

wc [filename]

Count lines, words, and characters in a file

grep [pattern] [file]

Search for text patterns in files

File Permissions

chmod [permissions] [file]

Change file permissions (e.g., chmod 755 script.sh)

chown [user]:[group] [file]

Change file owner and group

sudo [command]

Execute command with superuser privileges

System Information

whoami

Display current username

hostname

Show system hostname

uname -a

Show system information (kernel version, etc.)

df -h

Show disk usage with human-readable sizes

free -h

Show memory usage with human-readable sizes

ps aux

Show all running processes

top

Show running processes and system resource usage

Package Management (Ubuntu/Debian)

sudo apt update

Update package lists

sudo apt upgrade

Upgrade installed packages

sudo apt install [package]

Install a new package

sudo apt remove [package]

Remove a package

apt search [term]

Search for packages

Network Commands

ping [host]

Test network connectivity to a host

ip addr

Show network interface information

curl [url]

Transfer data from or to a server

wget [url]

Download files from the web

Remote Access & File Transfer

ssh user@hostname

Connect to remote server via SSH

ssh -p 2222 user@host

Connect to SSH on custom port

ssh-keygen -t ed25519

Generate new SSH key pair

ssh-copy-id user@hostname

Copy SSH public key to remote server

ssh-add ~/.ssh/key

Add SSH key to agent

scp file.txt user@host:/path/

Copy file to remote server

scp -r dir/ user@host:/path/

Copy directory to remote server

scp user@host:/path/file.txt ./

Copy file from remote server

rsync -avz src/ user@host:/dest/

Sync directory to remote server

rsync -avz --delete src/ dest/

Mirror sync (delete extra files)

rsync -avzn src/ dest/

Dry run (preview changes without executing)

Text Processing

sort [file]

Sort lines of text files

uniq [file]

Remove duplicate lines from a file

cut -d[delimiter] -f[field] [file]

Extract specific columns from delimited text

tr '[old]' '[new]'

Translate or delete characters

Useful Combinations

ls -la | grep '.txt'

List all .txt files with details

ps aux | grep [process]

Find specific running processes

history | grep [command]

Find previously used commands

find [directory] -name [pattern]

Search for files by name

du -sh [directory]

Show directory size in human-readable format

Help and Documentation

man [command]

Show manual page for a command

apropos [keyword]

Search manual pages for keywords

what-is [command]

Get brief description of a command

help

Show help for shell built-in commands

Remember: The pipe symbol (|) lets you combine commands. For example: ls -la | grep '.txt' | wc -l counts all .txt files.

Permission Numbers Quick Reference

Number Permission Meaning
4 r-- Read only
2 -w- Write only
1 --x Execute only
7 rwx Read, write, execute
6 rw- Read, write
5 r-x Read, execute
  • Module 8: Remote Access & File Transfer - SSH and remote file management
  • Related Resources