
Terminal - Commands using sort - 537 results
for i in `du --max-depth=1 $HOME | sort -n -r | awk '{print $1 ":" $2}'`; do size=`echo $i | awk -F: '{print $1}'`; dir=`echo $i | awk -F: '{print $NF}'`; size2=$(($size/1024)); echo "$size2 MB used by $dir"; done | head -n 10
This is sample output - yours may be different.
67 MB used by /var/log
42 MB used by /var/log/gdm
9 MB used by /var/log/ConsoleKit
2 MB used by /var/log/munin
1 MB used by /var/log/kismet
1 MB used by /var/log/dist-upgrade
0 MB used by /var/log/apache2
0 MB used by /var/log/installer
0 MB used by /var/log/vmware
0 MB used by /var/log/cups
fancy command line ncdu clone
awk 'BEGIN{srand()}{print rand(),$0}' SOMEFILE | sort -n | cut -d ' ' -f2-
This is sample output - yours may be different.
This appends a random number as a first filed of all lines in SOMEFILE then sorts by the first column and finally cuts of the random numbers.
sort -n <( for i in $(find . -maxdepth 1 -mindepth 1 -type d); do echo $(find $i | wc -l) ": $i"; done;)
This is sample output - yours may be different.
find . -name \*.mp3 -printf "%C+ %h/%f\n" | sort -r | head -n20 | awk '{print "\""$2"\""}' | xargs -I {} cp {} ~/tmp
This is sample output - yours may be different.
Change ~/tmp to the destination directory, such as your mounted media. Change -n20 to whatever number of files to copy. It should quit when media is full. I use this to put my most recently downloaded podcasts onto my phone.
du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh
This is sample output - yours may be different.
find / \( -name "*.log" -o -name "*.mylogs" \) -exec ls -lrt {} \; | sort -k6,8 | head -n1 | cut -d" " -f8- | tr -d '\n' | xargs -0 rm
This is sample output - yours may be different.
This works on my ubuntu/debian machines.
I suspect other distros need some tweaking of sort and cut.
I am sure someone could provide a shorter/faster version.
fc-list | cut -d ':' -f 1 | sort -u
This is sample output - yours may be different.
Andale Mono
Arab
Arial
Arial Black
AR PL UMing CN
AR PL UMing HK
AR PL UMing TW
AR PL UMing TW MBE
Balker
Bitstream Charter
Bitstream Vera Sans
Bitstream Vera Sans Mono
Bitstream Vera Serif ....
See all fonts installed in your system
awk -F\" '{print $4}' *.log | grep -v "eviljaymz\|\-" | sort | uniq -c | awk -F\ '{ if($1>500) print $1,$2;}' | sort -n
This is sample output - yours may be different.
jaymz@bowser:~/Desktop/tmp$ awk -F\" '{print $4}' *.log | grep -v "eviljaymz\|\-" | sort | uniq -c | awk -F\ '{ if($1>500) print $1,$2;}' | sort -n
517 http://kyberia.sk/id/63756
621 http://kyberia.sk/id/15
628 http://bdelive.fr/shoutbox_view.php?0?auto_refresh=1
644 http://digg.com/all/upcoming/most
658 http://winkftp.free.fr/minichat/minichatone.php
690 http://loading.se/forum.php?thread_id=125&page=412
704 http://www.reddit.com/new/
715 http://www.okoun.cz/boards/komixove_stripy
726 http://www.skyscrapercity.com/showthread.php?t=521993&page=343
759 http://www.reddit.com/r/programming/comments/7zena/reasons_why_people_who_work_with_computers_seem/
760 http://www.kalerab.sk/forum.php?forumid=1243
787 http://www.graphilla.com/viewtopic.php?t=15983&start=1000
819 http://www.google.com/reader/view/
878 http://www.reddit.com/?count=25&after=t3_7z5oj
884 http://www.diskusjon.no/index.php?showtopic=690294&st=8680
998 http://www.reddit.com/top/
1151 http://www.imilovice.cz/main/forum.php?action=showthread&threadid=20192
1239 http://www.ziapps.com/
1259 http://www.jimmyr.com/
1369 http://www.nyx.cz/index.php?l=topic;id=64
1381 http://www.stumbleupon.com/toolbar/
2559 http://twitturls.com/
2763 http://www.reddit.com/
2897 http://www.waarmaarraar.nl/opmerkelijkbeeld/0/GO/0/opmerkelijke_beelden.html
2994 http://www.reddit.com/r/pics/
4445 http://www.reddit.com/r/programming/
8222 http://www.bdelive.fr/shoutbox_view.php?0?auto_refresh=1
24220 http://www.plurk.com/getWidget?uid=423872&h=375&w=190&u_info=1&bg=cf682f&tl=cae7fd
This prints a summary of your referers from your logs as long as they occurred a certain number of times (in this case 500). The grep command excludes the terms, I add this in to remove results Im not interested in.
wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}'
This is sample output - yours may be different.
aback 1
abandon 6
abandoned 13
abase 1
abased 1
abashed 7
abated 1
abatement 1
...
This command might not be useful for most of us, I just wanted to share it to show power of command line.
Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination.
This command removes numbers and single characters from count. I'm sure you can write a shorter version.
netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'
This is sample output - yours may be different.
64.74.153.141 3 ***
192.168.10.10 5 *****
Written for linux, the real example is how to produce ascii text graphs based on a numeric value (anything where uniq -c is useful is a good candidate).
awk 'BEGIN {srand()} {print int(rand()*1000000) "\t" $0}' FILE | sort -n | cut -f 2-
This is sample output - yours may be different.
Replace FILE with a filename (or - for stdin).
find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1
This is sample output - yours may be different.
emerge -epv world | grep USE | cut -d '"' -f 2 | sed 's/ /\n/g' | sed '/[(,)]/d' | sed s/'*'//g | sort | uniq > use && grep ^- use | sed s/^-// | sed ':a;N;$!ba;s/\n/ /g' > notuse && sed -i /^-/d use && sed -i ':a;N;$!ba;s/\n/ /g' use
This is sample output - yours may be different.
This command puts all the flags of the USE variable actually used by the packages you emerged to the file "use", and those which are unused but available to the file "notuse"
xmms2 mlib search NOT +rating | grep -r '^[0-9]' | sed -r 's/^([0-9]+).*/\1/' | sort -R | head | xargs -L 1 xmms2 addid
This is sample output - yours may be different.
Added medialib id 5076 to playlist
Added medialib id 1537 to playlist
Added medialib id 1148 to playlist
Added medialib id 5336 to playlist
Added medialib id 3876 to playlist
Added medialib id 5165 to playlist
Added medialib id 5485 to playlist
Added medialib id 3884 to playlist
Added medialib id 498 to playlist
Added medialib id 3791 to playlist
If you're like me and want to keep all your music rated, and you use xmms2, you might like this command.
I takes 10 random songs from your xmms2 library that don't have any rating, and adds them to your current playlist. You can then rate them in another xmms2 client that supports rating (I like kuechenstation).
I'm pretty sure there's a better way to do the grep ... | sed ... part, probably with awk, but I don't know awk, so I'd welcome any suggestions.
sort -u filename > newfilename
This is sample output - yours may be different.
For users looking to simplify management of large entries in files and directories, this command is the key to fun and simplicity. Using the power sort, only a couple of seconds are necessary to accomplish what would take minutes or hours in ?standard? client applications.
find | sed -e "s/^.*\///" | awk ' BEGIN { FS=""} { print NF " " $0 } ' | sort -nrf | head -10
This is sample output - yours may be different.
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
This is sample output - yours may be different.
8 wine
8 kill
7 killall
66 cd
5 wget
4 telnet
It will return a ranked list of your most commonly-entered commands using your command history
ps aux | sort +2n | tail -20
This is sample output - yours may be different.
This command will show the 20 processes using the most CPU time (hungriest at the bottom).
You can see the 20 most memory intensive processes (hungriest at the bottom) by running:
ps aux | sort +3n | tail -20
Or, run both:
echo "CPU:" && ps aux | sort +2n | tail -20 && echo "Memory:" && ps aux | sort +3n | tail -20
cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
This is sample output - yours may be different.
Searches /var/log/secure for smtp connections then lists these by number of connections made and hosts.
cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n
This is sample output - yours may be different.
2 67.11.200.144
4 210.40.128.31
6 208.71.128.195
6 64.39.0.38
15 219.246.112.241
20 200.214.15.142
30 119.70.154.57
30 79.38.22.92
40 61.152.201.74
87 88.191.94.168
107 200.27.214.30
107 61.134.27.234
115 200.6.208.186
170 222.73.37.25
387 99.154.226.153
548 222.35.78.224
627 94.75.240.141
946 213.191.111.5
Searches the /var/log/secure log file for Failed and/or invalid user log in attempts.
du -xk | sort -n | tail -20
This is sample output - yours may be different.
This command will tell you the 20 biggest directories starting from your working directory and skips directories on other filesystems. Useful for resolving disk space issues.
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
This is sample output - yours may be different.
20 81.49.60.x
21 116.212.111.x
26 65.184.224.x
31 189.61.36.x
84 89.180.3.x
212 127.0.0.1
Here is a command line to run on your server if you think your server is under attack. It prints our a list of open connections to your server and sorts them by amount.
BSD Version:
netstat -na |awk '{print $5}' |cut -d "." -f1,2,3,4 |sort |uniq -c |sort -nr
netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768; again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}'
This is sample output - yours may be different.
$ netstat -atn | awk ' /tcp/ {printf("%s\n",substr($4,index($4,":")+1,length($4) )) }' | sed -e "s/://g" | sort -rnu | awk '{array [$1] = $1} END {i=32768; again=1; while (again == 1) {if (array[i] == i) {i=i+1} else {print i; again=0}}}'
32768
Some commands (such as netcat) have a port option but how can you know which ports are unused?
cat file.txt | sort | uniq -dc
This is sample output - yours may be different.
Displays the duplicated lines in a file and their occuring frequency.
This is sample output - yours may be different.