Linux Commands Cheatsheet

account
admin
api
archive
backup
commands
compress
connections
connectivity
copy
delete
directory
disk
download
files
filter
history
info
installation
interactive
kernel
list
locate
logs
management
memory
monitoring
move
navigation
network
ownership
package
path
permissions
ports
process
remote
remove
rename
search
secure
security
service
shell
size
status
storage
system
terminate
text
transfer
user
view
web

ls

file

List directory contents

ls -la
Common options:
  • -l (detailed list)
  • -a (show hidden)
  • -h (human readable)
  • -R (recursive)
  • -t (sort by time)
files
directory
list

Use 'ls -lah' for most comprehensive view

cd

file

Change directory

cd /path/to/directory
Common options:
  • cd - (previous directory)
  • cd ~ (home directory)
  • cd .. (parent directory)
directory
navigation

Use 'cd -' to toggle between last two directories

pwd

file

Print working directory

pwd
directory
path

Shows the full path of current directory

cp

file

Copy files and directories

cp -r source destination
Common options:
  • -r (recursive)
  • -i (interactive)
  • -v (verbose)
  • -p (preserve attributes)
files
copy

mv

file

Move/rename files and directories

mv oldname newname
Common options:
  • -i (interactive)
  • -v (verbose)
  • -f (force)
files
move
rename

rm

file

Remove files or directories

rm -rf directory
Common options:
  • -r (recursive)
  • -f (force)
  • -i (interactive)
files
delete
remove

Be careful with rm -rf, it's irreversible!

chmod

file

Change file permissions

chmod 755 file.txt
Common options:
  • -R (recursive)
  • +x (add execute)
  • -w (remove write)
permissions
security

Use numeric (777) or symbolic (u+x) notation

ps

process

Report process status

ps aux
Common options:
  • aux (all processes)
  • -ef (full format)
  • -u (user processes)
process
status
monitoring

top

process

Display system processes

top
Common options:
  • -u (user processes)
  • -n (number of iterations)
  • -b (batch mode)
process
monitoring
system

kill

process

Terminate processes

kill -9 PID
Common options:
  • -9 (SIGKILL)
  • -15 (SIGTERM)
  • -l (list signals)
process
terminate

netstat

network

Network statistics

netstat -tulpn
Common options:
  • -t (TCP)
  • -u (UDP)
  • -l (listening)
  • -p (programs)
  • -n (numeric)
network
ports
connections

ping

network

Test network connectivity

ping -c 4 google.com
Common options:
  • -c (count)
  • -i (interval)
  • -w (timeout)
network
connectivity

ssh

network

Secure shell remote login

ssh user@hostname
Common options:
  • -p (port)
  • -i (identity file)
  • -v (verbose)
network
remote
secure

systemctl

system

Control the systemd system and service manager

systemctl status service-name
Common options:
  • start
  • stop
  • restart
  • enable
  • disable
service
system
management

journalctl

system

Query the systemd journal

journalctl -u service-name
Common options:
  • -u (unit)
  • -f (follow)
  • -n (lines)
  • --since
logs
system
monitoring

df

system

Report file system disk space usage

df -h
Common options:
  • -h (human readable)
  • -T (file system type)
  • -i (inodes)
disk
storage
system

useradd

user

Create a new user

useradd -m username
Common options:
  • -m (create home)
  • -s (shell)
  • -G (groups)
user
account
management

apt

package

Package management

apt install package-name
Common options:
  • update
  • upgrade
  • install
  • remove
  • autoremove
package
installation
management

Use apt-get for scripts, apt for interactive use

grep

file

Search text patterns in files

grep 'pattern' file.txt
Common options:
  • -i (ignore case)
  • -r (recursive search)
  • -v (invert match)
  • -n (show line numbers)
search
text
filter

Use -R for recursive search including symlinks

find

file

Search for files in directory hierarchy

find /path -name '*.txt'
Common options:
  • -name (search by name)
  • -type f (files only)
  • -type d (directories only)
  • -mtime (modified time)
search
files
locate

Powerful tool for finding files with various criteria

tar

file

Archive files

tar -czvf archive.tar.gz directory/
Common options:
  • -c (create)
  • -x (extract)
  • -z (gzip)
  • -v (verbose)
  • -f (file)
archive
compress
backup

Common formats: .tar.gz, .tgz, .tar.bz2

wget

network

Download files from the web

wget https://example.com/file
Common options:
  • -c (continue)
  • -O (output file)
  • -P (directory prefix)
  • --limit-rate
download
network
web

curl

network

Transfer data from/to a server

curl -X GET https://api.example.com
Common options:
  • -X (HTTP method)
  • -H (headers)
  • -d (data)
  • -o (output file)
network
api
transfer

du

system

Estimate file space usage

du -sh *
Common options:
  • -s (summarize)
  • -h (human readable)
  • --max-depth
  • -a (all files)
disk
storage
size

free

system

Display memory usage

free -h
Common options:
  • -h (human readable)
  • -s (seconds interval)
  • -t (show total)
memory
system
monitoring

htop

process

Interactive process viewer

htop
Common options:
  • -u (user processes)
  • -d (delay)
  • -s (sort column)
process
monitoring
interactive

More user-friendly alternative to top

history

system

Command line history

history | grep ssh
Common options:
  • -c (clear)
  • -d (delete entry)
  • -w (write to file)
history
commands
shell

Use !n to execute command number n from history

tail

file

Output the last part of files

tail -f /var/log/syslog
Common options:
  • -f (follow)
  • -n (lines)
  • --pid
  • -c (bytes)
logs
monitoring
files

Commonly used for log monitoring

head

file

Output the first part of files

head -n 10 file.txt
Common options:
  • -n (lines)
  • -c (bytes)
  • -q (quiet)
files
text
view

less

file

View file content with pagination

less file.txt
Common options:
  • -N (show line numbers)
  • -S (chop long lines)
  • -i (ignore case)
files
view
text

More feature-rich than more command

chown

file

Change file owner and group

chown user:group file
Common options:
  • -R (recursive)
  • -v (verbose)
  • --from=
permissions
ownership
security

sudo

system

Execute command as superuser

sudo command
Common options:
  • -u (user)
  • -i (login shell)
  • -s (shell)
security
permissions
admin

Use sudo -i for root shell

uname

system

Print system information

uname -a
Common options:
  • -a (all)
  • -r (kernel release)
  • -m (machine hardware)
system
info
kernel
X
LinkedIn