Posted: 18 October 2023. At: 8:51 AM. This was 9 months ago. Post ID: 18626
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

Get the most used Linux commands easily on either bash or zsh.

Getting a list of the most used Linux commands on your Linux system and a count of how many times the command has been executed is very simple.

This one-liner will get this information very easily. If you are using zsh as well as bash it will get the information from both shells.

(jcartwright@localhost) 192.168.1.5 ~  $ cat ~/.bash_history <(cut -d";" -f2 ~/.zsh_history) | sed "s|sudo ||g; s/|/\n/g" | awk '{hist[$1]++} END {for \
(cmd in hist) print hist[cmd], cmd}' | sort -n | tail -n20
cut: /home/jcartwright/.zsh_history: No such file or directory
15 screenfetch
17 awk
17 make
19 cat
21 ffmpeg
22 whatweb
23 export
25 ./freeram
26 yt-dlp
27 tesseract
29 grep
34 mpv
46 sed
52 ls
53 mc
66 su
68 gcc
126 cd
161 htmlq
162 curl

This is a very useful bash shell tip.

Get the amount of free disk space on your / partition.

(jcartwright@localhost) 192.168.1.5 ~  $ echo "There is: $(df -Hla / | awk '/dev/ {print $3 " remaining of",$4 " \
on the / partition."}')"
There is: 15G remaining of 61G on the / partition.

Get the load average and the amount of CPU cores using bash.

(jcartwright@localhost) 192.168.1.5 ~  $ echo "The load average is: $(cut -f1 -d ' ' /proc/loadavg). The CPU has\
 $(grep -c ^processor /proc/cpuinfo 2>/dev/null) cores."
The load average is: 1.17. The CPU has 12 cores.
(jcartwright@localhost) 192.168.1.5 ~  $ echo "The load average is: $(cut -f1 -d ' ' /proc/loadavg). The CPU has\
 $(grep -c ^processor /proc/cpuinfo 2>/dev/null) cores."
The load average is: 1.16. The CPU has 12 cores.

This is also very helpful.

(jcartwright@localhost) 192.168.1.5 ~  $ echo "The load average is: $(cut -f1 -d ' ' /proc/loadavg). The CPU has\
 $(grep -c ^processor /proc/cpuinfo 2>/dev/null) cores."
echo "Current CPU usage is: $(top -bn 2 -d 0.01 | grep '^%Cpu' | \
tail -n 1 | awk '{print $2+$4+$6}')%"
The load average is: 0.83. The CPU has 12 cores.
Current CPU usage is: 10%

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.