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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using fdisk from sorted by
Terminal - Commands using fdisk - 9 results
for x in {a..d}; do echo -e "n\np\n\n\n\nt\n8e\nw\n" | fdisk /dev/sd"$x"; done
2015-05-21 12:59:48
User: jaimerosario
Functions: echo fdisk
Tags: fdisk for loop

So, I'm using a CentOS VM in VirtualBox, and created four new disks in the SCSI controller.

The VM created the folders:





Using a 'for loop' all disks are partitioned for LVM.

fdisk -l
fdisk -l /dev/sda
fdisk -l /dev/sda | grep -E sda[0-9]+ | sed s/*// | awk '{printf ("%s %f ",$1,$2/512); if($2%512){ print "BAD" }else {print "Good"} }' | column -t
2012-05-18 08:34:36
Functions: awk column fdisk grep sed

To get most of you HDD/SSD driver you need to make sure you partition are aligned, if not the speed penalty can be up to 50% slower!

this simple one liner will check to see if each partition start sector is divided by 512

you need to change sda with your driver

if you find the one of your partitions is not aligned use gparted to move the start sector of the partition to be divided of 512

echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/sdX
echo "w" | fdisk /dev/sdb
2010-09-07 13:42:59
User: BCK
Functions: echo fdisk

Used this after cloning a disk with dd to make the newly written partitions show up in /dev/

echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk /dev/sdX
2009-10-20 16:21:54
User: sud0er
Functions: echo fdisk
Tags: Linux fdisk

This is a bit hacky, but if you're setting up a bunch of new LUNs, it can save a bunch of time. Also check out sfdisk. The fdisk will fail if, for example, a partition table already exists.

fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g"
expr $(fdisk -s ` grep ' / ' /etc/mtab |cut -d " " -f1`) / 1024