This is a oneliner bash command to determine my 10 most used linux commands according to my history file
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
The result
1 188 37.6% vi
2 38 7.6% ls
3 24 4.8% cat
4 22 4.4% apt-get
5 12 2.4% date
6 11 2.2% tail
7 11 2.2% cd
8 10 2% rm
9 10 2% man
10 9 1.8% basename
It looks like i use vim a lot on my home server. You should try it yourself and see what commands you use the most.
Source: http://linux.byexamples.com
Tags: awk, bash, count, grep, head, nl, sort
Posted by Hans-Henry Jakobsen
This is one way to determine the ports needed to open in your iptables rules to get NFS to work properly. First we need to determine the ports NFS uses
rpcinfo -p | awk -F " " '{print $3 ", " $4 ", " $5}' | sort | uniq
Notice!
Since portmap assigns ports on random this example is only valid as long as you don’t restart your NFS.
On my system, a RedHat Enterprise Linux WS 4, the result was
proto, port, tcp, 111, portmapper tcp, 2049, nfs tcp, 32771, nlockmgr tcp, 768, rquotad tcp, 782, mountd udp, 111, portmapper udp, 2049, nfs udp, 32768, nlockmgr udp, 765, rquotad udp, 779, mountd
This gave me a nice overview of protocols (tcp/udp) and ports used.
Now the rules
iptables -A RH-Firewall-1-INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -p tcp -m state --state NEW -m multiport --dports 111,2049,32771,768,782 -j ACCEPT iptables -A RH-Firewall-1-INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -p udp -m state --state NEW -m multiport --dports 111,2049,32768,765,779 -j ACCEPT
You see that the multiport statement is just like the result of my rpcinfo command above.
Remember to save your new rules, othervise they will disappear the next time the iptables rules are being loaded.
In addition to this rule you should add the iptables rule for ssh access I wrote about earlier.
Another way to determine the ports
nmap -sC -p 111 localhost
Notice!
This solution won’t work after a reboot of the server since NFS changes ports. One way to overcome this problem is to follow the instructions in a newer post I’ve made about RedHat and NFS.
Tags: awk, iptables, nmap, rpcinfo, sort
Posted by Hans-Henry Jakobsen
If you use the –queryformat argument with rpm it is possible to query RPMs for different architectures installed
# rpm -qa --queryformat %{NAME}-%{VERSION}-%{ARCH}\\n | grep dbus-glib | sort
Result
dbus-glib-0.22-12.EL.5-i386
dbus-glib-0.22-12.EL.5-x86_64
This can also be used in one of my previous posts: Remove duplicate packages when querying the rpm database.
Tags: Fedora, RedHat, rpm, sort
Posted by Hans-Henry Jakobsen
Sorting IP addresses using sort is not easy because the dot confuses sort.
This line makes it possible to sort by the whole value of the address
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 ipaddresses.txt
You can also sort by the last octet
sort -r. -n +3.0 ipaddresses.txt
Posted by Hans-Henry Jakobsen
ps -e -o pid,args --forest
List processes by % cpu usage
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'
List processes by mem usage
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS
List info for particular process IDs
ps -p 1,2
Posted by Hans-Henry Jakobsen