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 from sorted by
Terminal - Commands using dd - 138 results
find /dev/ -name random -exec bash -c '[ -r $0 -a -w $0 ] && dd if=$0 | sort | dd of=$0' {} \;
dd if=inputfile of=split3 bs=16m count=32 skip=64
2010-02-21 10:09:46
User: jearsh
Functions: dd
Tags: dd file split
2

bs = buffer size (basically defined the size of a "unit" used by count and skip)

count = the number of buffers to copy (16m * 32 = 1/2 gig)

skip = (32 * 2) we are grabbing piece 3...which means 2 have already been written so skip (2 * count)

i will edit this later if i can to make this all more understandable

dd if=/dev/zero of=/tmp/bigfile bs=1024k count=100
dd if=fromfile of=tofile & DDPID=$! ; sleep 1 ; while kill -USR1 $DDPID ; do sleep 5; done
2010-01-12 15:01:44
User: deltaray
Functions: dd kill sleep
Tags: dd kill while sleep
4

This is a more accurate way to watch the progress of a dd process. The $DDPID=$! is needed so that you don't get the PID of the sleep. The sleep 1 is needed because in my testing at least, if you run kill -USR1 against dd too quickly, it will kill it off instead of display the status. So you need to wait a second, probably so that it can configure itself to trap the USR1 signal.

dd if=/dev/sdc of=/dev/sdd conv=notrunc & while killall -USR1 dd; do sleep 5; done
2010-01-12 14:09:40
User: bw
Functions: dd killall sleep
3

The following command will clone usb stick inside /dev/sdc to /dev/sdd

Double check you got the correct usb sticks (origional-clone)with fdisk -l.

echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done
2009-12-19 19:05:04
User: psykotron
Functions: dd echo tr true
Tags: color
4

A bit different from some of the other submissions. Has bold and uses all c printable characters. Change the bs=value to speed up and increase the sizes of the bold and non-bold strings.

SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234 TARGET: netcat -l -p 1234 | dd of=/dev/mapper/laptop bs=16065b STATS on target: watch -n60 -- kill -USR1 $(pgrep dd)
2009-12-16 10:51:06
User: bw
Functions: dd kill watch
5

I wanted to create a copy of my whole laptop disk on an lvm disk of the same size.

First I created the logical volume: lvcreate -L120G -nlaptop mylvms

SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234

TARGET: nc -l -p 1234 | dd of=/dev/mapper/mylvms-laptop bs=16065b

to follow its process you issue the following command in a different terminal

STATS: on target in a different terminal: watch -n60 -- kill -USR1 $(pgrep dd)

(see http://www.commandlinefu.com/commands/view/4356/output-stats-from-a-running-dd-command-to-see-its-progress)

dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc
2009-12-11 17:34:38
User: nerd65536
Functions: dd tee
Tags: bash tee dd pipe root
21

If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel.

To improve efficiency, specify a larger block size in dd:

dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64k

To image more drives , insert them as additional arguments to tee:

dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde
tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k
2009-12-08 16:05:28
User: azeey
Functions: dd tr
Tags: dd tr
4

This is similar to how you would generate a file with all zeros

dd if=/dev/zero of=allzeros bs=1024 count=2k
dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}')
2009-12-03 15:20:18
User: arcege
Functions: awk dd df
Tags: dd df
-3

For disk space constraint testing. Leaves a little space available for creating temp files, etc. Easily free up the used disk space again by deleting the dummy00 file. Can tailor the testing by building smaller 'blocks' to suit the needs of the testing.

WARNING: do not do this to the '/' (root) filesystem unless you know what you are doing... on some systems it could crash the OS.

dd if=/dev/<device location> | gzip -c /<path to backup location>/<disk image name>.img.gz
dd if=/dev/hda of=file.img
dd if=/dev/zero of=/dev/hda bs=16M
2009-11-09 00:13:35
User: Clopnixus
Functions: dd
-3

If you leave out the block size it defaults to 512 bytes. I set it to 16 Megabytes and it was much faster...

dd if=/dev/zero of=junk bs=1M count=1K
2009-11-01 23:45:51
User: guedesav
Functions: dd
Tags: dd ram rm
-11

This is an useful command for when your OS is reporting less free RAM than it actually has. In case terminated processes did not free their variables correctly, the previously allocated RAM might make a bit sluggis over time.

This command then creates a huge file made out of zeroes and then removes it, thus freeing the amount of memory occupied by the file in the RAM.

In this example, the sequence will free up to 1GB(1M * 1K) of unused RAM. This will not free memory which is genuinely being used by active processes.

ssh user@server 'dd if=sda.img' | dd of=/dev/sda
dd if=/dev/sda | ssh user@server 'dd of=sda.img'
for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo $d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
2009-10-20 01:00:51
User: matthewbauer
Functions: bzip2 date dd echo seq
3

See: http://imgur.com/JgjK2.png for example.

Do some serious benchmarking from the commandline. This will write to a file with the time it took to compress n bytes to the file (increasing by 1).

Run:

gnuplot -persist <(echo "plot 'lzma' with lines, 'gzip' with lines, 'bzip2' with lines")

To see it in graph form.

time dd if=/dev/zero of=TEST bs=4k count=512000
# for i in $(seq 1 25); do dd if=/dev/urandom of=<your disk> bs=1M ; done
2009-09-29 07:12:34
User: danam
Functions: dd seq
Tags: dangerous
2

Intentional hash in the beginning. May run a looong time. Wipes your data for real. Was meant to be /dev/urandom - I mistyped it. :-)

ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
2009-09-11 18:08:36
User: kamathln
Functions: dd ssh
Tags: ssh dvd dump
5

You can use this to directly dump from machine A (with dvd drive) to machine B (without dvd drive) . I used this to copy dvd using my friend's machine to my netbook. Above command is to be issued on machine B.

Advantages :

1) No wasting time dumping first to machine A and then copying to Machine B.

2) You dont need to use space on Machine A. In fact, this will work even when Machine A doesnt have enough hdd space to dump the DVD.

Use -C ssh option on slow networks (enables compression).

you can replace "dd if=/dev/dvd" with any ripping command as long as it spews the iso to stdout.

dd if=/dev/zero of=/dev/fd0 bs=512 count=1
2009-09-09 23:43:22
User: andrew112358
Functions: dd
2

Overwrites the boot sector. Since this doesn't overwrite any data, you can usually recover by re-creating the partition table exactly the same as before you zeroed it. This can also help sometimes if you install a new drive in a Windows machine which can't read it.

dd if=/dev/cdrom of=whatever.iso
2009-09-05 09:19:41
User: 0disse0
Functions: dd
Tags: backup dd iso dvd
7

A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command

sudo dd if=/dev/hda1 of=/dev/hdb2
2009-09-05 09:16:52
User: 0disse0
Functions: dd sudo
5

This command clone the first partition of the primary master IDE drive to the second partition

of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)

echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;}
dd bs=1 seek=2TB if=/dev/null of=ext3.test