O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  

Dismount multiple but not all mount points
Hack to dismount multiple mount points (or, with a little hacking, devices) without dismounting needed ones (/proc, etc)

Contributed by:
Donovan Warren
[03/28/03 | Discuss (0) | Link to this hack]

from just about anywhere, in the bash shell, do:

root@venus:~# for i in `mount | grep "regexp" | awk '{ print $3 }'`; do umount $i ; done

for regexp, use any search pattern you like; for example, if you have multiple disks for


etc, use:

root@venus:~# for i in `mount | grep "/usr/[dhlw]" | awk '{ print $3 }'`; do umount $i ; done

This will first pipe the "mount" output through grep, finding only those mount points which match the regexp. awk then prints the 3rd field from each line, and each iteration of the "for" will fill $i with that awk output, in turn. Then, once the "for" finds no more output from mount, it ends.

If you would prefer, you can have it do raw devices (/dev/sdb1, for example) by changing the field that awk prints to $1, and the regexp to something like

grep "/dev/sd[a-z]1"

instead. For example, to dismount /dev/sdb1 thru /dev/sdf1, use

root@venus:~# for i in `mount | grep "/dev/sd[b-f]1" | awk '{ print $1 }'`; do umount $i ; done

Also, it would work to use

df | grep "regexp" | awk '{ print $6 }'
(for mount points) or

df | grep "regexp" | awk '{ print $1 }'
(for device names)

instead of mount | grep | awk

from above.

This avoids using umount -a which dismounts all filesystems not activly in use, including /dev/shm and sometimes /proc

See also: awk manpage

O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.