wiki:Linux/Shell/UnmountUsingRegExp

Unmount Using Regular Expression

This is a quick aid to unmounting all --bind mounts in chroot configurations. It solves an issue where scanning a file system for used/free space can end up examining a folder twice or more - which then reports incorrect usage and takes a lot longer.

Set REGEXP to the expression to match.

REGEXP=".* on \(.*chroots.*\) type .*"; \
 mount | while read mountpoint; do \
 mpath=$(expr match "$mountpoint" "$REGEXP"); \
 if [ ! -z "$mpath" ]; then echo "umount $mpath"; sudo umount $mpath; fi; \
done