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 - 137 results
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!

dd if=/dev/zero of=sparse_file bs=1024 skip=1024 count=1
2010-10-24 00:28:34
User: ubahmapk
Functions: dd
2

If you're trying to create a sparse file, you can use dd by 'skip'ing to the last block instance.

ls -ls shows the actual size vs. the reported size

dd if=/dev/zero of=foo.txt bs=1M count=1
dd if=/dev/sda of=~/backup-disk-YY-MM-DD.img
2010-09-14 11:14:14
Functions: dd
-4

Change /dev/sda with the Disk or partition you want to back-up

To restore use:

dd if=~/backup-disk-YY-MM-DD.img of=/dev/sda

Once again change /dev/sda accordingly

Source: http://www.go2linux.org/linux/2010/09/small-tip-back-disks-clone-hard-disk-773

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

dd [...] p
2010-07-23 23:19:06
User: bartonski
Functions: dd
1

Use this if you're using vi editing mode.

Example use :

sudo vim /root/bin/ ##uh... autocomplete doesn't work... dd sudo ls /root/bin

##ah! that's the name of the file!

<p> sudo vim /root/bin/ ##resume here! Thanks readline!
# dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8
2010-07-02 09:38:19
User: new_user
Functions: dd strings
Tags: BIOS
15

read the memory from C:0000 to F:FFFF

without the need auf dmidecode

dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
2010-06-08 18:49:51
User: atoponce
Functions: dd ssh
Tags: ssh dd
5

The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space.

Of course, change the byte size and count as necessary.

This command also doesn't rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems.

dd if=/dev/zero | pv | dd of=/dev/null
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1|sed '2d;s/0000000 *//;s/ /:/g;s/::*$//'
2010-04-30 16:57:59
User: hckhckhck
Functions: dd od sed
0

Mac OS X needs some clean up. First command works in Linux, Solaris just needs the "0000000"'s removed

2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 | sed '2d;s/^0\+ //;s/ /:/g'
dd
dd if=/dev/nst0 |pv|dd of=restored_file.tar
2010-04-07 09:21:18
User: oernii2
Functions: dd
8

piping through 'pv' shows a simple progress/speed bar for dd. This is a replacement for my otherwise favorite 'while :;do killall -USR1 dd;sleep 1;done'

dd if=file1 of=file2 seek=1 bs=$(stat -c%s file2)
dd bs=1k if=image.nrg of=image.iso skip=300
2010-03-30 22:07:58
User: rpavlick
Functions: dd
Tags: dd iso nero
14

This line removes the 300k header from a Nero image file converting it to ISO format

find /dev/ -name random -exec bash -c '[ -r $0 -a -w $0 ] && dd if=$0 | sort | dd of=$0' {} \;