
Terminal - Commands using sort - 526 results
du -ms * .[^.]*| sort -nk1
This is sample output - yours may be different.
186 Foto
213 .mozilla
260 .eclipse
295 .kde
301 Desktop
using mb it's still readable;) a symbol variation
$ du -ms {,.[^.]}* | sort -nk1
function duf { du -k $@ | sort -rn | perl -ne '($s,$f)=split(/\t/,$_,2);for(qw(K M G T)){if($s<1024){$x=($s<10?"%.1f":"%3d");printf("$x$_\t%s",$s,$f);last};$s/=1024}' }
This is sample output - yours may be different.
svn log | tr -d '\n' | sed -r 's/-{2,}/\n/g' | sed -r 's/ \([^\)]+\)//g' | sed -r 's/^r//' | sed -r "s/[0-9]+ lines?//g" | sort -g
This is sample output - yours may be different.
1 | author | 2009-09-09 12:12:12 +200 | Initial import
2 | author | 2009-09-09 12:15:16 +200 | ADDED: great feature
Note you have also the --xml option ;)
echo $numbers | sed "s/\( \|$\)/\n/g" | sort -nu | tr "\n" " " | sed -e "s/^ *//" -e "s/ $//"
This is sample output - yours may be different.
$ echo "4 2 3 5 2 52 11" | sed "s/\( \|$\)/\n/g" | sort -nu | tr "\n" " "| sed -e "s/^ *//" -e "s/ $//"
2 3 4 5 11 52
You can replace "sort -nu" with "sort -u" for a word list sorted or "sort -R" for a random-sorted line
(edit: corrected)
find . -depth -type d -exec du -s {} \; | sort -k1nr
This is sample output - yours may be different.
somewhat faster version to see the size of our directories. Size will be in Kilo Bytes. to view smallest first change '-k1nr' to '-k1n'.
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted
This is sample output - yours may be different.
This commands will make it easier to select only common items between two files being compared. If your lines start with things other than lowercase a-z, adjust this Regex appropriately. Number of lines in the output has been set to no more than 10000, and should be adjusted as needed.
This is sample output - yours may be different.
grep -h -o '<[^/!?][^ >]*' * | sort -u | cut -c2-
This is sample output - yours may be different.
This set of commands was very convenient for me when I was preparing some xml files for typesetting a book. I wanted to check what styles I had to prepare but coudn't remember all tags that I used. This one saved me from error-prone browsing of all my files. It should be also useful if one tries to process xml files with xsl, when using own xml application.
This is sample output - yours may be different.
Tells sort to ignore all characters before the Xth position in the first field per line. If you have a list of items one per line and want to ignore the first two characters for sorting purposes, you would type "sort -k1.3". Change the "1" to change the field being sorted. The decimal value is the offset in the specified field to sort by.
( nw=192.168.0 ; h=1; while [ $h -lt 255 ] ; do ( ping -c2 -i 0.2 -W 0.5 -n $nw.$h & ); h=$[ $h + 1 ] ; done ) | awk '/^64 bytes.*/ { gsub( ":","" ); print $4 }' | sort -u
This is sample output - yours may be different.
What do you do when nmap is not available and you want to see the hosts responding to an icmp echo request ? This one-liner will print all hosts responding with their ipv4 address.
This is sample output - yours may be different.
Sort ls output of all files in current directory in ascending order
Just the 20 biggest ones:
ls -la | sort -k 5bn | tail -n 20
A variant for the current directory tree with subdirectories and pretty columns is:
find . -type f -print0 | xargs -0 ls -la | sort -k 5bn | column -t
And finding the subdirectories consuming the most space with displayed block size 1k:
du -sk ./* | sort -k 1bn | column -t
svn log -v -r{2009-05-21}:HEAD | awk '/^r[0-9]+ / {user=$3} /yms_web/ {if (user=="george") {print $2}}' | sort | uniq
This is sample output - yours may be different.
just change the date following the -r flag, and/or the user name in the user== conditional statement, and substitute yms_web with the name of your module
URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|)
This is sample output - yours may be different.
Lists revisions in a Subversion repository with a timestamp that doesn't follow the revision numbering order. If everything is OK, nothing is displayed.
for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
This is sample output - yours may be different.
2009-06-03 12:21:35 +0900 3 hours ago add_cool_functionality
2009-06-02 16:15:13 +0900 24 hours ago remove_strange_bug
2009-06-02 16:12:20 +0900 24 hours ago implement_observer
2009-06-02 14:42:58 +0900 25 hours ago experiment_with_bobcat_feature
Print out list of all branches with last commit date to the branch, including relative time since commit and color coding.
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).