Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to unmount the last mounted filesystem without doing umount <dev>?

I ask because I'm getting tired of doing mount to get the device when all I could do is just unmount the last filesystem.

share|improve this question

3 Answers 3

Presumably you know the mountpoint, so you can just do umount /mnt/point.

I don't know of an "unmount last filesystem" option, but personally, it sounds a bit risky. You could do something like

fs='/dev/sda1'
mount $fs /mnt/point
.
.
.
umount $fs

If that makes your life any easier.

share|improve this answer

I have never tried this, but you might want to test it. The tune2fs utility gives the last mount time for a file system, if run with the -l flag. You can then write a script to list all the last mount time field for all your mount points and then unmount the latest one.

Partial output from tune2fs

    root@localhost:/# tune2fs -l /dev/sda1  | grep -i time
    Last mount time:          Tue Mar  5 17:40:36 2013
    Last write time:          Mon Feb  4 11:53:20 2013
share|improve this answer

According to the answer to this question, /proc/mounts contains a list of filesystems in mounted order. Therefore you could do

umount `tail -1 /proc/mounts | cut -f2 -d' '`
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.