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 dd

Commands using dd from sorted by
Terminal - Commands using dd - 128 results
:|dd of=./ssss.txt seek=1 bs=$(($(stat -c%s ./ssss.txt)-$(tail -n 2 ./ssss.txt|wc -c)))
2011-10-17 07:53:00
User: ri0day
Functions: dd stat tail wc
0

new way to replace text file with dd,faster than head,sed,awk if you do this with big file

dd if=/dev/cdrom of=~/cd_image.iso
2011-09-24 15:27:04
User: eastwind
Functions: dd
3

create an iso from your cd/dvd-rom device . You need to umount /dev/cdrom

before using the cli

for F in `find ./ -type f`;do SIZE=`ls -s $F | awk -F" " '{print $1}'`; dd if=/dev/urandom of=$F bs=1024 count=$SIZE;done
2011-08-19 18:50:27
User: tduvally
Functions: awk dd
0

This will find any regular file starting with the current directory and use /dev/urandom to overwrite that file. It will is the same size of the file (in blocks) as the file. Can't handle files with spaces or odd characters in the name (who does that anyway?)

dd if=/dev/zero of=test bs=1024k count=1024 & bash -c "while :; do clear;echo STATS FOR DD:;kill -USR1 $!; sleep 1; done"
2011-08-19 01:10:18
User: ideivid
Functions: bash dd
-1

Have you ever wondered what the hell was dd command doing? well, there you have it... notice the -USR1 signal :)...

dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync
2011-08-14 16:37:06
User: marcel
Functions: dd
Tags: disk io vps
2

Especially useful to gauge the performance of a VPS.

dd if=/dev/sda bs=1 count=4 skip=$((0x1b8)) 2>/dev/null | hexdump -n4 -e '"0x%x\n"'
2011-07-30 02:42:32
User: d3Xt3r
Functions: dd hexdump
2

Useful when you want to know the mbrid of a device - for the purpose of making it bootable. Certain hybridiso distros, for eg the OpenSUSE live ISO uses the mbrid to find the live media. Use this command to find out the mbrid of your USB drive and then edit the /grub/mbrid file to match it.

dd bs=1 if=/dev/zero of=/path/to/imagename.raw seek=50G count=1 conv=notrunc
dd of=output.txt if=input.txt ibs=1 skip=$(expr `stat -c%s input.txt` / 2)
dd if=/dev/urandom of=file.img bs=4KB& pid=$!; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 1 && clear; done
2011-06-24 21:49:10
Functions: dd kill sleep
Tags: dd progress
1

Only slightly different than previous commands. The benefit is that your "watch" should die when the dd command has completed. (Of course this would depend on /proc being available)

mem(){ { case $1 in st*|[vgid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf "\r\nquit\r\n";}|nc -n 127.0.0.1 11211; }
2011-06-17 06:39:07
User: argv
Functions: dd printf sed
5

usage: mem memcache-command [arguments]

where memcache-command might be:

set

add

get[s]

append

prepend

replace

delete

incr

decr

cas

stats

verbosity

version

notes:

exptime argument is set to 0 (no expire)

flags argument is set to 1 (arbitrary)

SIZE=`fdisk -s /dev/sdx`; dd if=/dev/sdx bs=1M | pv -s "$SIZE"k > hdd.img
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 |sed '2d;s/^0\+ //;s/ /:/g'
tr '\0' '\377' < /dev/zero|dd count=$((<bytes>/512))
2011-04-05 14:26:02
User: cfy
Functions: dd tr
Tags: dd tr
4

the speed is about 500MB/s on my machine.

i think it's fast enough to output not too many bytes.

while a C program may output 1GB per sencond on my machine.

if the size is not the power of 512,you may change the bs and count in dd.

dd if=/dev/zero of=testfile.seek seek=5242879 bs=1 count=1
2011-04-04 17:56:47
Functions: dd
9

Similar to the original, but is much faster since it only needs to write the last byte as zero. A diff on testfile and testfile.seek will return that they are the same.

dd if=/dev/zero of=testfile bs=1024 count=5000
2011-03-25 09:08:50
User: mpathi
Functions: dd
4

Useful for testing purposes

dd if=FILE | pv -s $(stat FILE | egrep -o "Size: [[:digit:]]*" | egrep -o "[[:digit:]]*") | dd of=OUTPUT
2011-02-09 22:21:06
User: andrepuel
Functions: dd egrep stat
0

Will automatically take the size of the file but longer, usefull only if in an function.

mysqldump -u user -p --all-databases | ssh user@host dd of=/opt/all-databases.dump
dd if=/dev/sda of=/home/sam/MBR.image bs=512 count=1
2011-01-08 11:25:02
User: bbelt16ag
Functions: dd
Tags: dd ddrescue
1

Step#2 Create a copy of the bootload and partition table!

echo <percentage> | sudo dd of=/proc/acpi/video/VGA/LCD/brightness
2011-01-05 03:57:58
User: alperyilmaz
Functions: dd echo sudo
Tags: dd echo
2

An alternative which does not require to be root

dd if=/dev/sdb | pigz | gpg -r <recipient1> -r <recipient2> -e --homedir /home/to/.gnupg | nc remote_machine 6969
2010-12-31 19:24:37
User: brainstorm
Functions: dd gpg
3

Acquires a bit-by-bit data image, gzip-compresses it on multiple cores (pigz) and encrypts the data for multiple recipients (gpg -e -r). It finally sends it off to a remote machine.

dd if=mfsbsd.iso | ssh distant.server dd of=/dev/sda
2010-12-23 09:34:33
User: gormux
Functions: dd ssh
5

Install a basic FreeBSD system on a distant server. I use this to install FreeBSD on servers that can only boot a Linux rescue system. This sytem loads on ram when booted, so it is possible to install freely. You can even install on ZFS root !

dd if=/path/inputfile | pv | dd of=/path/outpufile
dd if=/path/to/inputfile of=/path/to/outputfile & pid=$! && sleep X && while kill -USR1 $pid; do sleep X; done
2010-12-02 15:07:18
User: cyrusza
Functions: dd kill sleep
Tags: dd copy progress
1

Adjust "sleep X" to your needs.

*NOTE: First sleep is required because bash doesn't have a "post-test" syntax (do XXX while).

dd if=/dev/urandom of=/dev/dsp
2010-10-27 09:25:02
User: khashmeshab
Functions: dd
-5

Sends random sounds to your sound card output (e.g. your speaker). Think... You can also run it remotely on another computer using SSH and scare its user!

dd if=/dev/urandom of=/dev/speaker bs=1
2010-10-27 09:22:40
User: khashmeshab
Functions: dd
-5

Sends random beeps to your PC-speaker. Think... You can also run it remotely on another computer using SSH and scare its user! Don't forget to run it on your dedicated hosting server and watch sysadmin's action from data-center's live remote cameras!