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 - 469 results
allVideos() { find ./ -type f -print0 | xargs -0 file -iNf - | grep ": video/" | cut -d: -f1; }
2011-08-19 11:58:59
User: totti
Functions: cut file find grep xargs
0

Videos are found using their MIME type. Thus no need to for an extension for the video file.

This is a efficent version of "jnash" cmd (4086). Thanks for jnash. This cmd will only show video files while his cmd show files having "video" anywhere in path.

httpd -V | grep -i SERVER_CONFIG_FILE | cut -f2 -d'"' | xargs grep -i '^DocumentRoot' | cut -f2 -d'"'
2011-08-13 20:45:05
User: dcpesses
Functions: cut grep
1

Grabs the Apache config file (yielded from httpd) and returns the path specified as DocumentRoot.

git branch | cut -c3- | grep -v "^master$" | while read line; do git branch -d $line; done | grep 'Deleted branch' | awk '{print $3;}' | while read line; do git push <target_remote> :$line; done
2011-08-13 16:58:34
User: gocoogs
Functions: awk cut grep read
0

attempts to delete all local branches. git will fail on any branches not fully merged into local master, so don't worry about losing work. git will return the names of any successfully deleted branches. Find those in the output with grep, then push null repositories to the corresponding names to your target remote.

assumes:

- your local and remote branches are identically named, and there's nothing extra in the remote branch that you still want

- EDIT: you want to keep your local master branch

cut -d, -f5
2011-08-12 01:42:30
User: cromadon
Functions: cut
1

extracts the 5th column using the delimiter ','

mplayer $(ls -l /proc/$(pgrep -f flash)/fd/* |grep Flash | cut -d" " -f8)
vim -p `grep -r PATTERN TARGET_DIR | cut -f1 -d: | sort | uniq | xargs echo -n`
netstat -an |grep ":80" |awk '{print $5}' | sed s/::ffff://g | cut -d: -f1 |sort |uniq -c |sort -n | tail -1000 | grep -v "0.0.0.0"
netstat -nut | awk '$NF=="ESTABLISHED" {print $5}' | cut -d: -f1 | sort -u
2011-07-27 07:24:10
User: bitbasher
Functions: awk cut netstat sort
-1

find all computer connected to my host through TCP connection

MAC=$((date +'%Y%m%d%H%M%S%N'; cat /proc/interrupts) | md5sum | sed -r 's/(..)/\1:/g' | cut -d: -f 1-6)
2011-07-14 13:11:50
User: jazznjam
Functions: cat cut date md5sum sed
-1

I liked vaporub's suggestion, here a little simplification of the sed command.

netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
2011-07-04 20:23:21
User: letterj
Functions: awk cut netstat sort uniq
Tags: netstat
-4

netstat has two lines of headers:

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

Added a filter in the awk command to remove them

netstat -ntu | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
alias cd1='cd $( ls -lt | grep ^d | head -1 | cut -b 51- )'
mv file.png $( mktemp -u | cut -d'.' -f2 ).png
netstat -n -f inet|awk '/\.389/{print $2}'|cut -f1-4 -d.|sort -u
ip -f inet addr |grep "global eth0$"|awk '{print $2}'|cut -d '/' -f 1
lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
2011-05-30 20:45:58
User: leenucks
Functions: cut grep sort
-3

Useful after a complete system update (without a new kernel) when you want to know, which processes need to be restarted

sudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
find . -maxdepth 1 -printf '%A@\t%p\n' | sort -r | cut -f 2,2 | head -1
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
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