Show Menu

Linux cheatsheet Cheat Sheet by

A cheat sheet of the commands and hints I use most for Linux


ls $(which cp)

ls `which cp`
Command expansion
mkdir {2017...2­020­}-{­01-12}
Brace expansion
echo text ~/*.txt {a,b} $USER
Variable expansion
echo "text ~/*.txt {a,b} $USER"
" expansion
echo 'text ~/*.txt {a,b} $USER'
' expansion (NONE)

Redire­ction & Commands

ls > file.txt
Standard Out
ls 2> file.txt
Standard Error
ls > file.txt 2>&1

ls &> file.txt
Standard Out & Error
ls | tee file | wc -l
Read stdin & writes stdout
cmd1 ; cmd2
Run cmd1 then cmd2
cmd1 && cmd2
Run cmd2 if cmd1 is OK
cmd1 || cmd2
Run cmd2 if cmd1 is KO

su / sudo

su [-[l]] [user]
Become another user,
by default. If
, load user envs and working dir.
su [user] -c 'command'
Execute command as user. Default
sudo [-u user] command
Execute command as user. Default
sudo -ll
Which commands I'm allowed to execute
file. Example
teralco ALL=(root) NOPASSWD: /etc/i­nit.d/­jboss

teralco ALL=(j­boss) NOPASSWD: /bin/kill


ufw status [verbose|numbered]
Show status and rules
ufw default deny incoming

ufw default allow outgoing
Deny all incoming traffic by default
Allow all outgoing traffic by default
ufw [allow|deny] from IP to [any|i­nte­rfa­ce_­name] [proto tcp|udp] port PORT
Full allow/deny rule
ufw [allow|deny] servic­e_name
Allow/deny a service (
ssh www ftp ...
ufw [enable|disable]
ufw delete [rule|number]

Alt commands

/var/l­og/­mes­sages & /var/l­og/­syslog
System log files
script file
Record session commands in file
nohup command  &
Keep command running even after close session
tar -Jxvf file.t­ar.xz [-C dest_f­older]
Extract xz (higher compress ratio)
zip -FF --out && unzip
Merge zip files (, x.z01, x.z02)
ps aux --sort -rss
Higher memory consum­ption processes
fdisk -l
List partition tables
dd bs=4M if=inp­ut.iso of=/de­v/sd? conv=f­dat­async
Burn iso in device


find path -name *.log -type f -mtime +5 -exec rm -rvf {} \;
Find and delete files older than 5 days
find path -type f -printf "­%s­\t%p­\n" | sort -rn | head -10
Find the 10 biggest files
grep -rlie 'pattern' path
Find files with pattern content
du -cks path/* | sort -rn | head -10
Find biggest dirs
du -sh path
Dir size


chmod [u|g|o­][+­|-|­=][rwx] dir_file
Change permis­sions
chmod u[+|-]s file
Set uid. File is always exec as owner user
chmod g[+|-]s dir
Set gid. New files in folder are always owned by folder owner
chmod [+|-]t dir
Sticky Bit. Files in dir can only be renamed or removed by owner or root
umask xxxx
Set default permis­sions to dirs


Global env config files
User env config file
Print defined env vars
Show defined aliases
export VAR
Make a VAR available to child process
source script

. script
Load a file into current script or shell session


ip addr
Show ips
ifup|ifdown interf­ace­_name
Up or down an interface
File interfaces are defined
hostna­mectl [set-h­ostname hostname]
Manage hostname (
) without restarting
netstat -tuln
All tcp and udp listening ports
ss -tuln
All tcp and udp listening ports
nc -vz host port
Scan port in host


ssh-keygen [-f /etc/s­sh/­ssh­_ho­st_­rsa­_key] -t rsa -b 4096
Generate ssh rsa key. By default
ssh-co­py-id [-i ~/.ssh­/mykey] user@host
Copy ssh key in remote host (
). By default
ssh user@host command
Exec command in host
ssh -J hostA hostB
Connect to hostB through hostA (Jumping). Identi­fic­ation in localhost. Can use
ssh -D port -fCqN user@host
Proxy socket (HTTP and HTTPS traffic) through port.
ssh -nNT -L 9000:r­emo­te_­ser­ver:80 user@host
Tunneling (Local port forwar­ding). Map
through host
ssh -nNT -R 9000:l­oca­lho­st:3000 user@host
Tunneling (Remote port forwar­ding). Map


Nice, I will use it.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          mod_rewrite Cheat Sheet
          Vim NERDTree Cheat Sheet