Take the 2-minute tour ×

Is there an easy way to determine if a mounted filesystem is mounted as Read-Only or Read-Write? I was thinking just to pipe mount but I thought there might be an easier way.

share|improve this question

5 Answers 5

up vote 6 down vote accepted

If the file system is mounted, I'd cd to a temporary directory and attempt to create a file. The return code will tell you if the file system is Read-Only or Read-Write.

share|improve this answer
If you are just checking to see how a filesytem is mounted, getting the output from mount should be enough. But I have to agree, this is a more exhaustive way to check. There are occasions mount can report that it is mounted read/write, but is actually read-only. A common example of this is a large number of SCSI errors on a device causing it to protect itself by going read-only. Creating a file will verify read+write/read-only without a doubt. –  Alex Oct 22 '10 at 20:33
this would be tidy: touch afile && { rm afile; echo "read-write"; } || echo "read-only" –  glenn jackman Jun 6 '11 at 14:59
The scriptlet as written has a race condition. I would use FILE=mktemp -p /filesystem/of/interest/ instead of just using 'afile' to generate the file and filename. best –  Rik Schneider Jun 6 '11 at 21:22

Old question, but I've came across it looking for same help and seems like found even easier way without the need to create file.

    [ -w /root-rw ] && echo "rw" || echo "ro"
    [ -w /root-ro ] && echo "rw" || echo "ro"

Of course, root-ro is ro mounted fs and root-rw is rw fs.

share|improve this answer
That seems to test filesystem permission, but not mount status. –  Robert Calhoun Oct 29 at 14:13

I just had this issue and these are real pastes ...

Take a look at /proc/mounts -

egrep " ro,|,ro " /proc/mounts 
/dev/sda3 / ext4 ro,seclabel,relatime,barrier=1,data=ordered 0 0    
/dev/sda5 /var ext4 ro,seclabel,relatime,barrier=1,data=ordered 0 0

FYI - These two partitions show as being mounted rw when just using the mount command.

share|improve this answer

This little one-liner will pop-out something if a ro file system exists.

grep "\sro[\s,]" /proc/mounts 

Assuming you don't usually have a ro file system like a CD in the drive, it is sufficient for some basic monitoring type stuff and doesn't require changing the file system to find the current state. It also doesn't assume your file system type. Pipe it into grep -v iso9660 if you want to keep your CDs out of the record.

share|improve this answer

For example, to check if the root partition is in Read-Only mode:

if [[ ! -z `mount | grep "on / type ext3 (ro,"` ]]
   echo "It's in read-only mode"
share|improve this answer
This doesn't catch all cases. /sbin/mount will look at /etc/mtab for the cached version of the currently mounted filesystems (and their current options). If / manages to remount ro for some reason, mtab may not be updated correctly, so / may appear rw still. /proc/mounts should always show the correct value though. –  Travis Campbell Jan 11 '12 at 18:15
I agree with the need to use /proc/mounts. I think this test should be reduced to a shell (bash since the OP asks that) function that makes sure the string being referenced is not a substring of another path. –  Skaperen Aug 17 '12 at 4:46

Your Answer


