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,857 results
cp -dpRx /* /mnt/target/
2011-08-22 14:22:01
Functions: cp
-1

preserve all except context and xattr. useful when moving a running system to a new partition.

vgdisplay -v 2>/dev/null | grep "^ LV Name" | while read A B LVDEV; do echo $LVDEV; done
NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH)
2010-06-04 07:58:53
User: keymon
Functions: mount perl umount
-1

Based on the execute with timeout command in this site.

A more complex script:

#!/bin/sh

# This script will check the avaliability of a list of NFS mount point,

# forcing a remount of those that do not respond in 5 seconds.

#

# It basically does this:

# NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH)

#

TIMEOUT=5

SCRIPT_NAME=$(basename $0)

for i in $@; do

echo "Checking $i..."

if ! perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $i" > /dev/null 2>&1; then

echo "$SCRIPT_NAME: $i is failing with retcode $?."1>&2

echo "$SCRIPT_NAME: Submmiting umount -fl $i" 1>&2

umount -fl $i;

echo "$SCRIPT_NAME: Submmiting mount $i" 1>&2

mount $i;

fi

done

cat /etc/passwd | wc -l
iostat -En $(iostat -en|grep c#t|awk '$2 > 0 {print $NF}')
2011-12-09 15:54:28
Functions: awk grep
-1

This helps quickly get information for each disk that is seemingly having hardware issues.

do-release-upgrade
2009-03-25 07:25:33
User: dizzgo
Tags: Ubuntu
-1

release upgrades are major upgrades as from 8.04 to 8.10 or from 8.10 to 9.04

update-manager-core must be installed:

sudo apt-get install update-manager-core

in some cases you must edit '/etc/update-manager/release-upgrades' and set 'Prompt=normal'

recoll -t -q "keyword" | grep message/rfc822 | sed -s 's,^.*\('$MAILDIR'[^]]*\)\].*$,\"\1\",' | xargs ln -sft $MAILDIR/bingo/cur/
ls -d */* | sed -e 's/^/\"/g' -e 's/$/\"/g' | xargs mv -t $(pwd)
2010-03-01 23:43:26
User: leovailati
Functions: ls mv sed xargs
-1

You WILL have problems if the files have the same name.

Use cases: consolidate music library and unify photos (especially if your camera separates images by dates).

After running the command and verifying if there was no name issues, you can use

ls -d */ | sed -e 's/^/\"/g' -e 's/$/\"/g' | xargs rm -r

to remove now empty subdirectories.

dc -e "1 1 + p"
ff() { find -maxdepth 3 -type f -iname "$1"; }; fd() { find -maxdepth 4 -type d -iname "$1"; }
2012-08-15 15:04:48
User: plasticboy
Functions: find
Tags: find simple
-1

These should be a little faster since they don't have to spawn grep.

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=merged.pdf -dBATCH `ls | grep foo`
perl -e 'print 1+1 ."\n";'
echo | socat -u - file:/tmp/swapfile,create,largefile,seek=10000000000000
gzip -c source.csv > source.csv.gz
2012-10-17 18:31:51
User: cfunz
Functions: gzip
Tags: gzip aix
-1

use this command to gzip the file and write to stdout and from the stdout redirect to the another file

find ~/.thunderbird/*.default/ -name *.msf | sed 's/ /\\ /g' | xargs rm {} \;
2010-06-04 12:35:24
User: allrightname
Functions: find rm sed xargs
-1

The thunderbird message datastores get corrupt some times causing random failures, compaction to fail and general suck in thunderbird. Removing them causes thunderbird to rebuild the indexes and makes things quick again.

fdupes -rdN $folder
openssl pkcs8 -inform DER -nocrypt -in [priv key] -out [pem priv key]
eval $(curl -s http://www.commandlinefu.com/commands/matching/external/ZXh0ZXJuYWw=/sort-by-votes/plaintext|sed -n '/^# Get your external IP address$/{n;p;q}')
2009-11-04 16:58:31
User: jgc
Functions: eval sed
-1

This command uses the top voted "Get your external IP" command from commandlinefu.com to get your external IP address.

Use this and you will always be using the communities favourite command.

This is a tongue-in-cheek entry and not recommended for actual usage.

PATH="${PATH}:$(find ${HOME}/bin -type d | tr '\n' ':' | sed 's/:$//')"
2013-06-19 19:22:06
User: malathion
Tags: $PATH
-1

Many users have a personal ~/bin folder for user scripts and other miscellaneous applications they can't or don't want to add to /usr/bin. But this folder can get large and unwieldy. The above command adds ~/bin and all its subdirectories to the PATH environment variable so the scripts can be organized without changing .bashrc.

openssl ans1parse -inform DER < [priv key]
2009-02-05 16:54:19
User: wwest4
-1

a pkcs8 key will have integer 00 at offset 4 and an rsaEncryption object at offset 9

defaults write com.apple.finder NSUserKeyEquivalents -dict 'New Finder Window' '@$N' 'New Folder' '@N'; killall Finder
2009-02-17 23:20:53
User: Vulpine
Functions: killall write
-1

In Mac OS 9, the "New Folder" keyboard shortcut was Command+N, but in Mac OS X this was changed to "New Finder Window" instead, with "New Folder" taking the more awkward shortcut of Command+Shift+N. This command reverses their mappings.

find -name ".php" -exec perl -pi -e 's/search/replace/g/' {} \;
git push origin --all
awk "/<xsd:annotation>/{h=1};!h;/<\/xsd:annotation>/{h=0}" annotatedSchema.xsd
2011-07-15 07:17:17
User: 2chg
Functions: awk
Tags: xml filter
-1

Removes all lines between the lines containing "" and "", including these lines itself

Backdrop:

Sometimes when working with XML files without an graphical editor, large comment-/annotation-blocks taper the readability to walk through the file. I like to create a copy of such documents without these annotations. As the documentation itself is in documentation tags inside the annotation tags an therefore graphical editors tend to put the annotation tags in their own lines, this command removes all documentations within annotation-tags.

ip route show | awk '$3 ~ /^[1-9]+/ {print $3;}'
2010-08-08 23:57:23
User: kerim
Functions: awk route
-1

Find your default gateway and print it directly output.

http://www.bayner.com/

kerim@bayner.com