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 cut from sorted by
Terminal - Commands using cut - 474 results
paste <(cut -f1 log.txt) <(cut -f2- log.txt | shuf)
dpkg --status nvidia-current | grep Version | cut -f 1 -d '-' | sed 's/[^.,0-9]//g'
2011-05-06 09:09:33
User: mtron
Functions: cut grep sed
1

i've been writing a bash script where i needed to query the installed version number of the nvidia driver when it's not loaded. Unfortunately i have not found a easy way of doing this.

If i'm a stupid person, please enlighten me of a better way ;)

curl -s http://www.cavejohnsonhere.com/random/ | grep quote_main | cut -d \> -f 2- | fmt -w $(tput cols)
2011-05-06 01:28:40
User: ColOfNature
Functions: cut fmt grep tput
1

There's been a similar Futurama thing around for a while, which grabs a quote from the /. headers [curl -Ism3 slashdot.org | egrep "^X-(F|B|L)" | cut -d \- -f 2- | fmt -w $(tput cols)]. Same deal, but more likely to stop working when someone forgets to pay the bill on the domain. Until then: Cave Johnson!

cut -f1 -d"<TAB>"
pacman -Qi $(pacman -Qq)|grep 'Name\|Size'| cut -d: -f2 | paste - - | column -t | sort -nk2
cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30
for arq in *.png; do size=$(identify $arq | cut -f3 -d" "); [ $size == "280x190" ] || rm $arq ; done
2011-04-22 20:00:05
Functions: cut rm
Tags: ImageMagick
1

Removes all png files whose geometry is not 280x190 pixels

function command_not_found_handle(){ apt-get install $( apt-file search "$1" | grep bin | grep -w "$1" | head -n1 | cut -d ':' -f 1 ) && $* ; }
2011-04-06 19:58:32
User: Juluan
Functions: cut grep head install
-7

Work only with bash and apt-file installed.

When it found an unknow command, it will search for a file named "scribus" (in my example), in a folder named bin and then install the corresponding package.

After installation, it will run the command.

Usefull juste after reinstalling linux and missing lot of package.

egrep -ie "<*HREF=(.*?)>" index.html | cut -d "\"" -f 2 | grep ://
2011-03-29 18:20:50
User: fanfani
Functions: cut egrep grep
3

you can also use cut instead of awk. less powerful but probably faster. ;)

for R in `svn log file:///path/repo | grep ^r | grep dude | cut -d' ' -f1 | cut -dr -f2`; do svn ps svn:log --revprop -r $R "`svn pg svn:log --revprop -r $R file:///path/repo; perl -e 'print ".\n";' | fromdos`" file:///path/repo; done
2011-03-24 08:29:15
User: theist
Functions: cut grep ps
Tags: svn
0

Let's supose some moron used some m$ shit to commit to a later svnsynced repo. On a svn sync all his message logs cause a svnsync: Error setting property 'log': this commands finds all its contributions and fix all his commit logs

while :; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
2011-03-22 10:02:23
User: hons
Functions: awk cut echo grep sleep tr
15

Just a simple way without the need of additional tools. Of course, replace eth0 with your IF.

quota -q $(cat /etc/passwd|cut -d ':' -f 1)
wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=translation+example&sl=auto&tl=fr" | sed 's/\[\[\[\"//' | cut -d \" -f 1
2011-03-06 13:46:16
User: sairon
Functions: cut sed wget
5

substitute "example" with desired string;

tl = target language (en, fr, de, hu, ...);

you can leave sl parameter as-is (autodetection works fine)

for i in *; do j=`echo $i | cut -d "-" -f1`; j=$j; mv $i $j; done
2011-03-06 11:58:37
User: jaimerosario
Functions: cut mv
-1

Renames files eliminating suffix, in this case everything after "-" is cutted. Just change "-" with the character you need.

echo -n "String to MD5" | md5sum | cut -b-32
echo -n "String to MD5" | md5sum | cut -f1 -d' '
2011-03-05 03:53:09
User: xakon
Functions: cut echo md5sum
-2

Nothing special about hashing here, only the use of cut, I think, could result at fewer keystrokes.

for h in `find /proc/*/fd -ilname "/tmp/Flash*" 2>/dev/null`; do ln -s "$h" `readlink "$h" | cut -d' ' -f1`; done
2011-03-02 09:43:42
User: hons
Functions: cut ln
17

Newer versions of the flashplayer browser plugin delete the tmp flash video immediately after opening a filehandle to prevent the user from "exporting" the video by simply copying the /tmp/FlashXYZ file. This command searches such deleted flash videos and creates symbolic links to the opened filehandle with the same name as the deleted file.

This allows you to play your flash-videos (from e.g. youtube) with e.g. mplayer or copy the buffered video if you want to keep it.

nice -n 5 electricsheep -window-id `xwininfo -root|head -n 2|grep xwininfo|cut -c 22-26`
2011-02-14 03:58:58
User: kbaegis
Functions: cut grep head nice
0

This is a simple command which makes electricsheep render directly to your background

seq -s^2+ 11 |rev| cut -d'+' -f2- | rev | bc
2011-02-10 08:41:14
User: rubenmoran
Functions: cut rev seq
Tags: seq sum math
-2

I can't put the last ^2 with seq, so I reverse it to delete the last +N. So for doing sum(N^2) you have to do sum((N+1)^2). Must be a better way.

strace -e open zim 2>&1 1>/dev/null | fgrep ~ | fgrep -v "= -1" | cut -d'"' -f2
2011-01-31 22:46:51
Functions: cut fgrep strace
0

Locate config files of the program. May not be used for interactive programs like vim.

grep -w /media/KINGSTON /proc/mounts | cut -d " " -f
IFS=$'\n'; i=1; ls -lt *mp3 | cut -d ":" -f2 | cut -d " " -f2- | while read f; do mv "$f" $(echo "$i"."$f"); ((i++)); done
2011-01-22 00:21:12
User: m1cawber
Functions: cut echo ls mv read
0

i use this after ripping internet radio streams to number the files as they originally played (even though streamripper can do this with -q).

to number other types of files, or all files, just change the *mp3. to rename directories only you could use

... ls -lt | grep ^d | cut -d ":" -f2 | cut -d " " -f2- | while read ...

df | grep -w '/media/armadillo' | cut -d " " -f 1
df | grep -w '/media/mountpoint' | cut -d " " -f 1
2011-01-21 05:38:05
User: ntropia
Functions: cut df grep
-2

Identical output but a different way without having to shoot with the Awk cannon :)