Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using uniq from sorted by
Terminal - Commands using uniq - 192 results
cat /var/log/nginx/access.log | grep -oe '^[0-9.]\+' | perl -ne 'system("geoiplookup $_")' | grep -v found | grep -oe ', [A-Za-z ]\+$' | sort | uniq -c | sort -n
2012-05-08 13:28:25
User: theist
Functions: cat grep perl sort uniq
Tags: sort uniq geoip
-1

Per country GET report, based on access log. Easy to transform to unique IP

for a in $(find . -xdev -type f -printf '%i\n'|sort|uniq -d);do find . -xdev -inum $a -printf '%s %i %m %n %U %G %AD %Ar %p\n';done|sort -n|awk '{if(x!=$2){print "---"};x=$2;print $0}'
2012-04-09 12:52:07
User: knoppix5
Functions: awk find sort uniq
0

The listing will be nice separated with dashes in chunks of identical files.

Output format:

Size Inode Mode Count_of_identical_files UID GID Date Time Path/Filename

find . -type f -print0 | xargs -0 -n1 md5sum | sort -k 1,32 | uniq -w 32 -d --all-repeated=separate | sed -e 's/^[0-9a-f]*\ *//;'
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
find /some/path -type f -and -printf "%f\n" | egrep -io '\.[^.]*$' | sort | uniq -c | sort -rn
2012-04-02 19:25:35
User: kyle0r
Functions: egrep find sort uniq
Tags: uniq ls grep
0

the

find -printf "%f\n" prints just the file name from the given path. This means directory paths which contain extensions will not be considered.
head -n1 nation.tbl | sed 's/\(.\)/\1\n/g' | sort | uniq -c | grep \| | awk '{ print $1 }'
cat z.log | cut -d ':' -f1,2 | uniq -c
cat z.log | cut -d ':' -f1 | sort | uniq | xargs -l1 -iFF echo 'echo FF $(cat z.log | grep -e "^FF" | grep -e Timeout | wc -l )' | bash
cat z.log | grep Timeout | cut -d ':' -f1 | sort | uniq -c
sed -e 's/[;|][[:space:]]*/\n/g' .bash_history | cut --delimiter=' ' --fields=1 | sort | uniq --count | sort --numeric-sort --reverse | head --lines=20
awk -F: '{print $3}' /etc/passwd | sort |uniq -d
2012-01-17 11:16:35
User: ultips
Functions: awk sort uniq
0

Detect duplicate UID in you /etc/passwd (or GID in /etc/group file).

Duplicate UID is often forbidden for it can be a security breach.

find . -type f -exec md5 '{}' ';' | sort | uniq -f 3 -d | sed -e "s/.*(\(.*\)).*/\1/"
2012-01-14 08:54:12
User: noahspurrier
Functions: find sed sort uniq
-1

This works on Mac OS X using the `md5` command instead of `md5sum`, which works similarly, but has a different output format. Note that this only prints the name of the duplicates, not the original file. This is handy because you can add `| xargs rm` to the end of the command to delete all the duplicates while leaving the original.

history | sed -e 's/^sudo //' | awk '{print $2}' | sort | uniq -c | sort -rn | head
2012-01-07 22:29:54
User: bibe
Functions: awk sed sort uniq
-2

I make an extensive use of sudo, so I had to exclude the sudo part of the command history

history | awk '{print $2}' | sort | uniq -c | sort -rn | head
history | cut -c8- | sort | uniq -c | sort -rn | head
mysql -u root -p -N -e"show processlist\G;" | egrep "Host\:" | awk -F: '{ print $2 }' | sort | uniq -c
mysql -u root -p -e"show processlist;"|awk '{print $3}'|awk -F":" '{print $1}'|sort|uniq -c
2011-12-22 05:37:36
User: prasadwani
Functions: awk uniq
Tags: mysql
0

This command will help you to find how many number of connection are made to given mysql and what are the different hosts connected to it with number of connection they are making.

grep -R Subject /var/spool/exim/input/ | sed s/^.*Subject:\ // | sort | uniq -c | sort -n > ~/email_sort.$(date +%m.%d.%y).txt
cat /file/way/somelogforexample | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | sort -n | uniq -c | sort -n
curl http://www.cpan.org/modules/01modules.index.html |awk '{print $1}'|grep -v "<"|sort|uniq -c|grep -v " +[0-9] "
2011-10-18 16:03:54
User: dinomite
Functions: awk grep uniq
1

Grabs the complete module list from CPAN, pulls the first column, ditches html lines, counts, ditches small namespaces.

tshark -r data.pcap -R "ip.addr==192.168.1.2 && ip.addr==64.12.24.50 && aim" -d tcp.port==443,aim -T fields -e "aim.buddyname" |sort |uniq -c
tshark -r data.pcap -R "ip.src==192.168.1.2" -T fields -e "ip.dst" |sort |uniq -c
dups() { sort "$@" | uniq -d; }
netstat -tn | awk 'NR>2 {print $6}' | sort | uniq -c | sort -rn
svn log -r{2011-08-01}:HEAD|awk '$14 ~/line/ {print $3}'|sort|uniq -c
2011-09-01 07:58:54
User: sangnoir
Functions: awk uniq
0

My script lists all users & the number of commits they made in the period, sorted alphabetically. To sort by number of commits, append a '|sort' to the end of the command. The script depends on the output format of svn log - original command didn't work for me because the string 'user' was not appearing in my output