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 tagged dd from sorted by
Terminal - Commands tagged dd - 60 results
ddrescue -n /dev/old_disk /dev/new_disk rescued.log
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=/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).

sleep 4; xwd >foo.xwd; mv foo.xwd "$(dd skip=100 if=foo.xwd bs=1 count=256 2>/dev/null | egrep -ao '^[[:print:]]+' | tr / :).xwd"
2010-09-19 08:03:02
User: hackerb9
Functions: mv sleep
3

In general, this is actually not better than the "scrot -d4" command I'm listing it as an alternative to, so please don't vote it down for that. I'm adding this command because xwd (X window dumper) comes with X11, so it is already installed on your machine, whereas scrot probably is not. I've found xwd handy on boxen that I don't want to (or am not allowed to) install packages on.

NOTE: The dd junk for renaming the file is completely optional. I just did that for fun and because it's interesting that xwd embeds the window title in its metadata. I probably should have just parsed the output from file(1) instead of cutting it out with dd(1), but this was more fun and less error prone.

NOTE2: Many programs don't know what to do with an xwd format image file. You can convert it to something normal using NetPBM's xwdtopnm(1) or ImageMagick's convert(1). For example, this would work: "xwd | convert fd:0 foo.jpg". Of course, if you have ImageMagick already installed, you'd probably use import(1) instead of xwd.

NOTE3: Xwd files can be viewed using the X Window UnDumper: "xwud <foo.xwd". ImageMagick and The GIMP can also read .xwd files. Strangely, eog(1) cannot.

NOTE4: The sleep is not strictly necessary, I put it in there so that one has time to raise the window above any others before clicking on it.

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.

dcfldd if=/dev/zero of=/dev/null
2010-05-14 17:37:03
User: twjolson
Tags: dd kill pkill
1

dcfldd is a forensic version of dd that shows a process indicator by default.

dd if=/dev/zero | pv | dd of=/dev/null
pkill -USR1 ^dd$
2010-05-14 16:25:01
User: atoponce
Tags: dd kill pkill
3

The 'dd' command doesn't provide a progress when writing data. So, sending the "USR1" signal to the process will spit out its progress as it writes data. This command is superior to others on the site, as it doesn't require you to previously know the PID of the dd command.

killall -INFO dd
2010-04-22 18:38:37
User: jearsh
Functions: killall
Tags: dd progress
14

"killall -USR1 dd" does not work in OS X for me. However, sending INFO instead of USR1 works.

while :;do killall -USR1 dd;sleep 1;done
2010-04-07 09:23:31
User: oernii2
Functions: killall
Tags: dd progress speed
9

every 1sec sends DD the USR1 signal which causes DD to print its progress.

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

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
dc3dd progress=on bs=512 count=2048 if=/dev/zero of=/dev/null
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/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
tail $0 >> $0
2009-12-07 12:33:41
User: yooreck
Functions: tail
Tags: dd df
1

Put into some file. No special purpouse, just for fun...

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.

sync; time `dd if=/dev/cciss/c0d1p1 of=/dev/null bs=1M count=10240`
sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync`
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.

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 !!!)