mount info for current directory











up vote
12
down vote

favorite
2












I can do df . to get some of the info on the mount that the current directory is in, and I can get all the info I want from mount, but get to much info (info about other mounts). I can grep it down, but am wondering if there is a better way.



Is there some command mountinfo such that mountinfo . gives info I want (like df ., but with the info that mount gives.)





I am using Debian Gnu+Linux.










share|improve this question




















  • 1




    I believe stat command can be used as well. However, I am not sure if %m option which gives the mount point is supported in your version of system. I checked in my system and it seemed to not return the mount point.
    – Ramesh
    Aug 14 '14 at 2:33






  • 1




    @Ramesh, Yes stat "--printf=%mn" . gets the mount-point of the file-system that the current directory is in. Thus allowing us to simplify some of the answers. Thanks.
    – ctrl-alt-delor
    Aug 14 '14 at 11:29















up vote
12
down vote

favorite
2












I can do df . to get some of the info on the mount that the current directory is in, and I can get all the info I want from mount, but get to much info (info about other mounts). I can grep it down, but am wondering if there is a better way.



Is there some command mountinfo such that mountinfo . gives info I want (like df ., but with the info that mount gives.)





I am using Debian Gnu+Linux.










share|improve this question




















  • 1




    I believe stat command can be used as well. However, I am not sure if %m option which gives the mount point is supported in your version of system. I checked in my system and it seemed to not return the mount point.
    – Ramesh
    Aug 14 '14 at 2:33






  • 1




    @Ramesh, Yes stat "--printf=%mn" . gets the mount-point of the file-system that the current directory is in. Thus allowing us to simplify some of the answers. Thanks.
    – ctrl-alt-delor
    Aug 14 '14 at 11:29













up vote
12
down vote

favorite
2









up vote
12
down vote

favorite
2






2





I can do df . to get some of the info on the mount that the current directory is in, and I can get all the info I want from mount, but get to much info (info about other mounts). I can grep it down, but am wondering if there is a better way.



Is there some command mountinfo such that mountinfo . gives info I want (like df ., but with the info that mount gives.)





I am using Debian Gnu+Linux.










share|improve this question















I can do df . to get some of the info on the mount that the current directory is in, and I can get all the info I want from mount, but get to much info (info about other mounts). I can grep it down, but am wondering if there is a better way.



Is there some command mountinfo such that mountinfo . gives info I want (like df ., but with the info that mount gives.)





I am using Debian Gnu+Linux.







filesystems mount disk-usage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 23:34

























asked Aug 11 '14 at 11:51









ctrl-alt-delor

10.2k41955




10.2k41955








  • 1




    I believe stat command can be used as well. However, I am not sure if %m option which gives the mount point is supported in your version of system. I checked in my system and it seemed to not return the mount point.
    – Ramesh
    Aug 14 '14 at 2:33






  • 1




    @Ramesh, Yes stat "--printf=%mn" . gets the mount-point of the file-system that the current directory is in. Thus allowing us to simplify some of the answers. Thanks.
    – ctrl-alt-delor
    Aug 14 '14 at 11:29














  • 1




    I believe stat command can be used as well. However, I am not sure if %m option which gives the mount point is supported in your version of system. I checked in my system and it seemed to not return the mount point.
    – Ramesh
    Aug 14 '14 at 2:33






  • 1




    @Ramesh, Yes stat "--printf=%mn" . gets the mount-point of the file-system that the current directory is in. Thus allowing us to simplify some of the answers. Thanks.
    – ctrl-alt-delor
    Aug 14 '14 at 11:29








1




1




I believe stat command can be used as well. However, I am not sure if %m option which gives the mount point is supported in your version of system. I checked in my system and it seemed to not return the mount point.
– Ramesh
Aug 14 '14 at 2:33




I believe stat command can be used as well. However, I am not sure if %m option which gives the mount point is supported in your version of system. I checked in my system and it seemed to not return the mount point.
– Ramesh
Aug 14 '14 at 2:33




1




1




@Ramesh, Yes stat "--printf=%mn" . gets the mount-point of the file-system that the current directory is in. Thus allowing us to simplify some of the answers. Thanks.
– ctrl-alt-delor
Aug 14 '14 at 11:29




@Ramesh, Yes stat "--printf=%mn" . gets the mount-point of the file-system that the current directory is in. Thus allowing us to simplify some of the answers. Thanks.
– ctrl-alt-delor
Aug 14 '14 at 11:29










4 Answers
4






active

oldest

votes

















up vote
12
down vote



accepted










I think you want something like this:



findmnt -T .


When using the option


-T, --target path
if the path is not a mountpoint file or directory, findmnt checks path elements in reverse order to get the mountpoint. You can print only certain fields via -o, --output [list].

See findmnt --help for the list of available fields.



Alternatively, you could run:



(until findmnt . ; do cd .. ; done)


The problem you're running into is that all paths are relative to something or other, so you just have to walk the tree. Every time.



findmnt is a member of the util-linux package and has been for a few years now. By now, regardless of your distro, it should already be installed on your Linux machine if you also have the mount tool.



man mount | grep findmnt -B1 -m1
For more robust and customizable output use
findmnt(8), especially in your scripts.


findmnt will print out all mounts' info without a mount-point argument, and only that for its argument with one. The -D is the emulate df option. Without -D its output is similar to mount's - but far more configurable. Try findmnt --help and see for yourself.



I stick it in a subshell so the current shell's current directory doesn't change.



So:



mkdir -p /tmp/1/2/3/4/5/6 && cd $_ 
(until findmnt . ; do cd .. ; done && findmnt -D .) && pwd


OUTPUT



TARGET SOURCE FSTYPE OPTIONS
/tmp tmpfs tmpfs rw
SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
tmpfs tmpfs 11.8G 839.7M 11G 7% /tmp
/tmp/1/2/3/4/5/6


If you do not have the -D option available to you (Not in older versions of util-linux) then you need never fear - it is little more than a convenience switch in any case. Notice the column headings it produces for each call - you can include or exclude those for each invocation with the -output switch. I can get the same output as -D might provide like:



 findmnt /tmp -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET


OUTPUT



SOURCE FSTYPE  SIZE  USED AVAIL USE% TARGET
tmpfs tmpfs 11.8G 1.1G 10.6G 10% /tmp





share|improve this answer























  • I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
    – ctrl-alt-delor
    Aug 12 '14 at 10:32










  • I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
    – ctrl-alt-delor
    Aug 12 '14 at 10:36










  • @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
    – mikeserv
    Aug 13 '14 at 10:11






  • 1




    Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
    – ctrl-alt-delor
    Aug 14 '14 at 11:30






  • 2




    My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
    – nitrogen
    Jan 23 '17 at 8:08


















up vote
1
down vote













The Linux/Unix way is to have a toolbox of small utilities that, when combined, give you the results that you're after.



They tend not to have an utility for every occassion. Instead you have many small useful utilities that are combined together with pipes etc. The advantage of this is that you can write your own utility quite easily if none are available.



For example, to get the info you're after, you could use:



mount | grep $(df  --output=source . | tail -1)


If you want to reuse the above with different directories, create a script:



#!/bin/bash
mount | grep $(df --output=source $1 | tail -1)


Save it as mountinfo and make it executable (chmod +x mountinfo). You can then use it as:



mountinfo .


If you want a system that has an utility for everything none of which interoperate with each other, then a certain Mr Gates may be able to help you ;-)






share|improve this answer





















  • --output only exists in very recent versions of GNU coreutils (≥8.22).
    – Gilles
    Aug 11 '14 at 22:52










  • This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
    – ctrl-alt-delor
    Aug 13 '14 at 13:26


















up vote
1
down vote













It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:



#!/bin/sh
mountpoint="$(df -P "$1" | awk '{
if (NR==1)
i=index($0,"Mounted on");
else
print substr($0,i);
}')"
mount|grep " on ${mountpoint} type "


df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.



After we get the mount point, we grep for it in the output of mount.






share|improve this answer






























    up vote
    1
    down vote













    I don't know of a command, but you could create a function. You can add the below to your .bashrc:



    mountinfo () {
    mount | grep $(df -P "$1" | tail -n 1 | awk '{print $1}')
    }


    This executes the mount command and passes the output to grep. grep will look for the output of df -P "$1" | tail -n 1 | awk '{print $1}', and to break it down:





    • df -P "$1" will run df on the argument passed to the function,


    • tail -n 1 will only output the second line, the one that contains the partition info.


    • awk '{print $1}' will print the first part of that line, which is the disk/partition number, for example /dev/sda5. That's what grep will look for in the mount command, and output it.


    Source your .bashrc file to apply the changes, or log out and log back in.



    Now, if you run mountinfo ., you'll get the output you want.






    share|improve this answer























    • This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
      – ctrl-alt-delor
      Aug 13 '14 at 13:29











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    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',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f149660%2fmount-info-for-current-directory%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    12
    down vote



    accepted










    I think you want something like this:



    findmnt -T .


    When using the option


    -T, --target path
    if the path is not a mountpoint file or directory, findmnt checks path elements in reverse order to get the mountpoint. You can print only certain fields via -o, --output [list].

    See findmnt --help for the list of available fields.



    Alternatively, you could run:



    (until findmnt . ; do cd .. ; done)


    The problem you're running into is that all paths are relative to something or other, so you just have to walk the tree. Every time.



    findmnt is a member of the util-linux package and has been for a few years now. By now, regardless of your distro, it should already be installed on your Linux machine if you also have the mount tool.



    man mount | grep findmnt -B1 -m1
    For more robust and customizable output use
    findmnt(8), especially in your scripts.


    findmnt will print out all mounts' info without a mount-point argument, and only that for its argument with one. The -D is the emulate df option. Without -D its output is similar to mount's - but far more configurable. Try findmnt --help and see for yourself.



    I stick it in a subshell so the current shell's current directory doesn't change.



    So:



    mkdir -p /tmp/1/2/3/4/5/6 && cd $_ 
    (until findmnt . ; do cd .. ; done && findmnt -D .) && pwd


    OUTPUT



    TARGET SOURCE FSTYPE OPTIONS
    /tmp tmpfs tmpfs rw
    SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 839.7M 11G 7% /tmp
    /tmp/1/2/3/4/5/6


    If you do not have the -D option available to you (Not in older versions of util-linux) then you need never fear - it is little more than a convenience switch in any case. Notice the column headings it produces for each call - you can include or exclude those for each invocation with the -output switch. I can get the same output as -D might provide like:



     findmnt /tmp -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET


    OUTPUT



    SOURCE FSTYPE  SIZE  USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 1.1G 10.6G 10% /tmp





    share|improve this answer























    • I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
      – ctrl-alt-delor
      Aug 12 '14 at 10:32










    • I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
      – ctrl-alt-delor
      Aug 12 '14 at 10:36










    • @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
      – mikeserv
      Aug 13 '14 at 10:11






    • 1




      Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
      – ctrl-alt-delor
      Aug 14 '14 at 11:30






    • 2




      My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
      – nitrogen
      Jan 23 '17 at 8:08















    up vote
    12
    down vote



    accepted










    I think you want something like this:



    findmnt -T .


    When using the option


    -T, --target path
    if the path is not a mountpoint file or directory, findmnt checks path elements in reverse order to get the mountpoint. You can print only certain fields via -o, --output [list].

    See findmnt --help for the list of available fields.



    Alternatively, you could run:



    (until findmnt . ; do cd .. ; done)


    The problem you're running into is that all paths are relative to something or other, so you just have to walk the tree. Every time.



    findmnt is a member of the util-linux package and has been for a few years now. By now, regardless of your distro, it should already be installed on your Linux machine if you also have the mount tool.



    man mount | grep findmnt -B1 -m1
    For more robust and customizable output use
    findmnt(8), especially in your scripts.


    findmnt will print out all mounts' info without a mount-point argument, and only that for its argument with one. The -D is the emulate df option. Without -D its output is similar to mount's - but far more configurable. Try findmnt --help and see for yourself.



    I stick it in a subshell so the current shell's current directory doesn't change.



    So:



    mkdir -p /tmp/1/2/3/4/5/6 && cd $_ 
    (until findmnt . ; do cd .. ; done && findmnt -D .) && pwd


    OUTPUT



    TARGET SOURCE FSTYPE OPTIONS
    /tmp tmpfs tmpfs rw
    SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 839.7M 11G 7% /tmp
    /tmp/1/2/3/4/5/6


    If you do not have the -D option available to you (Not in older versions of util-linux) then you need never fear - it is little more than a convenience switch in any case. Notice the column headings it produces for each call - you can include or exclude those for each invocation with the -output switch. I can get the same output as -D might provide like:



     findmnt /tmp -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET


    OUTPUT



    SOURCE FSTYPE  SIZE  USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 1.1G 10.6G 10% /tmp





    share|improve this answer























    • I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
      – ctrl-alt-delor
      Aug 12 '14 at 10:32










    • I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
      – ctrl-alt-delor
      Aug 12 '14 at 10:36










    • @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
      – mikeserv
      Aug 13 '14 at 10:11






    • 1




      Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
      – ctrl-alt-delor
      Aug 14 '14 at 11:30






    • 2




      My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
      – nitrogen
      Jan 23 '17 at 8:08













    up vote
    12
    down vote



    accepted







    up vote
    12
    down vote



    accepted






    I think you want something like this:



    findmnt -T .


    When using the option


    -T, --target path
    if the path is not a mountpoint file or directory, findmnt checks path elements in reverse order to get the mountpoint. You can print only certain fields via -o, --output [list].

    See findmnt --help for the list of available fields.



    Alternatively, you could run:



    (until findmnt . ; do cd .. ; done)


    The problem you're running into is that all paths are relative to something or other, so you just have to walk the tree. Every time.



    findmnt is a member of the util-linux package and has been for a few years now. By now, regardless of your distro, it should already be installed on your Linux machine if you also have the mount tool.



    man mount | grep findmnt -B1 -m1
    For more robust and customizable output use
    findmnt(8), especially in your scripts.


    findmnt will print out all mounts' info without a mount-point argument, and only that for its argument with one. The -D is the emulate df option. Without -D its output is similar to mount's - but far more configurable. Try findmnt --help and see for yourself.



    I stick it in a subshell so the current shell's current directory doesn't change.



    So:



    mkdir -p /tmp/1/2/3/4/5/6 && cd $_ 
    (until findmnt . ; do cd .. ; done && findmnt -D .) && pwd


    OUTPUT



    TARGET SOURCE FSTYPE OPTIONS
    /tmp tmpfs tmpfs rw
    SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 839.7M 11G 7% /tmp
    /tmp/1/2/3/4/5/6


    If you do not have the -D option available to you (Not in older versions of util-linux) then you need never fear - it is little more than a convenience switch in any case. Notice the column headings it produces for each call - you can include or exclude those for each invocation with the -output switch. I can get the same output as -D might provide like:



     findmnt /tmp -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET


    OUTPUT



    SOURCE FSTYPE  SIZE  USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 1.1G 10.6G 10% /tmp





    share|improve this answer














    I think you want something like this:



    findmnt -T .


    When using the option


    -T, --target path
    if the path is not a mountpoint file or directory, findmnt checks path elements in reverse order to get the mountpoint. You can print only certain fields via -o, --output [list].

    See findmnt --help for the list of available fields.



    Alternatively, you could run:



    (until findmnt . ; do cd .. ; done)


    The problem you're running into is that all paths are relative to something or other, so you just have to walk the tree. Every time.



    findmnt is a member of the util-linux package and has been for a few years now. By now, regardless of your distro, it should already be installed on your Linux machine if you also have the mount tool.



    man mount | grep findmnt -B1 -m1
    For more robust and customizable output use
    findmnt(8), especially in your scripts.


    findmnt will print out all mounts' info without a mount-point argument, and only that for its argument with one. The -D is the emulate df option. Without -D its output is similar to mount's - but far more configurable. Try findmnt --help and see for yourself.



    I stick it in a subshell so the current shell's current directory doesn't change.



    So:



    mkdir -p /tmp/1/2/3/4/5/6 && cd $_ 
    (until findmnt . ; do cd .. ; done && findmnt -D .) && pwd


    OUTPUT



    TARGET SOURCE FSTYPE OPTIONS
    /tmp tmpfs tmpfs rw
    SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 839.7M 11G 7% /tmp
    /tmp/1/2/3/4/5/6


    If you do not have the -D option available to you (Not in older versions of util-linux) then you need never fear - it is little more than a convenience switch in any case. Notice the column headings it produces for each call - you can include or exclude those for each invocation with the -output switch. I can get the same output as -D might provide like:



     findmnt /tmp -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET


    OUTPUT



    SOURCE FSTYPE  SIZE  USED AVAIL USE% TARGET
    tmpfs tmpfs 11.8G 1.1G 10.6G 10% /tmp






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 19 at 12:10









    don_crissti

    48.9k15129157




    48.9k15129157










    answered Aug 11 '14 at 23:20









    mikeserv

    45.1k566152




    45.1k566152












    • I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
      – ctrl-alt-delor
      Aug 12 '14 at 10:32










    • I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
      – ctrl-alt-delor
      Aug 12 '14 at 10:36










    • @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
      – mikeserv
      Aug 13 '14 at 10:11






    • 1




      Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
      – ctrl-alt-delor
      Aug 14 '14 at 11:30






    • 2




      My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
      – nitrogen
      Jan 23 '17 at 8:08


















    • I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
      – ctrl-alt-delor
      Aug 12 '14 at 10:32










    • I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
      – ctrl-alt-delor
      Aug 12 '14 at 10:36










    • @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
      – mikeserv
      Aug 13 '14 at 10:11






    • 1




      Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
      – ctrl-alt-delor
      Aug 14 '14 at 11:30






    • 2




      My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
      – nitrogen
      Jan 23 '17 at 8:08
















    I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
    – ctrl-alt-delor
    Aug 12 '14 at 10:32




    I like it, except the bit about -D, I don't have that option. (I am on Debian7, util-linux 2.20.1-5.3)
    – ctrl-alt-delor
    Aug 12 '14 at 10:32












    I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
    – ctrl-alt-delor
    Aug 12 '14 at 10:36




    I will √ you in a few days, I will leave some time to see if anyone has a more perfect answer. Though this is close to perfect (if it worked like df: did not need the loop, then it would be perfect).
    – ctrl-alt-delor
    Aug 12 '14 at 10:36












    @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
    – mikeserv
    Aug 13 '14 at 10:11




    @richard - that's a good idea - I don't like it when answers get accepted too soon. regarding the loop and df - I'm willing to bet it does loop, you just don't have to tell it to do so.
    – mikeserv
    Aug 13 '14 at 10:11




    1




    1




    Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
    – ctrl-alt-delor
    Aug 14 '14 at 11:30




    Thanks to @ramesh we can also do findmnt $(stat "--printf=%mn" .)
    – ctrl-alt-delor
    Aug 14 '14 at 11:30




    2




    2




    My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
    – nitrogen
    Jan 23 '17 at 8:08




    My version of findmnt has a -T option that can bypass the cd .. loop. Might be useful to someone else.
    – nitrogen
    Jan 23 '17 at 8:08












    up vote
    1
    down vote













    The Linux/Unix way is to have a toolbox of small utilities that, when combined, give you the results that you're after.



    They tend not to have an utility for every occassion. Instead you have many small useful utilities that are combined together with pipes etc. The advantage of this is that you can write your own utility quite easily if none are available.



    For example, to get the info you're after, you could use:



    mount | grep $(df  --output=source . | tail -1)


    If you want to reuse the above with different directories, create a script:



    #!/bin/bash
    mount | grep $(df --output=source $1 | tail -1)


    Save it as mountinfo and make it executable (chmod +x mountinfo). You can then use it as:



    mountinfo .


    If you want a system that has an utility for everything none of which interoperate with each other, then a certain Mr Gates may be able to help you ;-)






    share|improve this answer





















    • --output only exists in very recent versions of GNU coreutils (≥8.22).
      – Gilles
      Aug 11 '14 at 22:52










    • This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
      – ctrl-alt-delor
      Aug 13 '14 at 13:26















    up vote
    1
    down vote













    The Linux/Unix way is to have a toolbox of small utilities that, when combined, give you the results that you're after.



    They tend not to have an utility for every occassion. Instead you have many small useful utilities that are combined together with pipes etc. The advantage of this is that you can write your own utility quite easily if none are available.



    For example, to get the info you're after, you could use:



    mount | grep $(df  --output=source . | tail -1)


    If you want to reuse the above with different directories, create a script:



    #!/bin/bash
    mount | grep $(df --output=source $1 | tail -1)


    Save it as mountinfo and make it executable (chmod +x mountinfo). You can then use it as:



    mountinfo .


    If you want a system that has an utility for everything none of which interoperate with each other, then a certain Mr Gates may be able to help you ;-)






    share|improve this answer





















    • --output only exists in very recent versions of GNU coreutils (≥8.22).
      – Gilles
      Aug 11 '14 at 22:52










    • This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
      – ctrl-alt-delor
      Aug 13 '14 at 13:26













    up vote
    1
    down vote










    up vote
    1
    down vote









    The Linux/Unix way is to have a toolbox of small utilities that, when combined, give you the results that you're after.



    They tend not to have an utility for every occassion. Instead you have many small useful utilities that are combined together with pipes etc. The advantage of this is that you can write your own utility quite easily if none are available.



    For example, to get the info you're after, you could use:



    mount | grep $(df  --output=source . | tail -1)


    If you want to reuse the above with different directories, create a script:



    #!/bin/bash
    mount | grep $(df --output=source $1 | tail -1)


    Save it as mountinfo and make it executable (chmod +x mountinfo). You can then use it as:



    mountinfo .


    If you want a system that has an utility for everything none of which interoperate with each other, then a certain Mr Gates may be able to help you ;-)






    share|improve this answer












    The Linux/Unix way is to have a toolbox of small utilities that, when combined, give you the results that you're after.



    They tend not to have an utility for every occassion. Instead you have many small useful utilities that are combined together with pipes etc. The advantage of this is that you can write your own utility quite easily if none are available.



    For example, to get the info you're after, you could use:



    mount | grep $(df  --output=source . | tail -1)


    If you want to reuse the above with different directories, create a script:



    #!/bin/bash
    mount | grep $(df --output=source $1 | tail -1)


    Save it as mountinfo and make it executable (chmod +x mountinfo). You can then use it as:



    mountinfo .


    If you want a system that has an utility for everything none of which interoperate with each other, then a certain Mr Gates may be able to help you ;-)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 11 '14 at 12:29









    garethTheRed

    23.8k36079




    23.8k36079












    • --output only exists in very recent versions of GNU coreutils (≥8.22).
      – Gilles
      Aug 11 '14 at 22:52










    • This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
      – ctrl-alt-delor
      Aug 13 '14 at 13:26


















    • --output only exists in very recent versions of GNU coreutils (≥8.22).
      – Gilles
      Aug 11 '14 at 22:52










    • This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
      – ctrl-alt-delor
      Aug 13 '14 at 13:26
















    --output only exists in very recent versions of GNU coreutils (≥8.22).
    – Gilles
    Aug 11 '14 at 22:52




    --output only exists in very recent versions of GNU coreutils (≥8.22).
    – Gilles
    Aug 11 '14 at 22:52












    This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
    – ctrl-alt-delor
    Aug 13 '14 at 13:26




    This is pretty much what I have been doing, it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
    – ctrl-alt-delor
    Aug 13 '14 at 13:26










    up vote
    1
    down vote













    It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:



    #!/bin/sh
    mountpoint="$(df -P "$1" | awk '{
    if (NR==1)
    i=index($0,"Mounted on");
    else
    print substr($0,i);
    }')"
    mount|grep " on ${mountpoint} type "


    df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.



    After we get the mount point, we grep for it in the output of mount.






    share|improve this answer



























      up vote
      1
      down vote













      It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:



      #!/bin/sh
      mountpoint="$(df -P "$1" | awk '{
      if (NR==1)
      i=index($0,"Mounted on");
      else
      print substr($0,i);
      }')"
      mount|grep " on ${mountpoint} type "


      df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.



      After we get the mount point, we grep for it in the output of mount.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:



        #!/bin/sh
        mountpoint="$(df -P "$1" | awk '{
        if (NR==1)
        i=index($0,"Mounted on");
        else
        print substr($0,i);
        }')"
        mount|grep " on ${mountpoint} type "


        df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.



        After we get the mount point, we grep for it in the output of mount.






        share|improve this answer














        It can be somewhat messy if the mount points contain blanks, but this should work except in cases where the mount points contain newlines:



        #!/bin/sh
        mountpoint="$(df -P "$1" | awk '{
        if (NR==1)
        i=index($0,"Mounted on");
        else
        print substr($0,i);
        }')"
        mount|grep " on ${mountpoint} type "


        df -P outputs one line for the filesystem; without that option, df may output two lines if the mount point is long. The mount point name starts in the same column as does the "Mounted on" label in the header line.



        After we get the mount point, we grep for it in the output of mount.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 11 '14 at 22:50









        Gilles

        523k12610421575




        523k12610421575










        answered Aug 11 '14 at 16:55









        Mark Plotnick

        17.7k23964




        17.7k23964






















            up vote
            1
            down vote













            I don't know of a command, but you could create a function. You can add the below to your .bashrc:



            mountinfo () {
            mount | grep $(df -P "$1" | tail -n 1 | awk '{print $1}')
            }


            This executes the mount command and passes the output to grep. grep will look for the output of df -P "$1" | tail -n 1 | awk '{print $1}', and to break it down:





            • df -P "$1" will run df on the argument passed to the function,


            • tail -n 1 will only output the second line, the one that contains the partition info.


            • awk '{print $1}' will print the first part of that line, which is the disk/partition number, for example /dev/sda5. That's what grep will look for in the mount command, and output it.


            Source your .bashrc file to apply the changes, or log out and log back in.



            Now, if you run mountinfo ., you'll get the output you want.






            share|improve this answer























            • This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
              – ctrl-alt-delor
              Aug 13 '14 at 13:29















            up vote
            1
            down vote













            I don't know of a command, but you could create a function. You can add the below to your .bashrc:



            mountinfo () {
            mount | grep $(df -P "$1" | tail -n 1 | awk '{print $1}')
            }


            This executes the mount command and passes the output to grep. grep will look for the output of df -P "$1" | tail -n 1 | awk '{print $1}', and to break it down:





            • df -P "$1" will run df on the argument passed to the function,


            • tail -n 1 will only output the second line, the one that contains the partition info.


            • awk '{print $1}' will print the first part of that line, which is the disk/partition number, for example /dev/sda5. That's what grep will look for in the mount command, and output it.


            Source your .bashrc file to apply the changes, or log out and log back in.



            Now, if you run mountinfo ., you'll get the output you want.






            share|improve this answer























            • This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
              – ctrl-alt-delor
              Aug 13 '14 at 13:29













            up vote
            1
            down vote










            up vote
            1
            down vote









            I don't know of a command, but you could create a function. You can add the below to your .bashrc:



            mountinfo () {
            mount | grep $(df -P "$1" | tail -n 1 | awk '{print $1}')
            }


            This executes the mount command and passes the output to grep. grep will look for the output of df -P "$1" | tail -n 1 | awk '{print $1}', and to break it down:





            • df -P "$1" will run df on the argument passed to the function,


            • tail -n 1 will only output the second line, the one that contains the partition info.


            • awk '{print $1}' will print the first part of that line, which is the disk/partition number, for example /dev/sda5. That's what grep will look for in the mount command, and output it.


            Source your .bashrc file to apply the changes, or log out and log back in.



            Now, if you run mountinfo ., you'll get the output you want.






            share|improve this answer














            I don't know of a command, but you could create a function. You can add the below to your .bashrc:



            mountinfo () {
            mount | grep $(df -P "$1" | tail -n 1 | awk '{print $1}')
            }


            This executes the mount command and passes the output to grep. grep will look for the output of df -P "$1" | tail -n 1 | awk '{print $1}', and to break it down:





            • df -P "$1" will run df on the argument passed to the function,


            • tail -n 1 will only output the second line, the one that contains the partition info.


            • awk '{print $1}' will print the first part of that line, which is the disk/partition number, for example /dev/sda5. That's what grep will look for in the mount command, and output it.


            Source your .bashrc file to apply the changes, or log out and log back in.



            Now, if you run mountinfo ., you'll get the output you want.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 11 '14 at 22:51









            Gilles

            523k12610421575




            523k12610421575










            answered Aug 11 '14 at 12:41









            Alaa Ali

            9452820




            9452820












            • This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
              – ctrl-alt-delor
              Aug 13 '14 at 13:29


















            • This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
              – ctrl-alt-delor
              Aug 13 '14 at 13:29
















            This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
            – ctrl-alt-delor
            Aug 13 '14 at 13:29




            This is pretty much what I have been doing (but without the function, I don't do it enough, when I do it is on other systems e.g. answers on this site. ), it is just that mount with no options seem a bit of an after thought: with options you create mount points, without it lists them, I was hoping for a better list tool. As we see @mikeserv has shown us findmnt.
            – ctrl-alt-delor
            Aug 13 '14 at 13:29


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2funix.stackexchange.com%2fquestions%2f149660%2fmount-info-for-current-directory%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

            Morgemoulin

            Scott Moir

            Souastre