Basis
Shortcuts
Ctrl + AGo to the beginning of the line.
Ctrl + EGo to the end of the line.
Ctrl + Alt + F2Open TTY 2 (there are 6 TTYs on Linux that can be opened in parallel, from F1 to F6).
Files
Search for Files
find /search/path/ -name myFileFind a file by name.
find /search/path/ -type fFind by type (f (file), d (directory), l (symbolic link)).
find /search/path/ -size 50MFind 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 myUserFind a file by user.
find /search/path/ -group myGroupFind a file by group.
find /search/path/ -perm 000Find 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
uniqDeletes duplicate lines in a file (the comparison is done with the previous line, so use
sort -d
before).
uniq -uReturn lines that appear only once.
uniq -dReturn lines that appear more than once.
Diff
diff myFile1 myFile2Return differences between the two files.
String Manipulation
Grep
grep myString myFileReturn lines containing myString.
grep -e myString1 -e myString2Match multiple patterns.
grep -EUse a Regex.
grep -FInterpret patterns as fixed strings.
grep -iReturn lines that correspond to the string but is not case-sensitive.
grep -A 12Return 12 lines after the match.
grep -B 12Return 12 lines before the match.
grep -C 12Return 12 lines before and after the match.
grep -xReturn lines that correspond exactly to the string.
grep -vReturn lines that do not contain the string.
grep -cCounts the number of lines containing the string.
grep -nEach line containing the string is numbered.
grep -lReturn the names of files containing the string.
grep -hDo not return the folder prefix.
grep -vxFf myFileA myFileBPrints all lines in
fileA
that are not found infileB
.
Cut
cut -c 1-12Return characters from 1 to 12 of the input string.
cut -c -12Return the first 12 characters of the input string.
cut -c 12-Return the last 12 characters of the input string.
cut -c 1,12Return characters 1 and 12 of the input string.
cut -d : -f 2Return the second field (
-f 2
). Field separator is defined with-d
.
Sed
sed -dRemove a line (
"/.../d"
).sed -sReplace a string (
"s/old/new/"
).
sed -gApply on all lines (
"/old/new/g"
).
Tr
tr 'a-z' 'A-Z'Replace lower case letters with upper case letters.
tr 'abcd' 'jkmn'Replace
a
byj
,b
byk
,c
bym
andd
byn
.
Sort
sort myFile.txtSort the contents of a file.
sort -d myFile.txtSort using only blanks and alphanumeric chars (dictionary order).
sort -k 2 myFile.txtSort on the second column in the file (separated by space).
Monitoring
Watch
watch my-commandRun a command every 2 seconds (default).
-n 0.5Specify the interval in seconds.
-dHighlight changes.
Journalctl
journalctl -u my-service.serviceReturns logs for the specified service.
journalctl -fu my-service.serviceFollow 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 +short my.domainReturn only IP.
dig -x 12.12.12.12Reverse DNS.
dig -t TXT my.txt.recordReturn TXT Record.
dig -t CNAME my.txt.recordReturn CNAME Record.
dig -t MX my.txt.recordReturn MX Record.
SSL/TLS
openssl s_client -connect [MY_HOST]:[MY_PORT]Make an SSL/TLS client request.
Sockets
ss -tunpReturns established connections (TCP and UDP).
ss -tulnpReturns listening sockets (TCP and UDP).
ss -tuanpReturns established connection and listening sockets (TCP and UDP).
NMCLI
nmcli deviceList network devices (ethernet, wifi, ...)
nmcli device wifi connect MY_SSIDConnect to specified SSID.
nmcli connection down MY_SSIDDisconnect from specified SSID.