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 - 408 results
sudo arp-scan -I eth0 192.168.1.0/24
sudo find . -maxdepth 1 -cnewer olderFilesNameToMove -and ! -cnewer newerFileNameToMove -exec mv -v {} /newDirectory/ \;
2010-06-30 20:40:30
User: javamaniac
Functions: find mv sudo
2

In a folder with many files and folders, you want to move all files where the date is >= the file olderFilesNameToMove and

proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; sudo sh -c "$sudor_command"; }; alias sudor="proceed_sudo # "
2010-06-29 14:56:29
User: mechmind
Functions: alias sh sudo
Tags: history sudo
3

USAGE: $ sudor your command

This command uses a dirty hack with history, so be sure you not turned it off.

WARNING!

This command behavior differ from other commands. It more like text macro, so you shouldn't use it in subshells, non-interactive sessions, other functions/aliases and so on. You shouldn't pipe into sudor (any string that prefixes sudor will be removed), but if you really want, use this commands:

proceed_sudo () { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; pre_sudor_command="`history 1 | cut -d ' ' -f 5- | sed -r -e 's/sudor.*$//' -e 's/\"/\\\"/g'`"; if [ -n "${pre_sudor_command/ */}" ] ; then eval "${pre_sudor_command%| *}" | sudo sh -c "$sudor_command"; else sudo sh -c "$sudor_command" ;fi ;}; alias sudor="proceed_sudo # "
sudo -s "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all"
2010-06-22 19:16:43
User: sliceoflinux
Functions: sudo
Tags: ping icmp
6

It really disables all ICMP responses not only the ping one.

If you want to enable it you can use:

sudo -s "echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all"
dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge
2010-06-16 22:06:07
User: danlangford
0

on a dpkg managed system this PATTERN will help you generate .deb files from source AND remove all the dev libs you had to install. i hate cluttering up my machine with rouge packages and headers.

it would be pretty darn easy on rpm systems as well. i just dont have a rpm managed system to test on right now.

NOTE, you sharp ones will notice that it uninstalls the deb you just made! yeah, but the deb is still there to do with it what you want, like re install it. or you can just grep -v after the diff

sudo lsof -u someuser -a +D /etc
2010-06-11 06:37:27
User: zlemini
Functions: sudo
16

View all files opened by a user in specified directory.

The +D option makes lsof search all sub-directories to complete depth, while ignoring symbolic links.

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
2010-06-10 20:33:32
User: mitzip
Functions: sed sudo xargs
4

This will remove all installed kernels on your debian based install, except the one you're currently using.

From:

http://tuxtweaks.com/2009/12/remove-old-kernels-in-ubuntu/comment-page-1/#comment-1590

sudo lvdisplay |awk '/LV Name/{blockdev=$3} /Block device/{bdid=$3; sub("[0-9]*:","dm-",bdid); print bdid,blockdev;}'
2010-06-10 11:50:31
Functions: awk sudo
Tags: awk lvm
1

Emits the device names which will be printed by iostat for an LVM volume; doesn't show the names for the underlying devices when snapshots are being used (the -cow and -real devices in /dev/mapper)

sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
2010-05-23 11:39:35
User: bandie91
Functions: echo sudo sync tee
9

where proc filesystem mounted under /proc

sudo vconfig add eth0 [VID]
2010-05-15 21:32:24
User: leovailati
Functions: sudo
Tags: sudo vconfig
1

Great for sysadmins! Don't forget to pass the vlan to your port in a manageable switch.

After vconfig, you should use

sudo ifconfig eth0.[VID] up

Now the interface is up, you can use dhclient or ifconfig again to get an ip address.

pgrep rouge-process | xargs sudo kill -9
2010-05-09 22:30:05
User: mheadd
Functions: kill sudo xargs
Tags: xargs pgrep
-3

Find and kill multiple instances of a process with one simple command.

sudo usermod -p $(mkpasswd '') user_id
2010-05-06 20:39:58
User: ckclark
Functions: sudo usermod
-1

It is safe when there is

"PermitEmptyPasswords no"

in /etc/ssh/sshd_config.

This command is useful when there is no need to have a password.

echo "savedefault --default=2 --once" | grub --batch; sudo reboot
2010-05-02 03:06:23
User: matthewbauer
Functions: echo sudo
Tags: grub Reboot os
7

This will reboot as the Grub 2 option.

sudo powertop
2010-04-19 21:59:29
User: rkulla
Functions: sudo
3

Run this command as root to get enough stats. It works on AMD and Intel machines, including desktops. If ran on a laptop it'll give you suggestions on extending your battery life.

You'll need to install PowerTOP if you don't have, via 'apt-get install powertop', etc.

To grep the output use: sudo powertop -d | grep ...

The many command suggestions PowerTOP gives you alone will increase your command-line fu!

APP=wine; if [ $(sudo apt-get --print-uris -y install $APP | sed -ne 's/^After this operation, \([0-9]\{1,\}\).*MB.*/\1/p') -gt 50 ]; then gnometris 2>/dev/null & sudo apt-get install $APP; else sudo apt-get install $APP; fi
2010-04-18 19:32:26
User: rkulla
Functions: install sed sudo
2

Change the APP variable's value to whatever you want to install. Depending on how fast your machine is, you'll want to adjust the value 50 to something else. You might also want to play a different game than Gnometris - just make sure it's a GUI game.

cd /etc/init.d && sudo ./apache2 start
2010-04-17 16:01:18
User: nco
Functions: cd sudo
-9

This command is designed in order to avoid this error :

/etc/init.d/apache2 force-reload

* Reloading web server config apache2 httpd not running, trying to start

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

[fail]

sudo deborphan | xargs sudo apt-get -y remove --purge
sudo dmidecode --type=processor | grep -i -A 1 charac
sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c
2010-04-09 10:31:50
User: ninjasys
Functions: awk sort sudo uniq
Tags: log error apache
1

This command will return a full list of Error 404 pages in the given access log. The following variables have been given to awk

Hostname ($2), ERROR Code ($9), Missing Item ($7), Referrer ($11)

You can then send this into a file (>> /path/to/file), which you can open with OpenOffice as a CSV

sudo ethtool -s eth0 speed 100 duplex full
2010-04-05 10:36:27
User: 0disse0
Functions: sudo
1

ethtool is used for querying settings of an ethernet device and changing them. In this example I setup 100 Mb/s full duplex on my Linux Box

sudo date -s "$(ssh user@server.com "date -u")"
2010-03-31 11:59:27
User: rpavlick
Functions: date sudo
Tags: sudo
5

(Useful when firewalls prevent you from using NTP.)

sudo ifconfig en1 ether 00:e2:e3:e4:e5:e6
2010-03-30 21:48:55
User: rpavlick
Functions: ifconfig sudo
0

If you want to check that the spoof worked, type the same command as earlier:

ifconfig en1 | grep ether

Now you will see:

ether 00:e2:e3:e4:e5:e6

For the wired ethernet port:

sudo ifconfig en0 ether 00:e2:e3:e4:e5:e6
sudo chattr -i <file that cannot be modified>
2010-03-25 03:14:34
User: leovailati
Functions: chattr sudo
Tags: Ubuntu chattr
1

I had problems in Ubuntu while trying to edit /etc/resolv.conf, even with sudo I couldn't make any change. After a 2 minutes search on google I found this command.

Hope someone finds it useful.

It works like chmod, with + and - to denote which attributes are being added and which are being removed.

See other attributes on man pages or on wikipedia http://en.wikipedia.org/wiki/Chattr

sudo apt-get -o Acquire::http::Dl-Limit=30 upgrade
2010-03-22 01:29:44
User: alemani
Functions: sudo
16

Limits the usage of bandwidth by apt-get, in the example the command will use 30Kb/s ;)

It should work for most apt-get actions (install, update, upgrade, dist-upgrade, etc.)

awk '/d[a-z]+$/{print $4}' /proc/partitions | xargs -i sudo hdparm -I /dev/{} | grep 'device size with M'