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:



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.

Top Tags



Commands using sudo from sorted by
Terminal - Commands using sudo - 425 results
sudo mdutil -a -i off
2010-08-26 16:34:20
User: ElAlecs
Functions: sudo

To re enable just change the "off" for "on"

sudo foremost -i /dev/sda -o /recovery
2010-08-19 22:27:41
User: vlan7
Functions: sudo

The above command assumes the lost data is on /dev/sda and you previously issued the following command to mount _another_ disk or partition (/dev/sdb1) on /recovery

sudo mount /dev/sdb1 /recovery

If you don't do this, the data could be overwrited!

foremost is a very powerful carving tool. By default foremost recovers all known file types. If you want to reduce the amount of files that are recovered you can specify the file type you are looking for. Read the man page to know the available file types.

i.e to recover JPEG pictures append to foremost the switch -tjpg

sudo tcpdump -i eth0 -n port 67 and 68
2010-08-18 19:36:06
User: wsv123456
Functions: sudo tcpdump

You don't need this command often and there are other ways to test output but if you want to be sure if your router and ethernet card are working this is one way.

sudo dmidecode -t processor
vi2() {for i in $@; do [ -f "$i" ] && [ ! -w "$i" ] && sudo vim $@ && return; done; vim $@}
2010-08-15 10:00:14
User: pipeliner
Functions: sudo vim
Tags: vim sudo

Like the http://www.commandlinefu.com/commands/view/6327/open-file-with-sudo-when-there-is-no-write-permission, but works (in zsh; my commandlinefu is not strong enough to understand why bash don't like it) with vim options, like -O, and many input files.

There could be other mistakes.

if test -w $1; then vim $1; else sudo vim $1; fi
2010-08-14 13:28:32
User: srepmub
Functions: sudo test vim
Tags: vim sudo tee

this avoids several VIM warnings, which I seem too stupid to disable: warning, readonly! and: file and buffer have changed, reload?!

sudo sh -c "apt-get update;apt-get dist-upgrade;apt-get autoremove;apt-get autoclean"
2010-08-13 16:12:18
User: l0b0
Functions: sh sudo

Gets you the latest of everything, and removes any remaining junk. The "sh -c" part is so that you'll only run a single sh command, so you won't get asked more than once for the password.

sudo pm-suspend
sudo /etc/acpi/sleep.sh sleep
2010-08-03 23:54:49
User: jmfork
Functions: sudo
Tags: sleep suspend

It suspends to RAM: you always need your batteries for the RAM but it saves time as there is no need to slowly archive everything on your hard disk.

It works fine with me but if anyone has a nicer way, please contribute.

sudo ethtool -s eth0 wol d
sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f
2010-07-30 18:20:00
User: vutcovici
Functions: echo eval grep ls sed sudo tail xargs

Tail all logs that are opened by all java processes. This is helpful when you are on a new environment and you do not know where the logs are located. Instead of java you can put any process name. This command does work only for Linux.

The list of all log files opened by java process:

sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'
sudo dd if=/dev/sdc bs=4096 | pv -s 2G | sudo dd bs=4096 of=~/USB_BLACK_BACKUP.IMG
2010-07-28 22:39:46
User: BruceLEET
Functions: dd sudo

This command utilizes 'pv' to show dd's progress.

Notes on use with dd:

-- dd block size (bs=...) is a widely debated command-line switch and should usually be between 1024 and 4096. You won't see much performance improvements beyond 4096, but regardless of the block size, dd will transfer every bit of data.

-- pv's switch, '-s' should be as close to the size of the data source as possible.

-- dd's out file, 'of=...' can be anything as the data within that file are the same regardless of the filename / extension.

sudo iptables -L -nv
sudo dpkg-reconfigure -a
for i in {a..z};do sudo rm /usr/share/doc/$i*/*;done
2010-07-23 01:52:25
User: LinuxMan
Functions: rm sudo

Never read the documentation? No, then why have that ~ 20 MB sit there and take up space? This command preserves directory structure wile removing all of those unnecessary help and documentation files. Works on Ubuntu, Debian, and most related systems. Gives a lot of directory errors, I'll fix those later.

sudo ping -f -c 999 -s 4500 target.com
2010-07-11 16:38:44
User: gunslinger_
Functions: ping sudo
Tags: ping

sending packet by ping

if sending more high packet root needed...

sudo lsof|sed 's/ */ /g'|cut -f3 -d' '|sort -u
2010-07-07 08:20:28
User: binaryten
Functions: cut sed sort sudo

Most systems (at least my macbook) have system users defined, such as _www and using "users" for example will not list them. This command allows you to see who the 'virtual' users are on your system.

goburncd() { d=/tmp/goburncd_$RANDOM; mkdir $d && for i in *.[Mm][Pp]3; do lame --decode "$i" "$d/${i%%.*}.wav"; done; sudo cdrecord -pad $d/* && rm -r $d; eject }
2010-07-06 21:58:10
User: meathive
Functions: cdrecord eject mkdir rm sudo

My variation on an audio burning command from commandlinefu - this one doesn't crap out if you want to burn a CD in a directory whose permissions don't allow it, and instead rips everything to /tmp. If you mount your music partition like I do using Samba, you probably don't have write permission inside that file system in order to create the temporary directory other audio burning commands here use. Not a bad idea to add cdrom to your groups, and /bin/eject with visudo.

qlist --exact "$pkg" | sudo scanelf --needed --quiet --format '%n#F' | tr ',' '\n' | sort -u | qfile --from -
2010-07-06 14:39:15
User: Flameeyes
Functions: sort sudo tr

The output is only partial because runtime dependencies should count in also commands executed via system() and libraries loaded with dlopen(), but at least it gives an idea of what a package directly links to.

Note: this is meaningful *only* if you're using -Wl,--as-needed in your LDFLAGS, otherwise it'll bring you a bunch of false positives.

sudo arp-scan -I eth0
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

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

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.