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

All commands from sorted by
Terminal - All commands - 11,492 results
:g/\n"/jo
2010-09-11 18:51:41
User: mensa13
-2

In case the line you want to join start with a char different than ", you may use \n.*"\n as regex.

-y -r 1 -t 3 -f video4linux2 -vframes 1 -s sxga -i /dev/video0 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg
2013-02-27 05:32:03
User: navyjeff
Functions: date
-2

Take a picture from your webcam and save it to a jpeg.

A very slightly modified version of MarxBro's command.

echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }'
IFS=`echo -en "\n\b"`; for i in $(curl http://feeds.digg.com/digg/container/technology/popular.rss | grep '<title>' | sed -e 's#<[^>]*>##g' | tail -n10); do echo $i; echo $i | sed 's/^/Did you hear about /g' | say; sleep 30; done
2010-06-07 22:16:19
User: echosedawk
Functions: echo grep sed sleep tail
Tags: bash sed curl osx
-2

Instead of having someone else read you the Digg headlines, Have OSX do it. Requires Curl+Sed+Say. This could probably be easily modified to use espeak for Linux.

:bufdo %s/foo/bar/ge | up
dpkg --get-selections | awk '$2=="install" {print $1}' | sort
wget http://www.commandlinefu.com/commands/by/e7__7dal
pacof -e rlogin
2011-11-04 13:17:04
User: pipeliner
-2

Uses dpkg -S or apt-file to find the file you want and shows results in various ways. Available at https://github.com/Pipeliner/configs/blob/master/bin/pacof

pacof -xp 'bin/[^/]*mixer'

alsamixergui

alsa-tools-gui

alsa-utils

...

echo 0 > /proc/sys/kernel/randomize_va_space
2010-07-11 16:42:42
User: gunslinger_
Functions: echo
Tags: kernel
-2

Disable randomisation address

explorer $( cygpath "/path/to/file_or_exe" -w )
2009-07-22 17:00:21
User: Highwayman
-2

This executes faster than

cygstart.exe

I put this in a script and added it to my path:

cat `which explore.sh`

#!/bin/bash

if [ $# -eq 0 ]; then

explorer.exe $( cygpath `pwd` -w ) &

else

explorer.exe $( cygpath $1 -w ) &

fi;

Using the script you just type

explore.sh file_or_executable

Note: you can do this for any file that has an associated executable in the windows registry. This is quite handy if you want to open pictures or movies from xterm.

PS1='$PWD$ '
2009-02-13 22:00:57
User: Aldiansblog
-2

If you have tried to change your prompt and made a mistake, use this command to retrieve a standard prompt.

If you used the export command when you changed your prompt, also use it there:

export PS1='$PWD$ '

file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; };
2010-08-12 21:53:28
User: IgnitionWeb
Functions: file grep mv sed
Tags: mp3 sox resample
-2

This heavy one liner gets all the files in the "/music/dir/" directory and filters for non 44.1 mp3 files. After doing this it passes the names to sox in-order to re-sample those files. The original files are left just in case.

sar -r
2009-05-19 11:47:38
User: sharfah
-2

Report memory and swap space utilization statistics e.g. memory free/used, swap free/used

comm -13 <(sort file1) <(sort file2) > file-new
2011-10-01 18:07:54
User: daa
Functions: comm sort
-2

If both file1 and file2 are already sorted:

comm -13 file1 file2 > file-new

watch -n1 --differences cat /proc/meminfo
hb(){ sed "s/\($*\)/`tput setaf 2;tput setab 0;tput blink`\1`tput sgr0`/gI"; }
2010-04-07 08:45:26
User: AskApache
Functions: sed
-2
hb(){ sed "s/\($*\)/`tput setaf 2;tput setab 0;tput blink`\1`tput sgr0`/gI"; }

hb blinks, hc does a reverse color with background.. both very nice.

hc(){ sed "s/\($*\)/`tput setaf 0;tput setab 6`\1`tput sgr0`/gI"; }

Run this:

command ps -Hacl -F S -A f | hc ".*$PPID.*" | hb ".*$$.*"

Your welcome ;)

From my bash profile - http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

find / -name FILENAME
sudo scutil --set HostName MY_NEW_HOSTNAME
wget -nd -nH -r -A pdf -I library/mac/documentation/ http://developer.apple.com/library/mac/navigation/#section=Resource%20Types&topic=Reference
2011-10-02 04:56:25
User: GinoMan2440
Functions: wget
Tags: mac os x
-2

download every last pdf reference Doc from the Apple Developer Connection, takes a half hour on a fast connection. enjoy!

git push origin --all
for %%f in (*.json) do type %%f >> aggregate.json
tiger
2009-05-19 19:07:11
-2

From man tiger : Tiger is a package consisting of Bourne Shell scripts, C code and data files which is used for checking for security problems on a UNIX system. It scans system configuration files, file systems, and user configuration files for possible security problems and reports them.

xdg-open $(svn info | sed -n '/URL:/s/URL: //p')
sudo update-rc.d -f gdm remove
2011-12-16 10:12:21
User: kev
Functions: sudo
Tags: update-rc.d
-2

run `sudo update-rc.d gdm defaults` to get it back

wget -qO - snubster.com|sed -n '65p'|awk 'gsub(/<span><br>.*/,"")&&1'|perl -p -e 's:myScroller1.addItem\("<span class=atHeaderOrange>::g;s:</span> <span class=snubFontSmall>::g;s:&quot;:":g;s:^:\n:g;s:$:\n:'
2009-02-18 15:05:13
User: sil
Functions: wget
-2

I've got this posted in one of my .bash_profiles for humor whenever I log in.