
Terminal - Commands using sort - 526 results
sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4
This is sample output - yours may be different.
sort -nt . -k 1,1 -k 2,2 -k 3 -k 4 /tmp/j
2.159.416.20
3.4.160.100
3.40.64.100
3.59.146.22
3.159.144.22
3.195.144.22
10.159.164.22
Sort a list of IPV4 addresses in numerical order. Great as a filter, or within vim using !}
This is sample output - yours may be different.
fc -l | cut -d" " -f2- | sort -bdf
dhclient | grep 6
fc -l
fc -l | cut -d" " -f2-
fc -l | sort -bdf
head passwd
ls
ls
ls
ls /tmp
man dhclient.conf
more /etc/shadow
ps -ef | sort -bdf
ssh gislab63
Often, when sorting you want the sort to ignore extraneous characters. The b, d, and f tell sort to ignore leading blanks, use 'dictionary order' (ignore punctuation), and ignore (fold) case. Add a "u" if you only want one copy of duplicate lines.
This is a great command to use within vim to sort lines of text, using !}sort -bdf
du --max-depth=1 | sort -r -n | awk '{split("k m g",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}'
This is sample output - yours may be different.
[user@host]> bigfiles
123 m .
47 m ./media
27 m ./.mozilla
21 m ./src
14 m ./downloads
1 m ./.openoffice.org
1 m ./uni
288 k ./.gstreamer-0.10
208 k ./sketchbook
128 k ./.config
124 k ./.ipython
56 k ./.fontconfig
32 k ./.pal
I use this on debian testing, works like the other sorted du variants, but i like small numbers and suffixes :)
find . -type d | perl -nle 'print s,/,/,g," $_"' | sort -n | tail
This is sample output - yours may be different.
find . -type f -name "*.java" -print0 | xargs -0 -n 1 svn blame | sed -n 's/^[^a-z]*\([a-z]*\).*$/\1/p' | sort | uniq -c | sort -n
This is sample output - yours may be different.
sed -e "s/| /\n/g" ~/.bash_history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head
This is sample output - yours may be different.
"some line input" | sort | uniq -c | sort -nr
This is sample output - yours may be different.
sed 's/[ \t]*$//' < emails.txt | tr 'A-Z' 'a-z' | sort | uniq > emails_sorted.txt
This is sample output - yours may be different.
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'
This is sample output - yours may be different.
3.3G .
539.5M ./doc
494.2M ./locale
324.2M ./javadoc
229.3M ./icons
187.0M ./gnome
156.1M ./texmf
154.0M ./kde4
141.1M ./eclipse
135.5M ./fonts
91.4M ./gimp
62.1M ./java
Probably only works with GNU du and modern perls.
comm -1 -2 <(sort file1) <(sort file2)
This is sample output - yours may be different.
cat foo.csv bar.csv | sort -t "," -k 2 | uniq
This is sample output - yours may be different.
The value for the sort command's -k argument is the column in the CSV file to sort on. In this example, it sorts on the second column. You must use some form of the sort command in order for uniq to work properly.
lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
This is sample output - yours may be different.
sten@fenris:~$ sudo lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
3002 php5-cgi
122 master
116 sshd
115 freeswitc
82 mysqld
60 ssh
60 slapd
52 lighttpd
47 beam.smp
43 inet_geth
I think I could cut down the number of pipes here, any suggestions?
sed -n -e '/postfix\/smtp\[.*status=sent/s/^.*to=<\([^>]*\).*$/\1/p' /var/log/mail.log | sort -u
This is sample output - yours may be different.
foo@foo.com
foo2@foo2.com
This assumes your mail log is /var/log/mail.log
netstat -alpn | grep :80 | awk '{print $4}' |awk -F: '{print $(NF-1)}' |sort |
uniq -c | sort -n
This is sample output - yours may be different.
1 127.0.0.1
8 192.168.1.147
21 192.168.1.146
Useful to check DDoS attacks on servers.
last | grep -v "^$" | awk '{ print $1 }' | sort -nr | uniq -c
This is sample output - yours may be different.
1 wtmp
2 reboot
31 oracle
15 jsmith
142 jdoe
3 root
This command takes the output of the 'last' command, removes empty lines, gets just the first field ($USERNAME), sort the $USERNAMES in reverse order and then gives a summary count of unique matches.
diff <(sort file1.txt) <(sort file2.txt)
This is sample output - yours may be different.
Sees if two records differ in their entries, irrespective of order.
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
This is sample output - yours may be different.
egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
This is sample output - yours may be different.
find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}'
This is sample output - yours may be different.
798231bfb8892963eddffda0deb6b381
For quick validation of folder's file-contents (structure not taken into account) - I use it mostly to check if two folders' contents are the same.
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
This is sample output - yours may be different.
[root@vps10 root]# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
8 200.217.193.102
8 82.101.189.139
9 84.195.188.60
11 189.63.98.3
11 60.28.166.169
13 24.227.166.150
15 200.214.44.134
16 189.92.141.77
22 189.14.101.44
31 127.0.0.1
This command does a tally of concurrent active connections from single IPs and prints out those IPs that have the most active concurrent connections. VERY useful in determining the source of a DoS or DDoS attack.
ps -eo pcpu,pid,args | sort -n
This is sample output - yours may be different.
0.8 25686 gnome-terminal
1.3 23966 /usr/lib/thunderbird/thunderbird-bin
35.9 6638 /usr/lib/firefox-3.0.6/firefox
Useful to detect which process is causing system loads. It shows process PID so as we can take further actions.
This is sample output - yours may be different.
4 mvc_example.php
72 caseconverter
80 contact
248 hangman
Very useful for finding the largest files and subdirectories at any given point. Any user can run it from current location just when need to know their largest files and subtdirectories from a certain point down as well.
netstat -anl | grep :80 | awk '{print $5}' | cut -d ":" -f 1 | uniq -c | sort -n | grep -c IPHERE
This is sample output - yours may be different.
This will tell you who has the most Apache connections by IP (replace IPHERE with the actual IP you wish to check). Or if you wish, remove | grep -c IPHERE for the full list.
netstat -pant 2> /dev/null | grep SYN_ | awk '{print $5;}' | cut -d: -f1 | sort | uniq -c | sort -n | tail -20
This is sample output - yours may be different.
1 125.162.92.184
1 125.164.121.250
1 125.71.93.177
1 128.107.229.110
1 189.147.101.11
1 202.40.210.145
1 202.40.210.164
1 203.130.201.198
1 41.201.190.148
1 41.201.238.148
1 81.199.44.161
1 81.202.11.253
2 202.134.71.158
7 218.4.59.190
List top 20 IP from which TCP connection is in SYN_RECV state.
Useful on web servers to detect a syn flood attack.
Replace SYN_ with ESTA to find established connections
du -hs * | grep '^[0-9,]*[MG]' | sort -rn
This is sample output - yours may be different.
170M Richard Stevens TCP-IP Illustrated Vol 2.pdf
153M Richard_Stevens_UNIX_Network_Programming_Sec_Ed_Vol_1.pdf
126M Rederik_Smith_Full_Docs_FreeBSD_rus.pdf
117M WhiteParus.Unix.Rukovodstvo_Sysadmina.pdf
115M Richard_Stevens_Advanced_Programming_in_the_UNIX_Environment.pdf
89M Richard Stevens Tcp-Ip Illustrated Vol 1.pdf
80M Richard_Stevens_UNIX_Network_Programming_Sec_Ed_Vol_2.pdf
73M IEEE
22M tannenbaum