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
dd if=/dev/urandom of=file.img bs=4KB& sleep 1 && pid=`pidof dd`; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 10 && clear; done
2012-02-23 01:45:53
Functions: dd kill sleep
1

The previously-posted one-liner didn't work for me for whatever reason, so I ended up doing this instead.

dd if=/dev/disk1 of=disk1.iso
2012-02-06 13:58:15
User: DevEd
Functions: dd
0

This command dumps a mounted disk to an ISO image. (Use "mount" to get the mounted disk's name.)

Make sure to un-mount the disk first.

pv -petrs $(stat -c %s file.iso) file.iso | dd bs=1M oflag=sync of=/dev/sdX
time (pv file.iso | dd bs=1M oflag=sync of=/dev/sdX 2>/dev/null)
dd if=<device> | pv | nc <target> <port>
2012-01-27 18:37:36
Functions: dd
Tags: dd nc pv 7z
8

Create an image of "device" and send it to another machine through the network ("target" and "port" sets the ip and port the stream will be sent to), outputting a progress bar

On the machine that will receive, compress and store the file, use:

nc -l -p <port> | 7z a <filename> -si -m0=lzma2 -mx=9 -ms=on

Optionally, add the -v4g switch at the end of the line in order to split the file every 4 gigabytes (or set another size: accepted suffixes are k, m and g).

The file will be compressed using 7z format, lzma2 algorithm, with maximum compression level and solid file activated.

The compression stage will be executed on the machine which will store the image. It was planned this way because the processor on that machine was faster, and being on a gigabit network, transfering the uncompressed image wasn't much of a problem.

dd if=/dev/urandom of=/dev/somedisk
2012-01-24 09:13:15
User: joedhon
Functions: dd
-5

Same game as #10096 . loop as many times as you like.

dd if=/dev/zero of=/dev/hda
dd if=/dev/zero of=filename.file bs=1024 count=10240
2012-01-19 08:38:14
User: harpo
Functions: dd
-2

Command to create a dummy file (full of nulls). Useful for testing e.g. file transfers when no file is at hand.

bs = blocksize, count = filesize in kilobytes

sudo dd if=/dev/block/device bs=1MB | pv -s `sudo blockdev --getsize64 /dev/block/device' | gzip -9 > output.img.gz
:|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
2

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
10

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
1

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