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 partition from sorted by
Terminal - Commands tagged partition - 22 results
lsblk | grep <mountpoint>
mount -o sb=98304 /dev/sda5 /mnt/data5
sudo dumpe2fs /dev/sda1 | grep superblock
fsarchvier probe simple
diskutil list
ls /dev/disk* | xargs -n 1 -t sudo zdb -l | grep GPTE_
2012-10-06 20:19:45
User: grahamperrin
Functions: grep ls sudo xargs
1

Show the UUID-based alternate device names of ZEVO-related partitions on Darwin/OS X. Adapted from the lines by dbrady at http://zevo.getgreenbytes.com/forum/viewtopic.php?p=700#p700 and following the disk device naming scheme at http://zevo.getgreenbytes.com/wiki/pmwiki.php?n=Site.DiskDeviceNames

lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,MODEL,MOUNTPOINT
2012-09-12 15:30:25
User: BasketCase
2

Shows all block devices in a tree with descruptions of what they are.

blkid -c /dev/null
2012-09-12 13:34:41
User: mhs
2

`blkid` is an interface to libuuid - it can read Device Mapper, EVMS, LVM, MD, and regular block devices.

-c /dev/null - Do not use cached output from /etc/blkid.tab or /etc/blkid/blkid.tab (RHEL)

-i - Display I/O Limits (aka I/O topology) information (not available in RHEL)

-p - Low-level superblock probing mode (not available in RHEL)

parted /dev/sda print
2012-06-05 09:11:06
User: mesuutt
4

See size of partitions as human readable and get extra informations about hdd and partitions

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
1

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 "0,,L" | sfdisk /dev/sdX
2012-04-09 18:36:24
User: twobitsprite
Functions: echo
0

Creates a single primary partition starting at sector 0 and extending to the end of the disk. Use with care.

losetup /dev/loop0 harddrive.img; kpartx -a -v /dev/loop0; mount /dev/mapper/loop0p1 /mountpoint/
mount -o remount,ro /dev/foo /
2010-10-30 03:51:53
User: vlan7
Functions: mount
1

Necessary for fsck for example.

The remount functionality follows the standard way how the mount command works with options from fstab. It means the mount command doesn't read fstab (or mtab) only when a device and dir are fully specified. After this call all old mount options are replaced and arbitrary stuff from fstab is ignored, except the loop= option which is internally generated and maintained by the mount command.

It does not change device or mount point.

blkid /dev/sda7
2010-09-05 12:20:45
User: lineak
Tags: partition uuid
7

Shows the UUID of the given partition (here /dev/sda7). Doesn't need to be root.

sudo foremost -i /dev/sda -o /recovery
2010-08-19 22:27:41
User: vlan7
Functions: sudo
2

The above command assumes the lost data is on /dev/sda and you previously issued the following command to mount _another_ disk or partition (/dev/sdb1) on /recovery

sudo mount /dev/sdb1 /recovery

If you don't do this, the data could be overwrited!

foremost is a very powerful carving tool. By default foremost recovers all known file types. If you want to reduce the amount of files that are recovered you can specify the file type you are looking for. Read the man page to know the available file types.

i.e to recover JPEG pictures append to foremost the switch -tjpg

df -l | grep -e "9.%" -e "100%"
2010-04-26 17:57:54
User: dooblem
Functions: df grep
2

Reports all local partitions having more than 90% usage.

Just add it in a crontab and you'll get a mail when a disk is full.

(sending mail to the root user must work for that)

sfdisk -d /dev/sda | sfdisk /dev/sdb
sfdisk -d /dev/sda | sed 's/sda/sdb/g' | sfdisk /dev/sdb
sfdisk /dev/sdb <(sfdisk -d /dev/sda| perl -pi -e 's/sda/sdb/g')
2009-12-22 22:45:41
Functions: perl
-3

*as long as the drives are exactly the same* then this command copies the partition table on /dev/sda to /dev/sdb

lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
4

Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.

hwinfo --block --short
2009-04-24 11:13:31
13

Yields entries in the form of "/dev/hda1" etc.

Use this if you are on a new system and don't know how the storage hardware (ide, sata, scsi, usb - with ever changing descriptors) is connected and which partitions are available.

Far better than using "fdisk -l" on guessed device descriptors.

INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
6

Suppose you made a backup of your hard disk with dd:

dd if=/dev/sda of=/mnt/disk/backup.img

This command enables you to mount a partition from inside this image, so you can access your files directly.

Substitute PARTITION=1 with the number of the partition you want to mount (returned from sfdisk -d yourfile.img).