Basis
Shortcuts
Ctrl + A
Go to the beginning of the line.Ctrl + E
Go to the end of the line.
Ctrl + Alt + F2
Open TTY 2 (there are 6 TTYs on Linux that can be opened in parallel, from F1 to F6).
LS
ls -lS
Sort by size.ls -lX
Sort by extension.
Files
FIND
find /search/path/ -name myFile
Find a file by name.
find /search/path/ -type f
Find by type (f (file), d (directory), l (symbolic link)).find /search/path/ -size 50M
Find a file by size (c (octets / bytes), k (kilo octets), M (mega octets), G (giga octets), b (blocs of 512 octets).
find /search/path/ -user myUser
Find a file by user.find /search/path/ -group myGroup
Find a file by group.find /search/path/ -perm 000
Find a file by permission.
find /search/path/ -name .txt -exec rm {};
Find files and execute a command for each of them ({}is replaced by what is found byfind).
UNIQ
uniq
Deletes duplicate lines in a file (the comparison is done with the previous line, so usesort -dbefore).
uniq -u
Return lines that appear only once.uniq -d
Return lines that appear more than once.
DIFF
diff myFile1 myFile2
Return differences between the two files.
diff <(ls my_directory_1) <(ls my_directory_2)
Return differences between two directory contents (using process substitution).
PS2PDF
ps2pdf -d PDFSETTINGS=/ebook myFile.pdf myFile-Compressed.pdf
Compress a PDF.
/screen
72 dpi, lowest quality, smallest file size./ebook
150 dpi, better quality, slightly larger size./prepress
300 dpi, high quality, larger size./printer
300 dpi, printer-quality output./default
Useful for multiple purposes, may result in large files.
String Manipulation
GREP
grep myString myFile
Return lines containing myString.grep -e myString1 -e myString2
Match multiple patterns.
grep -f myFileA myFileB
Read the search patterns from a file (myFileA).grep -vxF -f myFileA myFileB
Prints all lines infileAthat are not found infileB.
grep -E
Use a Regex.grep -F
Interpret patterns as fixed strings.
grep -i
Return lines that correspond to the string but is not case-sensitive.grep -x
Return lines that correspond exactly to the string.grep -v
Return lines that do not contain the string.
grep -A 12
Return 12 lines after the match.grep -B 12
Return 12 lines before the match.grep -C 12
Return 12 lines before and after the match.
grep -c
Counts the number of lines containing the string.grep -n
Each line containing the string is numbered.
grep -l
Return the names of files containing the string.grep -h
Do not return the folder prefix.
CUT
cut -c 1-12
Return characters from 1 to 12 of the input string.cut -c -12
Return the first 12 characters of the input string.cut -c 12-
Return the last 12 characters of the input string.cut -c 1,12
Return characters 1 and 12 of the input string.
cut -d : -f 2
Return the second field (-f 2). Field separator is defined with-d.
SED
sed -d
Remove a line ("/.../d").sed -s
Replace a string ("s/old/new/").
sed -g
Apply on all lines ("/old/new/g").
TR
tr 'a-z' 'A-Z'
Replace lower case letters with upper case letters.tr 'abcd' 'jkmn'
Replaceabyj,bbyk,cbymanddbyn.
SORT
sort myFile.txt
Sort the contents of a file.
sort -d myFile.txt
Sort using only blanks and alphanumeric chars (dictionary order).
sort -k 2 myFile.txt
Sort on the second column in the file (separated by space).
Monitoring
WATCH
watch my-command
Run a command every 2 seconds (default).
-n 0.5
Specify the interval in seconds.-d
Highlight changes.
JOURNALCTL
journalctl -u my-service.service
Returns logs for the specified service.journalctl -fu my-service.service
Follow logs for the specified service.
journatl --since "1 hour ago"
Returns logs since one hour ago.journalctl --since "2025-01-01 12:00:00" --until "2025-01-01 13:00:00"
Returns logs between given dates.
Networking
DNS
dig my.domain
Return records for the given domain.dig @my.dns.provider my.domain
Specify the server to use for the query.
(e.g query the authoritative server to check if record have been correctly updated).dig -x 12.12.12.12
Reverse DNS.
dig +short my.domain
Short form answer (only record value).dig +noall +answer my.domain
Short form answer (ttl, type, record).dig +nostats +nocomments +nocmd my.domain
Short form answer (ttl, type, record).
dig +trace my.domain
Shows steps in the lookup chain.
dig -t NS my.domain
Return NS Records (authoritative servers for the domain).dig -t TXT my.domain
Return TXT Records.dig -t CNAME my.domain
Return CNAME Record.dig -t MX my.domain
Return MX Records.
dig +udp my.domain
Query using UDP.dig +tcp my.domain
Query using TCP.
SSL/TLS
openssl s_client -connect [MY_HOST]:[MY_PORT]
Make an SSL/TLS client request.
SS
ss -tunp
Returns established connections (TCP and UDP).
ss -tulnp
Returns listening sockets (TCP and UDP).
ss -tuanp
Returns established connection and listening sockets (TCP and UDP).
NMCLI
nmcli device
List network devices (ethernet, wifi, ...)
nmcli device wifi connect MY_SSID
Connect to specified SSID.
nmcli connection down MY_SSID
Disconnect from specified SSID.nmcli connection up MY_SSID
Connect back to a known SSID.
Disk Management
Disk usage
alias dutop='sh -c '''du -h --all --max-depth=1 "$1" | sort -hr | head -n 20 ''' _'
Alias for searching large files (vanilla alternative to ncdu).
WIPEFS (Erase partitions)
sudo wipefs -a /dev/sda
Erase filesystem and partition signatures (without deleting data).
FDISK (Edit partitions)
sudo fdisk /dev/sda
g (create GPT table) or o (create legacy DOS/MBR table).
n (new partition, use all default to use whole disk).
w (write changes and exit).
MKFS (Format partitions)
mkfs -t ext4 /dev/sda
Create an ext4 filesystem in a disk partition (old command).sudo mkfs.ext4 /dev/sda
Create an ext4 filesystem in a disk partition (new command).sudo mkfs.ext4 -L MY_LABEL /dev/sda
Create an ext4 filesystem in a disk partition and set the volume label.
