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 - 418 results
sudo update-grub
2014-02-27 19:50:25
User: Anshik
Functions: sudo
-5

sudo gedit /etc/default/grub

This would open the Grub configuration file. In this file we have to edit the line

GRUB_CMDLINE_LINUX=""

to

GRUB_CMDLINE_LINUX="acpi_backlight=vendor"

sudo lsof -i -n -P | grep TCP
sudo chmod --reference=Referenz.foo Datei.foo
sudo passwd <username>
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge
ram() { mt=/mnt/ram && grep "$mt" < /proc/mts > /dev/null; if [ $? -eq 0 ] ; then read -p"Enter to Remove Ram Partition ";sudo umount "$mt" && echo $mt 0; else sudo mt -t tmpfs tmpfs "$mt" -o size=$(( ${1:-1} * 1024 ))m && echo $mt '-' "${1:-1}"gb; fi; }
2013-12-13 05:22:02
User: snipertyler
Functions: echo grep mt read sudo umount
Tags: sudo ram tmpfs
3

Creates a temporary ram partition

To use:

ram 3

to make a 3gb partition (Defaults to 1gb)

x=KEY; gpg --keyserver subkeys.pgp.net --recv $x; gpg --export --armor $x | sudo apt-key add -
2013-11-26 10:49:32
User: sxiii
Functions: gpg sudo
1

Replace KEY with GPG key. This command will load GPG key and add it to your system so you can use software from third party repos etc.

for line in `ps aux | grep <string> | awk '{print $2}'`; do sudo kill $line; done;
2013-11-24 00:02:16
User: mjbrune
Functions: awk grep kill sudo
0

Kills all processes with a certain string. This was done to kill all ssh sessions openned by zenoss which look like: usr/bin/ssh /opt/zenoss/bin/zenmodeler

dpkg -l | grep ^ri | awk '{print $2 " install"}' | sudo dpkg --set-selections
2013-11-23 06:41:18
User: ajmccluskey
Functions: awk grep sudo
0

If you run dpkg --clear-selections or have otherwise selected installed packages for deinstall, but want to undo it, run this. It will set all installed packages back to installed status so that they won't be removed by commands like "dpkg -Pa"

% sudo yum remove streams-$(uname-r)
sudo lsof -iTCP:25
sudo lsof -iTCP:25 -sTCP:LISTEN
sudo apt-get build-dep rhythmbox
sudo adduser [username] lp && sudo adduser [username] lpadmin && sudo hp-setup -i
sudo tar -zcvf $(hostname)-etc-back-`date +%d`-`date +%m`-`date +%y`.tar.gz /etc && sudo chown $USER:$USER $(hostname)-etc-back*
2013-08-18 12:49:11
User: thanosme
Functions: chown sudo tar
Tags: backup tar date
0

Back up /etc directory with a name based on the current date and the hostname of the machine, then chown the file for the current user for use.

sudo netstat -plntu --inet | sort -t: -k2,2n | sort --stable -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | sort -s -t" " -k1,1
2013-08-13 09:21:26
User: thechile
Functions: netstat sort sudo
0

bit of a contrived example and playing to my OCD but nice for quick scripted output of listening ports which is sorted by port, ip address and protocol.

sudo tune2fs -l $(df -h / |(read; awk '{print $1; exit}')) | grep -i created
2013-08-08 15:18:09
User: thechile
Functions: awk df grep sudo tune2fs
12

..not guaranteed to always be accurate but fun to see how old you Linux installation is based on the root partitions file system creation date.

sudo netstat -tulpn | grep :8080
sudo mount vmware-server-flat.vmdk /tmp/test/ -o ro,loop=/dev/loop1,offset=32768 -t ntfs
2013-07-29 14:45:29
User: JeremyinNC
Functions: mount sudo
0

Assumes XP/2000/2003. For Server 2008+ try offset=105,906,176 You can find this number in the System Information utility under Partition Starting Offset. UEFI based boxes you want partition 2 since the first is just the boot files (and FAT). This works with (storage side) snapshots which is handy for single file restores on NFS mounted VMware systems

sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys [key to get here]
2013-07-23 08:29:40
User: phattmatt
Functions: get sudo
0

If you are an unlucky soul behind a corporate firewall you will likely find that downloading gpg keys is blocked. This is because the hkp protocol uses port 11371 by default to transfer the key.

By adding "hkp://" to the beginning of the hostname and ":80" to the end you are asking gpg to try using port 80 to connect (less likely to be blocked by a firewall). This relies on the remote server answering to requests over port 80.

sudo port selfupdate && sudo port upgrade outdated && sudo port clean --all installed && sudo port -f uninstall inactive
sudo dumpe2fs /dev/sda1 | grep superblock
sudo /usr/sbin/exim -bp | sed -n '/\*\*\* frozen \*\*\*/,+1!p' | awk '{print $1}' | tr -d [:blank:] | grep @ | sort | uniq -c | sort -n
sudo lsof -p `sudo ps aux | grep -i neo4j | grep -v grep | awk '{ print $2 }'`
2013-06-02 10:15:30
User: andycunn
Functions: awk grep ps sudo
0

Inner "ps...grep..." command searches for a process matching the specified .

"lsof -p lists all file descriptors owned by . Includes open files, sockets, devices, etc...

sudo apt-cache dumpavail | grep Package | cut -d ' ' -f 2 > available.packages