Check if two paths are the same, even if their strings don't match exactly












0















I have a script that depends on some environment variables, some of which are paths



The script checks if it's being run in the correct directory by checking $(pwd)/expected-subdir against $VARIABLE_PATH/expected_subdir



Of course if $VARIABLE_PATH == $(pwd)/ (I naturally appended a slash to the end of the variable when typing it), the string match fails even though the directories are technically sane.



Is there a way to uniquely identify a directory, given a path to it, and see if another path will route you to the same spot? It's possible the path given is not sane, so this check should still be done, but it seems unnecessary to force the path to exactly match, when a stray slash or even a relative directory (I know these can be bad sometimes) would route you to the same spot.










share|improve this question



























    0















    I have a script that depends on some environment variables, some of which are paths



    The script checks if it's being run in the correct directory by checking $(pwd)/expected-subdir against $VARIABLE_PATH/expected_subdir



    Of course if $VARIABLE_PATH == $(pwd)/ (I naturally appended a slash to the end of the variable when typing it), the string match fails even though the directories are technically sane.



    Is there a way to uniquely identify a directory, given a path to it, and see if another path will route you to the same spot? It's possible the path given is not sane, so this check should still be done, but it seems unnecessary to force the path to exactly match, when a stray slash or even a relative directory (I know these can be bad sometimes) would route you to the same spot.










    share|improve this question

























      0












      0








      0








      I have a script that depends on some environment variables, some of which are paths



      The script checks if it's being run in the correct directory by checking $(pwd)/expected-subdir against $VARIABLE_PATH/expected_subdir



      Of course if $VARIABLE_PATH == $(pwd)/ (I naturally appended a slash to the end of the variable when typing it), the string match fails even though the directories are technically sane.



      Is there a way to uniquely identify a directory, given a path to it, and see if another path will route you to the same spot? It's possible the path given is not sane, so this check should still be done, but it seems unnecessary to force the path to exactly match, when a stray slash or even a relative directory (I know these can be bad sometimes) would route you to the same spot.










      share|improve this question














      I have a script that depends on some environment variables, some of which are paths



      The script checks if it's being run in the correct directory by checking $(pwd)/expected-subdir against $VARIABLE_PATH/expected_subdir



      Of course if $VARIABLE_PATH == $(pwd)/ (I naturally appended a slash to the end of the variable when typing it), the string match fails even though the directories are technically sane.



      Is there a way to uniquely identify a directory, given a path to it, and see if another path will route you to the same spot? It's possible the path given is not sane, so this check should still be done, but it seems unnecessary to force the path to exactly match, when a stray slash or even a relative directory (I know these can be bad sometimes) would route you to the same spot.







      linux bash directory-listing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 21 at 14:46









      Brydon GibsonBrydon Gibson

      377213




      377213






















          2 Answers
          2






          active

          oldest

          votes


















          1














          This other answer mentions stat. Let's improve the approach:



          a="$(stat --format=%d:%i -- "$(pwd)/expected-subdir/")"         || printf "Error An" >&2
          b="$(stat --format=%d:%i -- "$VARIABLE_PATH/expected-subdir/")" || printf "Error Bn" >&2
          [ "$a" = "$b" ] || printf "Not the same path.n" >&2


          Notes:




          • We're using stat --format=, so no further parsing is required.


          • %d is device number, %i is inode number. The latter alone is not enough because two objects on different devices (filesystems) may have the same inode number.

          • The shell is smart enough to separately handle quotes inside and outside $( ).


          • printf-s are just stubs for error handling. In the real script you'd probably want something like



            [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


          • Nonexistent path will make stat throw an error.


          • Trailing slashes are important. If foo is a symlink to a directory, stat foo will examine the symlink while stat foo/ will examine the directory. Alternatively research stat -L and use it maybe.


          • -- is in case $(pwd) or $VARIABLE_PATH begins with - (see guideline 10 here).




          There are readlink -f (also mentioned in the other answer) and realpath utilities. One of them may be a better approach than stat. It depends on which aspects of paths are important to you. Main differences:




          1. If /foo/bar/ is a bind mount to /moo/baz/ then stat --format=%d:%i will tell you they are the same, but readlink or realpath will consider them different.

          2. The situation gets complicated with symlinks and ... See man 1 realpath, especially -L and -P options.


          With symlinks involved, if your script changes the directory upwards (towards /, e.g. cd ..), you may get different results depending on where you start, even if stat or readlink -f says the two starting points are the same (compare Why does ls .. show real parent content when I'm inside a symbolic link directory?). Consider this approach:



          # early in the script
          set -P
          cd . # seems like no-op but updates the PWD variable to physical path


          With bind mounts involved, if your script changes the directory, you may get different results depending on where you start, even if stat says the two starting points are the same. Consider the example with /foo/bar/ and /moo/baz/ (already introduced above). It's obvious /foo/ may be completely different than /moo/. But also /foo/bar/abc may be different than /moo/baz/abc because any abc may be an independent bind mount to something else. So not only cd .. may place you in a different spot, but also cd abc.



          Well, abc may be a file. What if you bind another file to /moo/baz/abc but not to /foo/bar/abc? The perceived files will be different even if stat says you're in the same place!



          Because of these problems you may indeed prefer readlink or realpath over stat.





          stat, readlink and realpath are not required by POSIX. In your case a portable solution may look like this:



          a="$(cd -P -- "expected-subdir" && pwd -P)"                || exit 1
          b="$(cd -P -- "$VARIABLE_PATH/expected-subdir" && pwd -P)" || exit 1
          [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


          It works by cd-ing to either path and retrieving it with pwd. These operations are explicitly forced to act "physically" (-P).



          set -P is not POSIX either. If you want POSIX shell to "emulate" set -P, replace cd and pwd:



          cd()  { command cd  -P "$@"; }
          pwd() { command pwd -P "$@"; }


          POSIX requires the last -P or -L option to take effect, so pwd -L still retrieves the logical path even though the function "injects" -P; the same for cd -L.






          share|improve this answer

































            1














            You can compare their inode numbers, which can be obtained from ls -i



            ls -di path/to/dir


            (-d prevents ls from showing the inode ids for the contents of the directory);



            or from stat



            stat path/to/dir | grep -o 'Inode: [0-9]*' | cut -d' ' -f2


            You can also use readlink -f to get the full path to the directory.






            share|improve this answer
























            • For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

              – MSalters
              Jan 21 at 16:17











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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%2fsuperuser.com%2fquestions%2f1396645%2fcheck-if-two-paths-are-the-same-even-if-their-strings-dont-match-exactly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            This other answer mentions stat. Let's improve the approach:



            a="$(stat --format=%d:%i -- "$(pwd)/expected-subdir/")"         || printf "Error An" >&2
            b="$(stat --format=%d:%i -- "$VARIABLE_PATH/expected-subdir/")" || printf "Error Bn" >&2
            [ "$a" = "$b" ] || printf "Not the same path.n" >&2


            Notes:




            • We're using stat --format=, so no further parsing is required.


            • %d is device number, %i is inode number. The latter alone is not enough because two objects on different devices (filesystems) may have the same inode number.

            • The shell is smart enough to separately handle quotes inside and outside $( ).


            • printf-s are just stubs for error handling. In the real script you'd probably want something like



              [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


            • Nonexistent path will make stat throw an error.


            • Trailing slashes are important. If foo is a symlink to a directory, stat foo will examine the symlink while stat foo/ will examine the directory. Alternatively research stat -L and use it maybe.


            • -- is in case $(pwd) or $VARIABLE_PATH begins with - (see guideline 10 here).




            There are readlink -f (also mentioned in the other answer) and realpath utilities. One of them may be a better approach than stat. It depends on which aspects of paths are important to you. Main differences:




            1. If /foo/bar/ is a bind mount to /moo/baz/ then stat --format=%d:%i will tell you they are the same, but readlink or realpath will consider them different.

            2. The situation gets complicated with symlinks and ... See man 1 realpath, especially -L and -P options.


            With symlinks involved, if your script changes the directory upwards (towards /, e.g. cd ..), you may get different results depending on where you start, even if stat or readlink -f says the two starting points are the same (compare Why does ls .. show real parent content when I'm inside a symbolic link directory?). Consider this approach:



            # early in the script
            set -P
            cd . # seems like no-op but updates the PWD variable to physical path


            With bind mounts involved, if your script changes the directory, you may get different results depending on where you start, even if stat says the two starting points are the same. Consider the example with /foo/bar/ and /moo/baz/ (already introduced above). It's obvious /foo/ may be completely different than /moo/. But also /foo/bar/abc may be different than /moo/baz/abc because any abc may be an independent bind mount to something else. So not only cd .. may place you in a different spot, but also cd abc.



            Well, abc may be a file. What if you bind another file to /moo/baz/abc but not to /foo/bar/abc? The perceived files will be different even if stat says you're in the same place!



            Because of these problems you may indeed prefer readlink or realpath over stat.





            stat, readlink and realpath are not required by POSIX. In your case a portable solution may look like this:



            a="$(cd -P -- "expected-subdir" && pwd -P)"                || exit 1
            b="$(cd -P -- "$VARIABLE_PATH/expected-subdir" && pwd -P)" || exit 1
            [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


            It works by cd-ing to either path and retrieving it with pwd. These operations are explicitly forced to act "physically" (-P).



            set -P is not POSIX either. If you want POSIX shell to "emulate" set -P, replace cd and pwd:



            cd()  { command cd  -P "$@"; }
            pwd() { command pwd -P "$@"; }


            POSIX requires the last -P or -L option to take effect, so pwd -L still retrieves the logical path even though the function "injects" -P; the same for cd -L.






            share|improve this answer






























              1














              This other answer mentions stat. Let's improve the approach:



              a="$(stat --format=%d:%i -- "$(pwd)/expected-subdir/")"         || printf "Error An" >&2
              b="$(stat --format=%d:%i -- "$VARIABLE_PATH/expected-subdir/")" || printf "Error Bn" >&2
              [ "$a" = "$b" ] || printf "Not the same path.n" >&2


              Notes:




              • We're using stat --format=, so no further parsing is required.


              • %d is device number, %i is inode number. The latter alone is not enough because two objects on different devices (filesystems) may have the same inode number.

              • The shell is smart enough to separately handle quotes inside and outside $( ).


              • printf-s are just stubs for error handling. In the real script you'd probably want something like



                [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


              • Nonexistent path will make stat throw an error.


              • Trailing slashes are important. If foo is a symlink to a directory, stat foo will examine the symlink while stat foo/ will examine the directory. Alternatively research stat -L and use it maybe.


              • -- is in case $(pwd) or $VARIABLE_PATH begins with - (see guideline 10 here).




              There are readlink -f (also mentioned in the other answer) and realpath utilities. One of them may be a better approach than stat. It depends on which aspects of paths are important to you. Main differences:




              1. If /foo/bar/ is a bind mount to /moo/baz/ then stat --format=%d:%i will tell you they are the same, but readlink or realpath will consider them different.

              2. The situation gets complicated with symlinks and ... See man 1 realpath, especially -L and -P options.


              With symlinks involved, if your script changes the directory upwards (towards /, e.g. cd ..), you may get different results depending on where you start, even if stat or readlink -f says the two starting points are the same (compare Why does ls .. show real parent content when I'm inside a symbolic link directory?). Consider this approach:



              # early in the script
              set -P
              cd . # seems like no-op but updates the PWD variable to physical path


              With bind mounts involved, if your script changes the directory, you may get different results depending on where you start, even if stat says the two starting points are the same. Consider the example with /foo/bar/ and /moo/baz/ (already introduced above). It's obvious /foo/ may be completely different than /moo/. But also /foo/bar/abc may be different than /moo/baz/abc because any abc may be an independent bind mount to something else. So not only cd .. may place you in a different spot, but also cd abc.



              Well, abc may be a file. What if you bind another file to /moo/baz/abc but not to /foo/bar/abc? The perceived files will be different even if stat says you're in the same place!



              Because of these problems you may indeed prefer readlink or realpath over stat.





              stat, readlink and realpath are not required by POSIX. In your case a portable solution may look like this:



              a="$(cd -P -- "expected-subdir" && pwd -P)"                || exit 1
              b="$(cd -P -- "$VARIABLE_PATH/expected-subdir" && pwd -P)" || exit 1
              [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


              It works by cd-ing to either path and retrieving it with pwd. These operations are explicitly forced to act "physically" (-P).



              set -P is not POSIX either. If you want POSIX shell to "emulate" set -P, replace cd and pwd:



              cd()  { command cd  -P "$@"; }
              pwd() { command pwd -P "$@"; }


              POSIX requires the last -P or -L option to take effect, so pwd -L still retrieves the logical path even though the function "injects" -P; the same for cd -L.






              share|improve this answer




























                1












                1








                1







                This other answer mentions stat. Let's improve the approach:



                a="$(stat --format=%d:%i -- "$(pwd)/expected-subdir/")"         || printf "Error An" >&2
                b="$(stat --format=%d:%i -- "$VARIABLE_PATH/expected-subdir/")" || printf "Error Bn" >&2
                [ "$a" = "$b" ] || printf "Not the same path.n" >&2


                Notes:




                • We're using stat --format=, so no further parsing is required.


                • %d is device number, %i is inode number. The latter alone is not enough because two objects on different devices (filesystems) may have the same inode number.

                • The shell is smart enough to separately handle quotes inside and outside $( ).


                • printf-s are just stubs for error handling. In the real script you'd probably want something like



                  [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


                • Nonexistent path will make stat throw an error.


                • Trailing slashes are important. If foo is a symlink to a directory, stat foo will examine the symlink while stat foo/ will examine the directory. Alternatively research stat -L and use it maybe.


                • -- is in case $(pwd) or $VARIABLE_PATH begins with - (see guideline 10 here).




                There are readlink -f (also mentioned in the other answer) and realpath utilities. One of them may be a better approach than stat. It depends on which aspects of paths are important to you. Main differences:




                1. If /foo/bar/ is a bind mount to /moo/baz/ then stat --format=%d:%i will tell you they are the same, but readlink or realpath will consider them different.

                2. The situation gets complicated with symlinks and ... See man 1 realpath, especially -L and -P options.


                With symlinks involved, if your script changes the directory upwards (towards /, e.g. cd ..), you may get different results depending on where you start, even if stat or readlink -f says the two starting points are the same (compare Why does ls .. show real parent content when I'm inside a symbolic link directory?). Consider this approach:



                # early in the script
                set -P
                cd . # seems like no-op but updates the PWD variable to physical path


                With bind mounts involved, if your script changes the directory, you may get different results depending on where you start, even if stat says the two starting points are the same. Consider the example with /foo/bar/ and /moo/baz/ (already introduced above). It's obvious /foo/ may be completely different than /moo/. But also /foo/bar/abc may be different than /moo/baz/abc because any abc may be an independent bind mount to something else. So not only cd .. may place you in a different spot, but also cd abc.



                Well, abc may be a file. What if you bind another file to /moo/baz/abc but not to /foo/bar/abc? The perceived files will be different even if stat says you're in the same place!



                Because of these problems you may indeed prefer readlink or realpath over stat.





                stat, readlink and realpath are not required by POSIX. In your case a portable solution may look like this:



                a="$(cd -P -- "expected-subdir" && pwd -P)"                || exit 1
                b="$(cd -P -- "$VARIABLE_PATH/expected-subdir" && pwd -P)" || exit 1
                [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


                It works by cd-ing to either path and retrieving it with pwd. These operations are explicitly forced to act "physically" (-P).



                set -P is not POSIX either. If you want POSIX shell to "emulate" set -P, replace cd and pwd:



                cd()  { command cd  -P "$@"; }
                pwd() { command pwd -P "$@"; }


                POSIX requires the last -P or -L option to take effect, so pwd -L still retrieves the logical path even though the function "injects" -P; the same for cd -L.






                share|improve this answer















                This other answer mentions stat. Let's improve the approach:



                a="$(stat --format=%d:%i -- "$(pwd)/expected-subdir/")"         || printf "Error An" >&2
                b="$(stat --format=%d:%i -- "$VARIABLE_PATH/expected-subdir/")" || printf "Error Bn" >&2
                [ "$a" = "$b" ] || printf "Not the same path.n" >&2


                Notes:




                • We're using stat --format=, so no further parsing is required.


                • %d is device number, %i is inode number. The latter alone is not enough because two objects on different devices (filesystems) may have the same inode number.

                • The shell is smart enough to separately handle quotes inside and outside $( ).


                • printf-s are just stubs for error handling. In the real script you'd probably want something like



                  [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


                • Nonexistent path will make stat throw an error.


                • Trailing slashes are important. If foo is a symlink to a directory, stat foo will examine the symlink while stat foo/ will examine the directory. Alternatively research stat -L and use it maybe.


                • -- is in case $(pwd) or $VARIABLE_PATH begins with - (see guideline 10 here).




                There are readlink -f (also mentioned in the other answer) and realpath utilities. One of them may be a better approach than stat. It depends on which aspects of paths are important to you. Main differences:




                1. If /foo/bar/ is a bind mount to /moo/baz/ then stat --format=%d:%i will tell you they are the same, but readlink or realpath will consider them different.

                2. The situation gets complicated with symlinks and ... See man 1 realpath, especially -L and -P options.


                With symlinks involved, if your script changes the directory upwards (towards /, e.g. cd ..), you may get different results depending on where you start, even if stat or readlink -f says the two starting points are the same (compare Why does ls .. show real parent content when I'm inside a symbolic link directory?). Consider this approach:



                # early in the script
                set -P
                cd . # seems like no-op but updates the PWD variable to physical path


                With bind mounts involved, if your script changes the directory, you may get different results depending on where you start, even if stat says the two starting points are the same. Consider the example with /foo/bar/ and /moo/baz/ (already introduced above). It's obvious /foo/ may be completely different than /moo/. But also /foo/bar/abc may be different than /moo/baz/abc because any abc may be an independent bind mount to something else. So not only cd .. may place you in a different spot, but also cd abc.



                Well, abc may be a file. What if you bind another file to /moo/baz/abc but not to /foo/bar/abc? The perceived files will be different even if stat says you're in the same place!



                Because of these problems you may indeed prefer readlink or realpath over stat.





                stat, readlink and realpath are not required by POSIX. In your case a portable solution may look like this:



                a="$(cd -P -- "expected-subdir" && pwd -P)"                || exit 1
                b="$(cd -P -- "$VARIABLE_PATH/expected-subdir" && pwd -P)" || exit 1
                [ "$a" = "$b" ] || { printf "Not the same path.n" >&2; exit 2; }


                It works by cd-ing to either path and retrieving it with pwd. These operations are explicitly forced to act "physically" (-P).



                set -P is not POSIX either. If you want POSIX shell to "emulate" set -P, replace cd and pwd:



                cd()  { command cd  -P "$@"; }
                pwd() { command pwd -P "$@"; }


                POSIX requires the last -P or -L option to take effect, so pwd -L still retrieves the logical path even though the function "injects" -P; the same for cd -L.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 22 at 9:45

























                answered Jan 22 at 8:46









                Kamil MaciorowskiKamil Maciorowski

                28.3k156185




                28.3k156185

























                    1














                    You can compare their inode numbers, which can be obtained from ls -i



                    ls -di path/to/dir


                    (-d prevents ls from showing the inode ids for the contents of the directory);



                    or from stat



                    stat path/to/dir | grep -o 'Inode: [0-9]*' | cut -d' ' -f2


                    You can also use readlink -f to get the full path to the directory.






                    share|improve this answer
























                    • For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

                      – MSalters
                      Jan 21 at 16:17
















                    1














                    You can compare their inode numbers, which can be obtained from ls -i



                    ls -di path/to/dir


                    (-d prevents ls from showing the inode ids for the contents of the directory);



                    or from stat



                    stat path/to/dir | grep -o 'Inode: [0-9]*' | cut -d' ' -f2


                    You can also use readlink -f to get the full path to the directory.






                    share|improve this answer
























                    • For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

                      – MSalters
                      Jan 21 at 16:17














                    1












                    1








                    1







                    You can compare their inode numbers, which can be obtained from ls -i



                    ls -di path/to/dir


                    (-d prevents ls from showing the inode ids for the contents of the directory);



                    or from stat



                    stat path/to/dir | grep -o 'Inode: [0-9]*' | cut -d' ' -f2


                    You can also use readlink -f to get the full path to the directory.






                    share|improve this answer













                    You can compare their inode numbers, which can be obtained from ls -i



                    ls -di path/to/dir


                    (-d prevents ls from showing the inode ids for the contents of the directory);



                    or from stat



                    stat path/to/dir | grep -o 'Inode: [0-9]*' | cut -d' ' -f2


                    You can also use readlink -f to get the full path to the directory.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 21 at 14:54









                    chorobachoroba

                    13.4k13341




                    13.4k13341













                    • For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

                      – MSalters
                      Jan 21 at 16:17



















                    • For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

                      – MSalters
                      Jan 21 at 16:17

















                    For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

                    – MSalters
                    Jan 21 at 16:17





                    For scripting, it might be easier to use find path/to/dir/ -maxdepth 0 -printf %i\n as that prints just the inode, and not the name. The maxdepth 0 prevents a deep search. For extra safety, add %D since inodes are only unique per disk, not systemwide.

                    – MSalters
                    Jan 21 at 16:17


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • 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%2fsuperuser.com%2fquestions%2f1396645%2fcheck-if-two-paths-are-the-same-even-if-their-strings-dont-match-exactly%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

                    Paul Cézanne

                    UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                    Angular material date-picker (MatDatepicker) auto completes the date on focus out