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.

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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using cut from sorted by
Terminal - Commands using cut - 497 results
svn up | sed 's/\.//g' | cut -d ' ' -f3 | xargs svn log -r
export var1=`ps -A | grep '[u]nique' | cut -d '?' -f 1`; echo${var1/ /}; kill -9 $var1
2010-03-22 21:06:58
User: headyadmin
Functions: cut export grep kill
Tags: Os X

This will kill a specific process you don't know the PID of, when pidof and pgrep are not available, for example on OS X. var1 is created so that the whitespace can be trimmed before passing off to kill.

cut -f2 file.txt | cut -d " " -f1
git reflog show | grep '}: commit' | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed s/commit://g | sed -e 's/HEAD*@{[0-9]*}://g'
ip route list match | cut -d " " -f 3
curl -sL xkcd.com | grep '<img [^>]*/><br/>' | sed -r 's|<img src="(.*)" title="(.*)" alt="(.*)" /><br/>|\1\t\2\t\3|' > /tmp/a; curl -s $(cat /tmp/a | cut -f1) | convert - -gravity south -draw "text 0,0 \"$(cat /tmp/a | cut -f2)\"" pdf:- > xkcd.pdf
2010-03-03 03:41:31
User: matthewbauer
Functions: cat cut grep sed
Tags: pdf xkcd caption

Saves to a PDF with title and alt text of comic.

As asked for on http://bbs.archlinux.org/viewtopic.php?id=91100

Change xkcd.com to dynamic.xkcd.com/comics/random for a random comic.

git log --reverse --pretty=oneline | cut -c41- | nl | sort -nr
svn log -r {`date "+%Y-%m-%d"`}:HEAD|grep '^r[0-9]' |cut -d\| -f2|sort|uniq -c
file /usr/bin/* | grep ELF | cut -d":" -f1
2010-02-17 14:01:52
Functions: cut file grep

This is a dirty raw way to simply list ELF objects in a folder.

The output is ready to be parsed i.e to the stripper or what else needs a path to an ELF object.

while read l; do echo $RANDOM "$l"; done | sort -n | cut -d " " -f 2-
2010-02-03 22:36:34
User: ketil
Functions: cut echo read sort

If you need to randomize the lines in a file, but have an old sort commands that doesn't support the -R option, this could be helpful. It's easy enough to remember so that you can create it as a script and use that.

It ain't real fast. It ain't safe. It ain't super random. Do not use it on untrusted data. It requires bash for the $RANDOM variable to work.

ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=$( for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done ); str=$(echo $str | cut -c -$COLUMNS) ; echo $str; done; }
for i in `netstat -rn |grep lan |cut -c55-60 |sort |uniq`; do ifconfig $i; done
2010-01-28 17:35:20
User: Kaio
Functions: cut grep ifconfig sort

HP UX doesn't have a -a switch in the ifconfig command.

This line emulates the same result shown in Solaris, AIX or Linux

du -s * | sort -nr | head | cut -f2 | parallel -k du -sh
2010-01-28 12:59:14
Functions: cut du head sort
Tags: du xargs parallel

If a directory name contains space xargs will do the wrong thing. Parallel https://savannah.nongnu.org/projects/parallel/ deals better with that.

svn st | cut -c 9- | parallel -X tar -czvf ../backup.tgz
2010-01-28 11:43:16
Functions: cut tar

xargs deals badly with special characters (such as space, ' and "). In this case if you have a file called '12" record'.

Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.

Both solutions work bad if the number of files is more than the allowed line length of the shell.

svn add $(svn st|grep ^\?|cut -c2-)
2010-01-28 09:48:46
User: inkel
Functions: cut grep
Tags: bash svn grep cut

This version makes uses of Bash shell expansion, so it might not work in all other shells.

fping -r1 -g <subnet> 2> /dev/null | grep unreachable | cut -f1 -d' '
paste -d "." <(curl http://.../dist.female.first http://.../dist.male.first | cut -d " " -f 1 | sort -uR) <(curl http://..../dist.all.last | cut -d " " -f 1 | sort -R | head -5163) | tr "[:upper:]" "[:lower:]" | sed [email protected]/g'
2010-01-21 19:52:28
User: connorsy
Functions: cut head paste sed sort tr

** Replace the ... in URLS with:


Couldn't fit in 256

Created on Ubuntu 9.10 but nothing out of the ordinary, should work anywhere with a little tweaking. 5163 is the number of unique first names you get when combine the male and female first name files from. http://www.census.gov/genealogy/www/data/1990surnames/names_files.html

cat -n <file> | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-
2010-01-21 18:55:58
User: fpunktk
Functions: cat cut sort uniq

i wanted to delete all duplicate lines from .bash_history and keep the order of the other lines.

the command cat's the file and adds line numbers, then sorts by the second column. afterwards uniq omits repeated lines, but skips the first field (the line number). then it sorts by the line numbers and at the end cuts the numbers off.

atrm $(atq|cut -f1)
2010-01-20 08:04:35
User: frans
Functions: atrm cut
Tags: at

Removes all the at shedules jobs

port=8888;pid=$(lsof -Pan -i tcp -i udp | grep ":$port"|tr -s " " | cut -d" " -f2); ps -Afe|grep "$pid"|grep --invert-match grep | sed "s/^\([^ ]*[ ]*\)\{7\}\(.*\)$/\2/g"
2010-01-11 17:49:22
User: glaudiston
Functions: cut grep ps sed tr

A way not so simple but functional for print the command for the process that's listening a specific port.

I got the pid from lsof because I think it's more portable but can be used netstat

netstat -tlnp
git shortlog -s | cut -c8-
2010-01-07 18:04:01
User: jedahan
Functions: cut
Tags: git

List everyone who committed to a particular project, listed alphabetically. To list by commits, add -n to the shortlog.

ifconfig | grep -B 1 "inet addr:" | head -1 | cut -d" " -f1
2010-01-04 23:02:57
User: jasonwalsh
Functions: cut grep head ifconfig

Get the line containing "inet addr:" and the line before that, get down to only the first line, and then get the first word on that line, which should be the interface.

openssl rand -base64 1000 | tr "[:upper:]" "[:lower:]" | tr -cd "[:alnum:]" | tr -d "lo" | cut -c 1-8 | pbcopy
2009-12-29 17:18:25
User: _eirik
Functions: cut tr

eliminates "l" and "o" characters change length by changing 'x' here: cut -c 1-x

find dir -size -1024k -type f | xargs -d $'\n' -n1 ls -l | cut -d ' ' -f 5 | sed -e '2,$s/$/+/' -e '$ap' | dc
2009-12-28 04:23:01
User: zhangweiwu
Functions: cut dir find ls sed xargs
Tags: size sum

The command gives size of all files smaller than 1024k, this information, together with disk usage, can help determin file system parameter (e.g. block size) or storage device (e.g. SSD v.s. HDD).

Note if you use awk instead of "cut| dc", you easily breach maximum allowed number of records in awk.

getent shadow | grep '^[^:]\+:!' | cut -d: -f1