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 sudo from sorted by
Terminal - Commands using sudo - 407 results
sudo update-rc.d -f nomemioscript start 99 2 3 4 5
echo "GRUB_INIT_TUNE=\"480 440 4 440 4 440 4 349 3 523 1 440 4 349 3 523 1 440 8 659 4 659 4 659 4 698 3 523 1 415 4 349 3 523 1 440 8"\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
dpkg -l | sed '/^rc/!d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/' | xargs -r sudo apt-get -y purge
sudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
sudo rpm -if "http://rpm_server/rpm_repo/this-app.rpm"
sudo chattr -R +i dirname
2011-05-17 05:05:49
User: mamue
Functions: chattr sudo
Tags: touch
6

-R Recursively change attributes of directories and their contents.

+i to set the immutable bit to prevent even root from erasing or changing the contents of a file.

sudo aptitude markauto $(apt-cache showsrc PACKAGE | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)//g')
sudo socat TCP4-LISTEN:80,bind=127.0.0.1,fork EXEC:'echo "HTTP/1.1 503 Service Unavailable";'
2011-05-02 19:31:56
User: adelie42
Functions: sudo
9

Normally when a site is blocked through /etc/hosts, traffic is just being redirected to a non-existent server that isn't going to respond. This helps get your point across a little more clearly than a browser timeout.

Of course you could use any number of codes: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Obviously, this command can be added to init-rc.d, and more sophisticated responses can be given. Seems noteworthy to mention that the information sent from the browser can be parsed using the bash READ builtin (such as 'while read -t 1 statement; do parsing'), and the connection stays open until the script exits. Take care that you must use EXEC:'bash -c foo.sh', as 'execvp' (socat's method for executing scripts) invokes 'sh', not 'bash'.

echo "shutdown -h now" | sudo at now + 4 hours
2011-05-02 15:29:48
User: depesz
Functions: at echo sudo
-2

Benefit is that it doesn't make you keep the terminal open.

sudo bash -c 'echo "GRUB_INIT_TUNE=\"480 165 2 165 2 165 3 554 1 587 1 554 2 370 1 554 1 523 2 349 1 523 1 494 3 165 2 165 2 165 2\"" >> /etc/default/grub && update-grub'
2011-05-02 12:06:49
User: slayer_ftw
Functions: bash sudo
3

I'll let Slayer handle that. Raining Blood for your pleasure.

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).

echo "GRUB_INIT_TUNE=\"1000 334 1 334 1 0 1 334 1 0 1 261 1 334 1 0 1 392 2 0 4 196 2\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
sudo apt-get install linux-headers-$(uname -r)
sudo apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver pool.sks-keyservers.net --recv $key && gpg --export --armor $key |sudo apt-key add -; done
2011-03-30 08:18:54
User: Bonster
Functions: echo gpg grep sed sudo
5

You can choose these mirror servers to get gpg keys, if the official one ever goes offline

keyserver.ubuntu.com

pool.sks-keyservers.net

subkeys.pgp.net

pgp.mit.edu

keys.nayr.net

keys.gnupg.net

wwwkeys.en.pgp.net #(replace with your country code fr, en, de,etc)

sudo aptitude purge ~ilinux-image-\[0-9\]\(\!`uname -r`\)
2011-03-28 13:54:21
User: ootync
Functions: sudo
1

Removes piling kernels from /boot, save the current one.

This command DOES NOT remove the 'linux-image-generic' package, so you'll continue getting kernel updates

sudo pacman -Rns packagename
2011-03-20 21:07:14
User: ibnarrashid
Functions: sudo
0

Removes the package, 'packagename' in the example ,from your system. '-R' is the actual removal option, 'n' is for removing backup configuration files saved by pacman, and 's' is for removing the dependencies of the given package which are not required by other packages. pacman does not remove configuration files, etc. created by the package.

sudo pacman -Scc
2011-03-20 20:57:42
User: ibnarrashid
Functions: sudo
0

Clears the package cache of all packages, installed and uninstalled packages. Do NOT USE if you might want to downgrade a package later.

sudo pacman -Sc
2011-03-20 20:55:32
User: ibnarrashid
Functions: sudo
0

Clears the package cache of all uninstalled packages. Does not remove package configuration files in user's home directory.

sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
2011-03-20 20:33:35
User: ibnarrashid
Functions: sudo
0

Requires 'reflector' package from official repository. '5' in the example is the number of mirrors you want in the mirrorlist, could be other numbers of course.

sudo -i; add-apt-repository ppa:webupd8team/sublime-text-2; apt-get update; apt-get install sublime-text-2
2011-03-16 23:57:41
User: xmonkey
Functions: install sudo
-7

This is the first version of the Sublime Text 2 packaging so there might be bugs.

sudo scutil --set HostName MY_NEW_HOSTNAME
sudo tcpdump -i eth0 -s 65535 -A -ttt port 11211
sudo update-alternatives --config java
2011-03-07 23:43:52
User: mccalni
Functions: sudo
Tags: java
1

You have openjdk and sun java installed. Many of your java plugins will not work properly. Something called IcedTea (the java web plugin) keeps crashing. Run this and select sun java to use sun java.

fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else sudo ln -f ${line// .*/} $file; fi; done; done
sudo arp-scan -l
2011-02-21 21:58:27
Functions: sudo
Tags: Arp arp-scan
8

A much quicker and (not dirtier) option. use the man page for help. On linux/ubuntu you will need to `sudo apt-get -y install arp-scan`.