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 - 426 results
sudo tcpdump -n -i eth0 -w data.pcap -v tcp or udp and 'not host'
sudo dpkg -i `ls -tr *.deb | tail -n4`
2011-10-09 14:20:11
User: _john
Functions: sudo tail

after kernel build with make deb-pkg, I like to install the 4 newest packages that exist in the directory. Beware: might be fewer for you....

sudo grub-install --root-directory=/media/ubuntu /dev/sda
2011-09-27 17:51:56
User: totti
Functions: sudo
Tags: grub boot fix

From live CD mount(open) the Ubuntu installed drive.

Copy the location (press Ctrl+l, Ctrl+c ) eg: /media/ubuntuuuu

Open terminal (Apllication->accessories->terminal)

Type this:

sudo grub-install --root-directory=/media/ubuntuuuu /dev/sda

(replace /media/ubuntuuuu with what u got (ie paste))

Will show success message. Now reboot

sudo ngrep -lqi -p -W none ^get\|^post tcp dst port 80 -d eth0 | egrep '(flv|mp4|m4v|mov|mp3|wmv)'
2011-09-18 06:33:36
User: marste
Functions: egrep sudo

Discover host and url of media files (ex. flv, mp4, m4v..).

It locate the urls of audio and video files so that they can be recorded.

sudo service bluetooth restart
sudo find / -type f | perl -MFile::Basename -ne '$counts{dirname($_)}++; END { foreach $d (sort keys %counts) {printf("%d\t%s\n",$counts{$d},$d);} }'|sort -rn | tee /tmp/sortedfilecount.out | head
2011-09-14 19:41:19
User: tamouse
Functions: find perl sort sudo tee

Find which directories on your system contain a lot of files.

Edit: much shorter and betterer with -n switch.

sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/
sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep udp && echo && sudo netstat|head -n2|tail -n1 && sudo netstat -a|grep tcp
if [ $EUID -ne 0 ];then if [ -t $DISPLAY ]; then sudo $0 "$*"; exit; else xdg-su -c "$0 $*"; exit;fi;fi
2011-08-24 18:03:46
User: houghi
Functions: sudo

Will run the script as root and exit if the wrong or no password is given. Also will keep the parameters active if any where given.

if [ $EUID -ne 0 ]; then if [ -t 0 ]; then exec sudo $0; else exec gksu $0; fi; fi;
2011-08-23 11:43:37
User: stanix
Functions: exec sudo

Place this code at the beginning of your script to ensure that it can only be executed by the root.

sudo ettercap -T -w out.pcap -i wlan0 -M ARP // //
sudo sox <file name>.wav -r 8000 <file name>.gsm
sudo sox <file name>.wav -r 8000 <file name>.gsm
sudo apt-get -y purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}')
2011-08-04 14:02:02
User: dakira
Functions: awk sudo

Removes all kernels and corresponding packages except of the one you're currently using.

sudo lsof -rc command >> /tmp/command.txt
2011-08-03 20:19:53
User: zlemini
Functions: command sudo

Run this before you run a command in order to see what the command does as it starts.

The -c flag is useful here as the PID is unknown before startup.

All config files, libraries, logs, ports, etc used by the command as it starts up, (and shuts down) will be captured at 1s intervals and written to a file.

Useful for debugging etc.

VBoxBlockBoot() { sudo umount "$2"*; sudo chmod 777 "$2"; VBoxManage storageattach "$1" --medium ~/.rawHD4VB_`basename "$2"`.vmdk --type hdd --storagectl "IDE Controller" --device 0 --port 0 ; VBoxManage startvm "$1";}
2011-07-29 13:04:19
User: totti
Functions: chmod sudo umount

Usage: VBoxBlockBoot [Virtual_Machine] [Block_device]

Eg: VBoxBlockBoot WinXP /dev/sdc

In another words

vm=usb; usb=sdc;sudo umount /dev/$usb* ; sudo chmod 777 /dev/$usb ; VBoxManage storageattach $vm --medium ~/raw-HD-4-VB/$usb.vmdk --type hdd --storagectl "IDE Controller" --device 0 --port 0 ; VBoxManage startvm $vm


vm --> Name of the virtual machine to start

usb --> Block device to use. (/dev/sdc)

This can used after setup up a boot loader on to my USB pen drive or HDD (After creating Live USB). Here root privilege is needed but not granted to Virtual Box. Thus we can access all our VM.( If we run VBox as root we can't access our VMs). Root privilege is used to

- Unmount the storage device

- Chmod to full access (777)


1. Device information file (rawvmdk file) created by the following command. Need to run only once. Not bad to run many.

VBoxCreateRawDisk() { VBoxManage internalcommands createrawvmdk -filename ~/.rawHD4VB_`basename "$1"`.vmdk -rawdisk "$1"; }

2. Root privilege to umount & chmod

3. Real storage medium (ie /dev/*) (Non-virtual such as USB HD, pen drive, a partition)

4. A virtual m/c already available (here "usb")

vm=usb; usb=sdc;sudo umount /dev/$usb* ; sudo chmod 777 /dev/$usb ; VBoxManage storageattach $vm --medium ~/raw-HD-4-VB/$usb.vmdk --type hdd --storagectl "IDE Controller" --device 0 --port 0 ; VBoxManage startvm $vm

VBoxBlockBoot() { sudo umount "$2"*; sudo chmod 777 "$2"; VBoxManage storageattach "$1" --medium ~/.rawHD4VB_`basename "$2"`.vmdk --type hdd --storagectl "IDE Controller" --device 0 --port 0 ; VBoxManage startvm "$1"; }

sudo tcpdump -i en0 'udp port 53'
sudo sh -c 'gunzip -c source.gz > destination'
2011-07-05 23:51:01
User: UnixNeko
Functions: sh sudo

Extracting .gz files and placing the output in another directory in one command line is convenient thing.

I just followed some how-to to install Nagios on Ubuntu Lucid Lynx but they give the method to install from archives. I wished to install from the repository. If you do so some files are missing. I've not tested yet but this is an example command line I did to extract

sudo sh -c 'gunzip -c /usr/share/doc/nagios3-common/examples/template-object/templates.cfg.gz > /etc/nagios3/objects/templates.cfg'

We need privilege to write the destination file.

sudo env ARCHFLAGS="-arch x86_64" gem install mysql
sudo bash -c "sleep 1h ; command"
2011-06-15 16:46:31
User: dbh
Functions: bash sudo
sleep 1h ; sudo command


sudo sleep 1h ; sudo command

won't work, because by the time the delay is up, sudo will want your password again.

sudo update-rc.d -f nomescript stop 90 0 6
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