File handling
ls
The ls
command lists the files in a directory:
-
-l
= details -
-t
= sort by modification date -
-r
= reverses the ranking order -
-R
= lists all subfolders and their files -
-h
= more readable size in M/G/T -
-a
= displays hidden files and folders - For convenience, please use
ls -ltrh
.
head
head
displays the first lines of a file:
-
-n
= number of lines to display
tail
The tail
command displays the last lines of a file:
-
-n
= number of lines to display -
-f
= allows to monitor the log (up to Ctrl + C)
Monitoring tools
-
top
-> The classing monitoring -
htop
-> More advanced version -
iftop
-> Network monitoring -
iotop
-> Monitoring of disk activity by process
Network
-
netstat
-> Allows you to obtain a large amount of information
netstat -tupan
argument provides most of the necessary information (e.g. open connections, listening ports)
Disk space
df
df
allows you to list filesystems with occupied/free disk space:
-
-h
= more readable size in M/G/T -
-i
= displays occupied/unoccupied inodes
du
du
displays the disk space used by a tree:
-
-s
= Means summary edition, it displays only the summary of the tree structure there ar no display of sub-folders -
-k
= display in KB -
-m
= display in MB -
-h
= display with the most readable unit -
-d
ou--max-depth
= depth of the listing (e.g. "du -d 1
" will display the compiled size of the 1st level sub-folders)
Miscellaneous
sort
sort
allows you to sort the display:
-
-k
= column used for sorting -
-n
= sort by number -
-h
= intelligent sorting by size (useful if used withdu
)
uniq
uniq
allows you to delete duplicate lines:
-
-c
= duplicate counts
wc
wc
counts the number of characters, words, lines:
-
-c
= counts the characters -
-l
= counts the lines -
-w
= counts the words
Combined commands
-
netstat -tupan | grep LISTEN
- lists the listening ports. -
du -h -d 1 | sort -h
- display of the size of the first level folders with sorting by size -
tail -n 100000 access.log | awk '{ print $1; }' | sort | uniq -c | sort -k 1 -n
- IPs ranking on the last 100 000 lines of the access.log file (e.g : 1st column of the file = IP address of the customer) -
cat file.txt | uniq | wc -l
- Displays the number of unique lines