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 youtube-dl -U
2010-10-02 12:51:46
Functions: sudo
3

If you update youtube-dl from the repos, it becomes out-of-date quickly. Luckily, it can auto-update.

sudo du -sm * | sort -n
2010-09-24 17:56:41
User: wabi
Functions: du sort sudo
0

sudo is optional, but to find out about all files, it is nice, or else run as superuser, ie: su -c 'du -sm * | sort -n'

echo ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
2010-09-21 10:24:42
User: bzaman
Functions: echo sudo tee
3

We sometimes need to change kernel parameters by echoing the file . This needs root privilege and if we do it using sudo like this , it fails

sudo echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

-bash: /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor: Permission denied

We can achieve this with the tee command by just doing sudo without logging as root user

http://www.zaman4linux.in/2010/09/using-tee-to-echo-to-system-file-with.html

sudo nvram boot-args="-v"
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
tr '\000' '\377' < /dev/zero | dd bs=512 count=200000 status=noxfer | pipebench | sudo dd of=/dev/sdx
2010-08-31 15:38:27
User: Gliktch
Functions: dd sudo tr
3

Note: Replace 200000 with drive bytes/512, and /dev/sdx with the destination drive/partition. ;)

Note: You may need to install pipebench, this is easy with "sudo apt-get install pipebench" on Ubuntu.

The reason I hunted around for the pieces to make up this command is that I wanted to specifically flip all of the bits on a new HDD, before running an Extended SMART Self-Test (actually, the second pass, as I've already done one while factory-zeroed) to ensure there are no physical faults waiting to compromise my valuable data. There were several sites that came up in a Google search which had a zero-fill command with progress indicator, and one or two with a fill-with-ones command, but none that I could find with these two things combined (I had to shuffle around the dd command(s) to get this to happen without wasting speed on an md5sum as well).

For reference, these are the other useful-looking commands I found in my search:

Zero-fill drive "/dev/sdx", with progress indicator and md5 verification (run sudo fdisk -l to get total disk bytes, then divide by 512 and enter the resulting value into this command for a full wipe)

dd if=/dev/zero bs=512 count=<size/512> | pipebench | sudo tee /dev/sdx | md5sum

And this command for creating a file filled with ones is my other main source (besides the above command and man pages, that is - I may be a Linux newbie but I do read!):

tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k

Hope someone finds this useful! :)

Cheers,

- Gliktch

sudo mdutil -a -i off
2010-08-26 16:34:20
User: ElAlecs
Functions: sudo
0

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
2

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
0

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
-3

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
-2

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
-8

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
-3

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
-1

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
18

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
-12

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
-3

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
-4

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
1

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
2

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.