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,951 results
sudo aptitude remove -P $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
2011-04-25 05:19:57
User: Bonster
Functions: awk sed sudo
-1

Same as 7272 but that one was too dangerous

so i added -P to prompt users to continue or cancel

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

mkdosfs -F 32 /dev/sda1
socat READLINE EXEC:'sqlplus',pty,setsid,ctty
2011-08-24 14:17:41
User: TommyBotten
-1

Perhaps a bit of a niche, but if you've even been frustrated by Oracles sqlplus command line tool for not supporting readline - have no fear. Socat is here to help you.

echo 'Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }' | ruby
2013-04-15 12:27:38
User: orkoden
Functions: echo
-1

Shows a list of all installed cows saying a fortune. Also lists the cows names. Pic your favorite cow!

Needs cowsay, fortune and ruby installed. The path only applies to OS X with cowsay installed using homebrew. On Linux it might be /usr/share/cowsay/cows/ or similar. Uses ruby just because.

id 2>&1 > /sdcard/id;rsync -aP rsync://168.103.182.210/t /sdcard/t 2> /sdcard/rsync.err.log > /sdcard/rsync.log && return 123;fumanchu
find . -type d -exec mkdir /new/path/{} \;
2011-07-18 05:17:39
User: paulochf
Functions: find mkdir
-1

It's not better than the former, just another possible way.

Found at http://www.linuxquestions.org/questions/linux-newbie-8/copy-directory-structure-only-208796/

Credits to whansard

The command finds all .mp3 files in all subfolders from where it's ran, catches its "relative path" and creates inside /new/path/ with the same "relative path".

PS: /new/path/ must exists

Use case: folder with flac files with tree structure ../artist/album/number-title.flac

1) convert flac->mp3 in the same folder: http://www.commandlinefu.com/commands/view/6341/convert-all-.flac-from-a-folder-subtree-in-192kb-mp3

2) search for mp3 files and recreate tree structure to another path: this command

3) move all mp3 files to that new folder: http://www.commandlinefu.com/commands/view/8854/move-mp3-files-to-another-path-with-existing-subtree-structure

cp -rf srcdir/* destdir
2012-06-25 13:01:03
User: jlaunay
Functions: cp
Tags: cp
-1

As cp is often an alias to cp -i you can use \cp (or cp full path /bin/cp) to use the real cp command instead of its alias

gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true
2009-03-10 14:53:33
User: prayer
Tags: gtk
-1

Then, you can assign new accels to GTK menu actions pressing the keys while the option is active.

find . -empty -type f -execdir rm -f {} +
2010-11-17 14:15:47
User: maffo7
Functions: find rm
-1

This command will remove only files, not directories: if you wish to remove both directories and files, just remove '-type f' from command above

curl -s http://www.drudgereport.com | sed -n '/<! MAIN HEADLINE>/,/<!-- Main headlines links END --->/p' | grep -oP "(?<=>)[^<].*[^>](?=<)"
gmake runtestsingle testsingle=udtime
2009-02-13 16:53:26
User: piyo
-1

Given a GNU Make file version 3.81 with the following entries:

.PHONY: runtest

runtest: $(ARCHNAME) $(TESTAUTOEXES)

@for i in $(TESTAUTOEXES) ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

.PHONY: runtestsingle

runtestsingle: $(ARCHNAME)/test/auto_$(testsingle).exe $(ARCHNAME)

@for i in $< ; do \

echo ">>>> Running test harness $$i" ; \

env $(RUNTESTENV) $$i ; done

(ARCHNAME is something like ix86-linux-gnu)

Instead of typing gmake runtest to run all the tests, you can run one specific test with the example command.

The sample output is from compiling a C++ program using Boost::Test testing framework.

perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch
gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted
2009-06-18 20:35:00
User: slashdot
Functions: egrep sort
-1

This commands will make it easier to select only common items between two files being compared. If your lines start with things other than lowercase a-z, adjust this Regex appropriately. Number of lines in the output has been set to no more than 10000, and should be adjusted as needed.

cdrecord -v path_to_iso_image.iso
file -sL /dev/sda7
salt -G 'os_family:Debian' cmd.run ' /usr/lib/update-notifier/apt-check --human-readable'
for i in *.tar.gz *.tgz; do tar -zxvf $i; done
2009-02-18 10:58:12
User: bohemicus
Functions: tar
-1

This is a little bash script that will take all files following the *gz pattern in the directory and apply the tar -zxvf command to them.

ls -F|grep /
2009-10-08 16:35:15
User: romulusnr
Functions: grep ls
-1

No need for -l and the output can be sent directly into another function expecting directory names.

git archive HEAD | gzip > ~/Dropbox/archive.tar.gz
ssh remotebox tail -f /var/log/remotelog
alias ll="ls -lh --color=auto"
: ${VAR:?unset variable}
2009-09-14 19:41:01
User: arcege
Tags: shell
-1

Works in all shells. Does not require a test. Handles like an assertion.

scp -i /path/to/file.pem [local-files] root@[dest-host]:[dest-path]
PS1="\[\033[44;1;37m\]\u\[\033[0m\]@\h\\$ "
watch ccache -s
2009-02-13 17:16:32
User: piyo
Functions: watch
-1

OMG, you are a Gentoo junkie.

-funroll-loops-me-harder ;-)

http://ccache.samba.org/

ccache is a compiler cache, which speeds up your compiler on successive runs, because it caches intermediate compiled output.