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).

Files


Search for Files

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 by find).


Uniq

uniq
Deletes duplicate lines in a file (the comparison is done with the previous line, so use sort -d before).

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.

String Manipulation


Grep

grep myString myFile
Return lines containing myString.

grep -e myString1 -e myString2
Match multiple patterns.

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 -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 -x
Return lines that correspond exactly to the string.

grep -v
Return lines that do not contain the string.

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.

grep -vxFf myFileA myFileB
Prints all lines in fileA that are not found in fileB.


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'
Replace a by j, b by k, c by m and d by n.


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 +short my.domain
Return only IP.

dig -x 12.12.12.12
Reverse DNS.

dig -t TXT my.txt.record
Return TXT Record.

dig -t CNAME my.txt.record
Return CNAME Record.

dig -t MX my.txt.record
Return MX Record.


SSL/TLS

openssl s_client -connect [MY_HOST]:[MY_PORT]
Make an SSL/TLS client request.


Sockets

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.