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 grep from sorted by
Terminal - Commands using grep - 1,532 results
for file in $(git ls-files | grep old_name_pattern); do git mv $file $(echo $file | sed -e 's/old_name_pattern/new_name_pattern/'); done
grep -l --include '*.rb' --include '*.rake' '^[^#]*[^a-zA-Z0-9[:punct:][:space:]]' -R . | xargs -L1 awk '!/encoding/ && NR < 2 { print FILENAME }'
netstat -tln | grep :25
2013-11-12 16:47:06
User: Peteches
Functions: grep netstat
0

netstat will list all open ports on the system, unix sockets, tcp sockets and udp sockets. the t flag limits to tcp ports the l flag limits to listening ports and the n flag disables the translation of port to service ( ie :25 displayed instead of :smtp ). then grep for the port you are interested in preceeded by a colon.

while true; do date; (curl -s -o 1.html http://www.biglion.ru/deals/ebay-80/ &); sleep 5; cat 1.html | grep "&#1082;&#1091;&#1087;&#1086;&#1085;&#1086;&#1074;" | awk -F"<div>" '{print $2}' | awk -F"<span>" '{print $1}'; done
2013-11-08 12:40:05
User: sxiii
Functions: awk cat grep sleep
-1

Processes biglion quantity of sold ebay coupons/bonus codes, so you can know approximate count of users who buyed the coupons and when sales are come up again.

You can change sleep parameter so script will work slowly or faster (default is 5 seconds).

Additional requirements: curl

Standart tools used: awk, date, cat, grep (bash)

wget --no-check-certificate https://www.kernel.org/$(wget -qO- --no-check-certificate https://www.kernel.org | grep tar | head -n1 | cut -d\" -f2)
(amixer get Master | grep off > /dev/null && amixer -q set Master unmute) || amixer -q set Master mute
find -type f | grep -v "^./.git" | xargs md5sum | md5sum
grep -lr "foo" . | xargs sed -i "s/foo/bar/g"
2013-10-28 13:02:47
User: sergeylukin
Functions: grep sed xargs
1

Replace "foo" with "bar" in all files in current directory recursively

alias tasks='git grep -EI "TODO|FIXME"'
2013-10-21 23:54:46
User: lizardo
Functions: alias grep
Tags: bash git todo
0

"git grep" automatically excludes untracked files (e.g. compiler output) and files under .git directory. If no directory or file is given, it will recursively search through the current directory.

ls -R | grep -v skipme | xargs rm -Rf
2013-10-18 08:11:39
Functions: grep ls rm xargs
Tags: delete rm
-11

This command will delete all files and folders except 'skipme'. it could be a file or a folder.

for i in `cat /proc/mounts | grep /home/virtfs | cut -d ? ? -f 2 ` ; do umount $i; done
grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n
pactl list sinks | grep -q Mute:.no && pactl set-sink-mute 0 1 || pactl set-sink-mute 0 0
dpkg-query -Wf '${Installed-Size}\t${Status}\t${Package}\n' | sort -n | grep installed
wget -q -O- http://example-podcast-feed.com/rss | grep -o "<enclosure[ -~][^>]*" | grep -o "http://[ -~][^\"]*" | xargs wget -c
2013-09-24 12:38:08
User: talha131
Functions: grep wget xargs
0

This script can be used to download enclosed files from a RSS feed. For example, it can be used to download mp3 files from a podcasts RSS feed.

dmidecode | grep -i 'Base Board Information' -A4 -B1
2013-09-20 02:29:32
User: boylah
Functions: grep
4

Very slick way to check your motherboard manufacturer, product name, version and serial number.

grep --color -R "text" directory/
grep "10/Sep/2013" access.log| cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'
tac ~/.bash_history | grep -w
2013-09-07 15:53:30
User: hamsolo474
Functions: grep tac
-3

greps your bash history for whatever you type in at the end returning it in reverse chronological order (most recent invocations first), should work on all distros.

works well as an alias

shuf /usr/share/dict/words |grep "^[^']\{3,6\}$" |head -n4 | sed -e "s/\b\(.\)/\u\1/g" | tr -d '\n'; echo
2013-09-06 03:05:31
User: chijonutor
Functions: grep head sed tr
Tags: tr xkcd shuf
0

Took one of the samples, added capitalization and removes in between spaces.

The final "echo" is just for readability.

Cheers

for i in `ip addr show dev eth1 | grep inet | awk '{print $2}' | cut -d/ -f1`; do echo -n $i; echo -en '\t'; host $i | awk '{print $5}'; done
curl ${URL} 2>/dev/null|grep "<${BLOCK}>"|sed -e "s/.*\<${BLOCK}\>\(.*\)\<\/${BLOCK}\>.*/\1/g"
2013-08-31 14:53:54
User: c3w
Functions: grep sed
0

set BLOCK to "title" or any other HTML / RSS / XML tag and curl URL to get everything in-between e.g. some text

apt-cache -n dumpavail | grep 'Package:' | awk '{print $2 }'
port=32768; while netstat -atn | grep -q :$port; do port=$(expr $port + 1); done; echo $port
ipcs -q | grep foo | awk '{print $2}' | xargs -I ipcid ipcrm -q ipcid