Search code examples
ubuntusynchronizationmount

Detecting Mounted Hard Drives in Linux


I have Windows 7 and Ubuntu 10.10 partitions on my hard drive, and have a folder for desktop backgrounds within the Windows partition that I would like to transfer from Windows on Ubuntu's startup. I am relatively new to Linux scripting, so I asked around and rsync sounded like the program to use for the synchronization part.

My question concerns how to find out if my Windows partition is currently mounted, or if automatically mounting it and running my synchronization script afterwards would be better.

In addition, after clicking the 250GB Volume corresponding to the partition in Nautilus, it seems to automatically mount the partition in /media/XXXXXXXX, (the XXXXXXXX being a bunch of alphanumerics, which lead me to believe it is some kind of unique identifier for the hard drive since it is always the same).

I suppose just checking to see if that /media/XXXXXXXX folder is present is a viable solution, but it feels like there is a better way, like making sure that folder corresponds to a device in /dev/ or something along those lines.


Solution

  • You can run just mount to see which devices (e.g. disk partitions) are mounted at which directories. If you want to go farther and check for e.g. mounted NTFS volumes, you could run

    mount | grep ntfs
    

    If you wanted just to test in a bash script whether any NTFS volumes were mounted, you could run e.g.

    if mount | grep -q ntfs ; then
      # an NTFS volume is mounted
    fi
    

    These are examples, but you get the idea. You can read man mount and man grep to learn more.