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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using sudo from sorted by
Terminal - Commands using sudo - 429 results
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

USAGE: $ sudor your command

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


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

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

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

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

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



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

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)

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

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

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

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

This will reboot as the Grub 2 option.

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

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

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

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

no listening sockets available, shutting down

Unable to open logs


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

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

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

(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

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

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

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'
for I in $(awk '/d[a-z]+$/{print $4}' /proc/partitions); do sudo hdparm -I '/dev/'$I; done | grep 'device size with M'
2010-03-02 18:56:32
User: ElAlecs
Functions: awk grep hdparm size sudo
Tags: hdparm

I know this sucks in some way but if someone can improve it please be my guest

sudo truecrypt <truecrypt-file> <mount-point>
2010-02-27 16:25:19
User: kbrill
Functions: sudo

It seems to completely void the benefit of having an encrypted folder if you then have a script on your unencrypted hard drive with your password in it. This command will mount a truecrypt file at a given mount point after asking you for the password.

sudo aptitude update; sudo apt-get -y --print-uris upgrade | egrep -o -e "http://[^\']+" | sudo aria2c -c -d /var/cache/apt/archives -i -; sudo aptitude -y safe-upgrade
2010-02-18 16:02:29
User: freethinker
Functions: egrep sudo

Please install aria2c before you try the above command. On ubuntu the command to install aria2c would be:

sudo aptitude install aria2