Shell script to know whether a filesystem is already mounted












16















I have a tmpfs file system mounted on a particular directory. I want to write a shell script to check whether the tmpfs filesystem is already mounted on the directory.










share|improve this question





























    16















    I have a tmpfs file system mounted on a particular directory. I want to write a shell script to check whether the tmpfs filesystem is already mounted on the directory.










    share|improve this question



























      16












      16








      16


      2






      I have a tmpfs file system mounted on a particular directory. I want to write a shell script to check whether the tmpfs filesystem is already mounted on the directory.










      share|improve this question
















      I have a tmpfs file system mounted on a particular directory. I want to write a shell script to check whether the tmpfs filesystem is already mounted on the directory.







      shell filesystems mount






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 17 '12 at 18:13









      Magellan

      1139




      1139










      asked Nov 18 '10 at 7:25









      nitin_cheriannitin_cherian

      2,7881456109




      2,7881456109
























          8 Answers
          8






          active

          oldest

          votes


















          4














          You can check the type of the filesystem.




          $ stat -f -c '%T' /
          xfs
          $ stat -f -c '%T' /dev/shm
          tmpfs


          You could also check whether a directory is a mountpoint by comparing its device with its parent's.




          $ stat -c '%D' /
          901
          $ stat -c '%D' /home
          fe01
          $ stat -c '%D' /home/$USER
          fe01





          share|improve this answer































            40














            There's a tool specifically for this: mountpoint(1)



            if mountpoint -q "$directory" ; then
            echo it is a mounted mountpoint
            else
            echo it is not a mounted mountpoint
            fi


            And you don't even have to scrape strings to do it!



            Note that I find this tool in Debian's initscripts package. How available it is elsewhere is not something I can comment on.






            share|improve this answer





















            • 1





              I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

              – cvolny
              May 27 '13 at 22:38








            • 2





              @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

              – Sorpigal
              May 29 '13 at 14:30













            • Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

              – Cody S
              Apr 17 '15 at 17:09





















            2














            Something like this, while hackish, should do the trick:



            FS_TO_CHECK="/dev" # For example... change this to suit your needs.

            if cat /proc/mounts | grep -F " $FS_TO_CHECK " > /dev/null; then
            # Filesystem is mounted
            else
            # Filesystem is not mounted
            fi





            share|improve this answer
























            • True enough ...

              – cdhowie
              Nov 18 '10 at 21:07



















            2














            I know this thread is old, but why not just use df and grep for the required path to the mountpoint? i.e. like this:



            df /full/path | grep -q /full/path


            grep returns true if mounted, false if not. So we just need to test it like this:



            df /mnt/myUSBdisk | grep -q /mnt/myUSBdisk && echo "Mounted" || echo "Not mounted"


            Easy peasy...






            share|improve this answer
























            • I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

              – Colin Keenan
              Oct 1 '14 at 3:58





















            1














            You could use df, try man df.



            df 'directory' | awk '{print $1, $6}'


            will give you sth like:



            Filesystem Mounted
            /dev/sda5 'some_dir'


            you can then add a check if the directory 'some_dir' is same as 'your_dir', and filesystem is same as yours.






            share|improve this answer

































              0














              Check /proc/mounts. If you grep on the filesystem name and the path you want it mounted (maybe even a specific line with all options included) you can tell if the filesystem is mounted.



              if [ "`grep "tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0" /proc/mounts`" != "" ]
              then
              echo Mounted.
              else
              echo Not mounted.
              fi





              share|improve this answer
























              • A virtual -1 for using backticks in a non-trivial location.

                – Sorpigal
                Nov 18 '10 at 19:13











              • if grep ... - no need for brackets either.

                – Dennis Williamson
                Nov 18 '10 at 21:06



















              0














              if mount -l -t tmpfs | grep "on $directory "
              then
              echo "it's mounted"
              fi





              share|improve this answer































                -2














                mountpoint is much more elegant and is in sysvinit-tools CentOS 6+++






                share|improve this answer
























                • This low-quality answer duplicates an existing answer with more details from 2010

                  – tripleee
                  Nov 20 '18 at 9:46











                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4212522%2fshell-script-to-know-whether-a-filesystem-is-already-mounted%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                8 Answers
                8






                active

                oldest

                votes








                8 Answers
                8






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4














                You can check the type of the filesystem.




                $ stat -f -c '%T' /
                xfs
                $ stat -f -c '%T' /dev/shm
                tmpfs


                You could also check whether a directory is a mountpoint by comparing its device with its parent's.




                $ stat -c '%D' /
                901
                $ stat -c '%D' /home
                fe01
                $ stat -c '%D' /home/$USER
                fe01





                share|improve this answer




























                  4














                  You can check the type of the filesystem.




                  $ stat -f -c '%T' /
                  xfs
                  $ stat -f -c '%T' /dev/shm
                  tmpfs


                  You could also check whether a directory is a mountpoint by comparing its device with its parent's.




                  $ stat -c '%D' /
                  901
                  $ stat -c '%D' /home
                  fe01
                  $ stat -c '%D' /home/$USER
                  fe01





                  share|improve this answer


























                    4












                    4








                    4







                    You can check the type of the filesystem.




                    $ stat -f -c '%T' /
                    xfs
                    $ stat -f -c '%T' /dev/shm
                    tmpfs


                    You could also check whether a directory is a mountpoint by comparing its device with its parent's.




                    $ stat -c '%D' /
                    901
                    $ stat -c '%D' /home
                    fe01
                    $ stat -c '%D' /home/$USER
                    fe01





                    share|improve this answer













                    You can check the type of the filesystem.




                    $ stat -f -c '%T' /
                    xfs
                    $ stat -f -c '%T' /dev/shm
                    tmpfs


                    You could also check whether a directory is a mountpoint by comparing its device with its parent's.




                    $ stat -c '%D' /
                    901
                    $ stat -c '%D' /home
                    fe01
                    $ stat -c '%D' /home/$USER
                    fe01






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 19 '10 at 2:46









                    ephemientephemient

                    154k31228352




                    154k31228352

























                        40














                        There's a tool specifically for this: mountpoint(1)



                        if mountpoint -q "$directory" ; then
                        echo it is a mounted mountpoint
                        else
                        echo it is not a mounted mountpoint
                        fi


                        And you don't even have to scrape strings to do it!



                        Note that I find this tool in Debian's initscripts package. How available it is elsewhere is not something I can comment on.






                        share|improve this answer





















                        • 1





                          I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

                          – cvolny
                          May 27 '13 at 22:38








                        • 2





                          @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

                          – Sorpigal
                          May 29 '13 at 14:30













                        • Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

                          – Cody S
                          Apr 17 '15 at 17:09


















                        40














                        There's a tool specifically for this: mountpoint(1)



                        if mountpoint -q "$directory" ; then
                        echo it is a mounted mountpoint
                        else
                        echo it is not a mounted mountpoint
                        fi


                        And you don't even have to scrape strings to do it!



                        Note that I find this tool in Debian's initscripts package. How available it is elsewhere is not something I can comment on.






                        share|improve this answer





















                        • 1





                          I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

                          – cvolny
                          May 27 '13 at 22:38








                        • 2





                          @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

                          – Sorpigal
                          May 29 '13 at 14:30













                        • Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

                          – Cody S
                          Apr 17 '15 at 17:09
















                        40












                        40








                        40







                        There's a tool specifically for this: mountpoint(1)



                        if mountpoint -q "$directory" ; then
                        echo it is a mounted mountpoint
                        else
                        echo it is not a mounted mountpoint
                        fi


                        And you don't even have to scrape strings to do it!



                        Note that I find this tool in Debian's initscripts package. How available it is elsewhere is not something I can comment on.






                        share|improve this answer















                        There's a tool specifically for this: mountpoint(1)



                        if mountpoint -q "$directory" ; then
                        echo it is a mounted mountpoint
                        else
                        echo it is not a mounted mountpoint
                        fi


                        And you don't even have to scrape strings to do it!



                        Note that I find this tool in Debian's initscripts package. How available it is elsewhere is not something I can comment on.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 19 '10 at 13:25

























                        answered Nov 18 '10 at 19:11









                        SorpigalSorpigal

                        19.7k44869




                        19.7k44869








                        • 1





                          I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

                          – cvolny
                          May 27 '13 at 22:38








                        • 2





                          @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

                          – Sorpigal
                          May 29 '13 at 14:30













                        • Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

                          – Cody S
                          Apr 17 '15 at 17:09
















                        • 1





                          I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

                          – cvolny
                          May 27 '13 at 22:38








                        • 2





                          @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

                          – Sorpigal
                          May 29 '13 at 14:30













                        • Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

                          – Cody S
                          Apr 17 '15 at 17:09










                        1




                        1





                        I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

                        – cvolny
                        May 27 '13 at 22:38







                        I see that mountpoint is part of the Gentoo Linux sys-apps/util-linux package along with more, mount, umount, dmesg, and a bunch of other system tools. I would say this is the cleanest solution.

                        – cvolny
                        May 27 '13 at 22:38






                        2




                        2





                        @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

                        – Sorpigal
                        May 29 '13 at 14:30







                        @cvolny: It turns out that mountpoint is part of util-linux (specifically the sys-utils part) and is probably available one way or another in most Linux distributions. It is, however, not part of GNU and not likely available on non-Linux systems.

                        – Sorpigal
                        May 29 '13 at 14:30















                        Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

                        – Cody S
                        Apr 17 '15 at 17:09







                        Looks like it comes stock with RHEL 7.1 (err. ok, I have installed some stuff on here. So I can't be certain of that)

                        – Cody S
                        Apr 17 '15 at 17:09













                        2














                        Something like this, while hackish, should do the trick:



                        FS_TO_CHECK="/dev" # For example... change this to suit your needs.

                        if cat /proc/mounts | grep -F " $FS_TO_CHECK " > /dev/null; then
                        # Filesystem is mounted
                        else
                        # Filesystem is not mounted
                        fi





                        share|improve this answer
























                        • True enough ...

                          – cdhowie
                          Nov 18 '10 at 21:07
















                        2














                        Something like this, while hackish, should do the trick:



                        FS_TO_CHECK="/dev" # For example... change this to suit your needs.

                        if cat /proc/mounts | grep -F " $FS_TO_CHECK " > /dev/null; then
                        # Filesystem is mounted
                        else
                        # Filesystem is not mounted
                        fi





                        share|improve this answer
























                        • True enough ...

                          – cdhowie
                          Nov 18 '10 at 21:07














                        2












                        2








                        2







                        Something like this, while hackish, should do the trick:



                        FS_TO_CHECK="/dev" # For example... change this to suit your needs.

                        if cat /proc/mounts | grep -F " $FS_TO_CHECK " > /dev/null; then
                        # Filesystem is mounted
                        else
                        # Filesystem is not mounted
                        fi





                        share|improve this answer













                        Something like this, while hackish, should do the trick:



                        FS_TO_CHECK="/dev" # For example... change this to suit your needs.

                        if cat /proc/mounts | grep -F " $FS_TO_CHECK " > /dev/null; then
                        # Filesystem is mounted
                        else
                        # Filesystem is not mounted
                        fi






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 18 '10 at 7:34









                        cdhowiecdhowie

                        110k15215237




                        110k15215237













                        • True enough ...

                          – cdhowie
                          Nov 18 '10 at 21:07



















                        • True enough ...

                          – cdhowie
                          Nov 18 '10 at 21:07

















                        True enough ...

                        – cdhowie
                        Nov 18 '10 at 21:07





                        True enough ...

                        – cdhowie
                        Nov 18 '10 at 21:07











                        2














                        I know this thread is old, but why not just use df and grep for the required path to the mountpoint? i.e. like this:



                        df /full/path | grep -q /full/path


                        grep returns true if mounted, false if not. So we just need to test it like this:



                        df /mnt/myUSBdisk | grep -q /mnt/myUSBdisk && echo "Mounted" || echo "Not mounted"


                        Easy peasy...






                        share|improve this answer
























                        • I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

                          – Colin Keenan
                          Oct 1 '14 at 3:58


















                        2














                        I know this thread is old, but why not just use df and grep for the required path to the mountpoint? i.e. like this:



                        df /full/path | grep -q /full/path


                        grep returns true if mounted, false if not. So we just need to test it like this:



                        df /mnt/myUSBdisk | grep -q /mnt/myUSBdisk && echo "Mounted" || echo "Not mounted"


                        Easy peasy...






                        share|improve this answer
























                        • I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

                          – Colin Keenan
                          Oct 1 '14 at 3:58
















                        2












                        2








                        2







                        I know this thread is old, but why not just use df and grep for the required path to the mountpoint? i.e. like this:



                        df /full/path | grep -q /full/path


                        grep returns true if mounted, false if not. So we just need to test it like this:



                        df /mnt/myUSBdisk | grep -q /mnt/myUSBdisk && echo "Mounted" || echo "Not mounted"


                        Easy peasy...






                        share|improve this answer













                        I know this thread is old, but why not just use df and grep for the required path to the mountpoint? i.e. like this:



                        df /full/path | grep -q /full/path


                        grep returns true if mounted, false if not. So we just need to test it like this:



                        df /mnt/myUSBdisk | grep -q /mnt/myUSBdisk && echo "Mounted" || echo "Not mounted"


                        Easy peasy...







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jul 21 '13 at 16:20









                        Scooby-2Scooby-2

                        1214




                        1214













                        • I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

                          – Colin Keenan
                          Oct 1 '14 at 3:58





















                        • I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

                          – Colin Keenan
                          Oct 1 '14 at 3:58



















                        I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

                        – Colin Keenan
                        Oct 1 '14 at 3:58







                        I decided to up-vote this one because although mountpoint would be easier for the question asked, this answer is more flexible. For example, some linux distros mount shared memory tmpfs at /tmp while others use /dev/shm or both. This answer makes it easy to realize you could tell if /tmp is shared memory or not the same way: df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory Or, more to the point df /tmp | grep -q tmpfs && tmp=/tmp || tmp=/dev/shm

                        – Colin Keenan
                        Oct 1 '14 at 3:58













                        1














                        You could use df, try man df.



                        df 'directory' | awk '{print $1, $6}'


                        will give you sth like:



                        Filesystem Mounted
                        /dev/sda5 'some_dir'


                        you can then add a check if the directory 'some_dir' is same as 'your_dir', and filesystem is same as yours.






                        share|improve this answer






























                          1














                          You could use df, try man df.



                          df 'directory' | awk '{print $1, $6}'


                          will give you sth like:



                          Filesystem Mounted
                          /dev/sda5 'some_dir'


                          you can then add a check if the directory 'some_dir' is same as 'your_dir', and filesystem is same as yours.






                          share|improve this answer




























                            1












                            1








                            1







                            You could use df, try man df.



                            df 'directory' | awk '{print $1, $6}'


                            will give you sth like:



                            Filesystem Mounted
                            /dev/sda5 'some_dir'


                            you can then add a check if the directory 'some_dir' is same as 'your_dir', and filesystem is same as yours.






                            share|improve this answer















                            You could use df, try man df.



                            df 'directory' | awk '{print $1, $6}'


                            will give you sth like:



                            Filesystem Mounted
                            /dev/sda5 'some_dir'


                            you can then add a check if the directory 'some_dir' is same as 'your_dir', and filesystem is same as yours.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 18 '10 at 7:39

























                            answered Nov 18 '10 at 7:33









                            sud03rsud03r

                            11.2k146789




                            11.2k146789























                                0














                                Check /proc/mounts. If you grep on the filesystem name and the path you want it mounted (maybe even a specific line with all options included) you can tell if the filesystem is mounted.



                                if [ "`grep "tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0" /proc/mounts`" != "" ]
                                then
                                echo Mounted.
                                else
                                echo Not mounted.
                                fi





                                share|improve this answer
























                                • A virtual -1 for using backticks in a non-trivial location.

                                  – Sorpigal
                                  Nov 18 '10 at 19:13











                                • if grep ... - no need for brackets either.

                                  – Dennis Williamson
                                  Nov 18 '10 at 21:06
















                                0














                                Check /proc/mounts. If you grep on the filesystem name and the path you want it mounted (maybe even a specific line with all options included) you can tell if the filesystem is mounted.



                                if [ "`grep "tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0" /proc/mounts`" != "" ]
                                then
                                echo Mounted.
                                else
                                echo Not mounted.
                                fi





                                share|improve this answer
























                                • A virtual -1 for using backticks in a non-trivial location.

                                  – Sorpigal
                                  Nov 18 '10 at 19:13











                                • if grep ... - no need for brackets either.

                                  – Dennis Williamson
                                  Nov 18 '10 at 21:06














                                0












                                0








                                0







                                Check /proc/mounts. If you grep on the filesystem name and the path you want it mounted (maybe even a specific line with all options included) you can tell if the filesystem is mounted.



                                if [ "`grep "tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0" /proc/mounts`" != "" ]
                                then
                                echo Mounted.
                                else
                                echo Not mounted.
                                fi





                                share|improve this answer













                                Check /proc/mounts. If you grep on the filesystem name and the path you want it mounted (maybe even a specific line with all options included) you can tell if the filesystem is mounted.



                                if [ "`grep "tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0" /proc/mounts`" != "" ]
                                then
                                echo Mounted.
                                else
                                echo Not mounted.
                                fi






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Nov 18 '10 at 7:34









                                Martin SchapendonkMartin Schapendonk

                                8,78431324




                                8,78431324













                                • A virtual -1 for using backticks in a non-trivial location.

                                  – Sorpigal
                                  Nov 18 '10 at 19:13











                                • if grep ... - no need for brackets either.

                                  – Dennis Williamson
                                  Nov 18 '10 at 21:06



















                                • A virtual -1 for using backticks in a non-trivial location.

                                  – Sorpigal
                                  Nov 18 '10 at 19:13











                                • if grep ... - no need for brackets either.

                                  – Dennis Williamson
                                  Nov 18 '10 at 21:06

















                                A virtual -1 for using backticks in a non-trivial location.

                                – Sorpigal
                                Nov 18 '10 at 19:13





                                A virtual -1 for using backticks in a non-trivial location.

                                – Sorpigal
                                Nov 18 '10 at 19:13













                                if grep ... - no need for brackets either.

                                – Dennis Williamson
                                Nov 18 '10 at 21:06





                                if grep ... - no need for brackets either.

                                – Dennis Williamson
                                Nov 18 '10 at 21:06











                                0














                                if mount -l -t tmpfs | grep "on $directory "
                                then
                                echo "it's mounted"
                                fi





                                share|improve this answer




























                                  0














                                  if mount -l -t tmpfs | grep "on $directory "
                                  then
                                  echo "it's mounted"
                                  fi





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    if mount -l -t tmpfs | grep "on $directory "
                                    then
                                    echo "it's mounted"
                                    fi





                                    share|improve this answer













                                    if mount -l -t tmpfs | grep "on $directory "
                                    then
                                    echo "it's mounted"
                                    fi






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 18 '10 at 21:15









                                    Dennis WilliamsonDennis Williamson

                                    240k63307375




                                    240k63307375























                                        -2














                                        mountpoint is much more elegant and is in sysvinit-tools CentOS 6+++






                                        share|improve this answer
























                                        • This low-quality answer duplicates an existing answer with more details from 2010

                                          – tripleee
                                          Nov 20 '18 at 9:46
















                                        -2














                                        mountpoint is much more elegant and is in sysvinit-tools CentOS 6+++






                                        share|improve this answer
























                                        • This low-quality answer duplicates an existing answer with more details from 2010

                                          – tripleee
                                          Nov 20 '18 at 9:46














                                        -2












                                        -2








                                        -2







                                        mountpoint is much more elegant and is in sysvinit-tools CentOS 6+++






                                        share|improve this answer













                                        mountpoint is much more elegant and is in sysvinit-tools CentOS 6+++







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jul 26 '16 at 16:54









                                        ChuckChuck

                                        1




                                        1













                                        • This low-quality answer duplicates an existing answer with more details from 2010

                                          – tripleee
                                          Nov 20 '18 at 9:46



















                                        • This low-quality answer duplicates an existing answer with more details from 2010

                                          – tripleee
                                          Nov 20 '18 at 9:46

















                                        This low-quality answer duplicates an existing answer with more details from 2010

                                        – tripleee
                                        Nov 20 '18 at 9:46





                                        This low-quality answer duplicates an existing answer with more details from 2010

                                        – tripleee
                                        Nov 20 '18 at 9:46


















                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4212522%2fshell-script-to-know-whether-a-filesystem-is-already-mounted%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                        ComboBox Display Member on multiple fields

                                        Is it possible to collect Nectar points via Trainline?