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 by sud0er from sorted by
Terminal - Commands by sud0er - 18 results
curl --ntlm -u DOMAIN/user https://sharepoint.domain.com/path/to/file
2010-11-11 22:22:25
User: sud0er
1

If you know the URL of a file on a SharePoint server, it's just a matter of logging in with your AD credentials to get the file with cURL

curl --ntlm -u DOMAIN/user https://sharepoint.domain.com/path/to/file
2010-11-11 22:22:24
User: sud0er
-1

If you know the URL of a file on a SharePoint server, it's just a matter of logging in with your AD credentials to get the file with cURL

STA=KILCHICA30 PAG=http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=${STA} D=($(curl -s $PAG | sed -n 's/.*<\(temp_f\|wind_dir\|wind_mph\)>\(.*\)<\/.*/\2/p')) echo ${D[1]}@${D[2]}mph ${D[0]}F
2010-10-28 00:40:28
User: sud0er
Functions: echo sed
-1

Uses the Wunderground web API to get weather data. Change the STA variable to a station near you.

curl -sS -o $outfile -m $showlengthinseconds $streamurl
2009-12-22 22:37:42
User: sud0er
Tags: curl
1

I use this with cron to timeshift radio programs from a station's live stream.

You will get an error message at the end like "curl: (28) Operation timed out after 10000 milliseconds with 185574 bytes received"; to suppress that but not other error messages, you can append "2>&1 | grep -v "(28)"" to the end of the command.

echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk /dev/sdX
2009-10-20 16:21:54
User: sud0er
Functions: echo fdisk
Tags: Linux fdisk
-1

This is a bit hacky, but if you're setting up a bunch of new LUNs, it can save a bunch of time. Also check out sfdisk. The fdisk will fail if, for example, a partition table already exists.

cat /dev/clipboard; $(somecommand) > /dev/clipboard
2009-07-10 18:48:21
User: sud0er
Functions: cat
Tags: windows cygwin
12

I spent a bunch of time yesterday looking for the xsel package in Cygwin- turns out you can use the /dev/clipboard device to do the same thing.

echo "screen -DR" >> ~/.bash_profile
2009-04-28 20:45:37
User: sud0er
Functions: echo
Tags: screen
11

From screen's manpage: "Attach here and now. In detail this means: If a session is running, then reattach. If necessary detach and logout remotely first. If it was not running create it and notify the user. This is the author's favorite."

Toss this in your ~/.bash_profile so that you never have that "oh crap" moment where you wanted to run something in screen and didn't.

shred targetfile
2009-04-28 19:57:43
User: sud0er
Functions: shred
5

GNU shred is provided by the coreutils package on most Linux distribution (meaning, you probably have it installed already), and is capable of wiping a device to DoD standards.

You can give shred any file to destroy, be it your shell history or a block device file (/dev/hdX, for IDE hard drive X, for example). Shred will overwrite the target 25 times by default, but 3 is enough to prevent most recovery, and 7 passes is enough for the US Department of Defense. Use the -n flag to specify the number of passes, and man shred for even more secure erasing fun.

Note that shredding your shell history may not be terribly effective on devices with journaling filesystems, RAID copies or snapshot copies, but if you're wiping a single disk, none of that is a concern. Also, it takes quite a while :)

sudo installer -pkg /Volumes/someapp/someapp.mpkg -target /
2009-04-28 19:43:56
User: sud0er
Functions: sudo
Tags: osx
4

Installing most OSX apps is just a matter of dropping it in /Applications, either GUI-wise or with cp -r. However, many packages are distributed in "mpkg" format, and those have to be installed with an installer. If you don't want to go to the trouble of firing up VNC to install an mpkg, you can use the "installer" command.

This will install an application from a .mpkg it to /Applications system-wide. To install a program for just one user, replace "-target /" with "-target username".

hdiutil attach somefile.dmg
2009-04-28 19:41:42
User: sud0er
Tags: osx
5

To unmount, replace "attach" with "eject"

history -d
2009-04-27 20:19:09
User: sud0er
Tags: bash
28

If you're a moron like me, sometimes your fingers get away from you and you, for example, enter your password when you're already authenticated to ssh-agent, sudo, etc., and your password ends up in shell history. Here's how to get it out.

ssh -vN hostname 2>&1 | grep "remote software version"
2009-03-31 18:28:41
User: sud0er
Functions: grep hostname ssh
Tags: ssh
2

I used this to confirm an upgrade to an SSH daemon was successful

elinks http://partmaps.org/era/unix/award.html
2009-03-01 18:59:55
User: sud0er
0

Everyone on CLIFU needs to check this site out. Learn how to accomplish what you've been doing faster and more efficiently.

:r !command
2009-02-25 15:49:08
User: sud0er
Tags: vim
13

This will append the output of "command" to whatever file you're currently editing in vim. Who else has good vim tricks? :)

autossh -f -M 20000 -D 8000 somehost -N
2009-02-19 20:17:52
User: sud0er
10

This command will log you into somehost via SSH and then go into the background (-f). From there, you can point e.g. firefox at localhost:8000 as a SOCKS proxy. Autossh will use port 20000 and 20001 to send and receive test data on those ports to ensure the SSH tunnel is still running, and will try to re-start the tunnel if it goes down. Make sure you have ssh-agent running, or passwordless ssh keys distributed between the two hosts.

$(STEEP=300; sleep $STEEP; xmessage "Your tea is done") &
2009-02-19 20:10:49
User: sud0er
Functions: sleep
1

wrapping the snippet in $( )& puts the whole thing in the background so you don't tie up your login session.

lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
sed -n -e '/postfix\/smtp\[.*status=sent/s/^.*to=<\([^>]*\).*$/\1/p' /var/log/mail.log | sort -u