pwd without symlinks

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
46
down vote

favorite
8












If I do pwd I notice it uses whatever symlinks I used to get into the current directory. Can I get it to tell me the "real" directory I'm in ... i.e. the path from the root to my current directory without the use of any symlinks?










share|improve this question

























    up vote
    46
    down vote

    favorite
    8












    If I do pwd I notice it uses whatever symlinks I used to get into the current directory. Can I get it to tell me the "real" directory I'm in ... i.e. the path from the root to my current directory without the use of any symlinks?










    share|improve this question























      up vote
      46
      down vote

      favorite
      8









      up vote
      46
      down vote

      favorite
      8






      8





      If I do pwd I notice it uses whatever symlinks I used to get into the current directory. Can I get it to tell me the "real" directory I'm in ... i.e. the path from the root to my current directory without the use of any symlinks?










      share|improve this question













      If I do pwd I notice it uses whatever symlinks I used to get into the current directory. Can I get it to tell me the "real" directory I'm in ... i.e. the path from the root to my current directory without the use of any symlinks?







      symlink






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 2 '11 at 18:07









      JoelFan

      535713




      535713




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          60
          down vote













          According to the POSIX manpage for pwd, the -P option may be of use:




          -P The absolute pathname written
          shall not contain filenames that, in
          the context of the pathname, refer to
          files of type symbolic link.




          Thus



          $ pwd -P


          should be what you need.






          share|improve this answer




















          • I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
            – Chud37
            Mar 9 at 14:52

















          up vote
          7
          down vote













          The pwd shell built-in uses the path the shell keeps track of when you cd (and stores it in $PWD). This means if you have a symlink to a complex (deep) path, it will tell you what you typed to change to that directory instead of the real path. This is done to give you what you want most of the time.



          /bin/pwd uses the getcwd system call (which these days is a library call, reading /proc/self/cwd) which returns the canonical path for the current directory, sans all symlink traversals.



          As Steven D pointed out, pwd has the -P option to ignore $PWD. It also has the -L option to return the contents of $PWD. The man page for pwd does not say which option is used by default but experience tells me the above description is correct (shell pwd vs. /bin/pwd). However you should probably not rely on that and just use pwd -P.






          share|improve this answer


















          • 2




            The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
            – Stéphane Chazelas
            Dec 2 '12 at 20:10










          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%2f6800%2fpwd-without-symlinks%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








          up vote
          60
          down vote













          According to the POSIX manpage for pwd, the -P option may be of use:




          -P The absolute pathname written
          shall not contain filenames that, in
          the context of the pathname, refer to
          files of type symbolic link.




          Thus



          $ pwd -P


          should be what you need.






          share|improve this answer




















          • I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
            – Chud37
            Mar 9 at 14:52














          up vote
          60
          down vote













          According to the POSIX manpage for pwd, the -P option may be of use:




          -P The absolute pathname written
          shall not contain filenames that, in
          the context of the pathname, refer to
          files of type symbolic link.




          Thus



          $ pwd -P


          should be what you need.






          share|improve this answer




















          • I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
            – Chud37
            Mar 9 at 14:52












          up vote
          60
          down vote










          up vote
          60
          down vote









          According to the POSIX manpage for pwd, the -P option may be of use:




          -P The absolute pathname written
          shall not contain filenames that, in
          the context of the pathname, refer to
          files of type symbolic link.




          Thus



          $ pwd -P


          should be what you need.






          share|improve this answer












          According to the POSIX manpage for pwd, the -P option may be of use:




          -P The absolute pathname written
          shall not contain filenames that, in
          the context of the pathname, refer to
          files of type symbolic link.




          Thus



          $ pwd -P


          should be what you need.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 2 '11 at 18:44









          Steven D

          31.6k696108




          31.6k696108











          • I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
            – Chud37
            Mar 9 at 14:52
















          • I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
            – Chud37
            Mar 9 at 14:52















          I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
          – Chud37
          Mar 9 at 14:52




          I would like to point out that this information is easily found by typing man pwd in shell to find out options for this command.
          – Chud37
          Mar 9 at 14:52












          up vote
          7
          down vote













          The pwd shell built-in uses the path the shell keeps track of when you cd (and stores it in $PWD). This means if you have a symlink to a complex (deep) path, it will tell you what you typed to change to that directory instead of the real path. This is done to give you what you want most of the time.



          /bin/pwd uses the getcwd system call (which these days is a library call, reading /proc/self/cwd) which returns the canonical path for the current directory, sans all symlink traversals.



          As Steven D pointed out, pwd has the -P option to ignore $PWD. It also has the -L option to return the contents of $PWD. The man page for pwd does not say which option is used by default but experience tells me the above description is correct (shell pwd vs. /bin/pwd). However you should probably not rely on that and just use pwd -P.






          share|improve this answer


















          • 2




            The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
            – Stéphane Chazelas
            Dec 2 '12 at 20:10














          up vote
          7
          down vote













          The pwd shell built-in uses the path the shell keeps track of when you cd (and stores it in $PWD). This means if you have a symlink to a complex (deep) path, it will tell you what you typed to change to that directory instead of the real path. This is done to give you what you want most of the time.



          /bin/pwd uses the getcwd system call (which these days is a library call, reading /proc/self/cwd) which returns the canonical path for the current directory, sans all symlink traversals.



          As Steven D pointed out, pwd has the -P option to ignore $PWD. It also has the -L option to return the contents of $PWD. The man page for pwd does not say which option is used by default but experience tells me the above description is correct (shell pwd vs. /bin/pwd). However you should probably not rely on that and just use pwd -P.






          share|improve this answer


















          • 2




            The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
            – Stéphane Chazelas
            Dec 2 '12 at 20:10












          up vote
          7
          down vote










          up vote
          7
          down vote









          The pwd shell built-in uses the path the shell keeps track of when you cd (and stores it in $PWD). This means if you have a symlink to a complex (deep) path, it will tell you what you typed to change to that directory instead of the real path. This is done to give you what you want most of the time.



          /bin/pwd uses the getcwd system call (which these days is a library call, reading /proc/self/cwd) which returns the canonical path for the current directory, sans all symlink traversals.



          As Steven D pointed out, pwd has the -P option to ignore $PWD. It also has the -L option to return the contents of $PWD. The man page for pwd does not say which option is used by default but experience tells me the above description is correct (shell pwd vs. /bin/pwd). However you should probably not rely on that and just use pwd -P.






          share|improve this answer














          The pwd shell built-in uses the path the shell keeps track of when you cd (and stores it in $PWD). This means if you have a symlink to a complex (deep) path, it will tell you what you typed to change to that directory instead of the real path. This is done to give you what you want most of the time.



          /bin/pwd uses the getcwd system call (which these days is a library call, reading /proc/self/cwd) which returns the canonical path for the current directory, sans all symlink traversals.



          As Steven D pointed out, pwd has the -P option to ignore $PWD. It also has the -L option to return the contents of $PWD. The man page for pwd does not say which option is used by default but experience tells me the above description is correct (shell pwd vs. /bin/pwd). However you should probably not rely on that and just use pwd -P.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 4 '11 at 22:04

























          answered Feb 2 '11 at 22:35









          camh

          24.1k66252




          24.1k66252







          • 2




            The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
            – Stéphane Chazelas
            Dec 2 '12 at 20:10












          • 2




            The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
            – Stéphane Chazelas
            Dec 2 '12 at 20:10







          2




          2




          The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
          – Stéphane Chazelas
          Dec 2 '12 at 20:10




          The behavior you describe is the one on Linux systems where /bin/pwd is GNU pwd when POSIXLY_CORRECT is not set. On POSIX systems where the pwd is in /bin. /bin/pwd will use $PWD and may return paths with symlinks. GNU pwd will behave in that POSIX manner when it find a POSIXLY_CORRECT variable in its environment.
          – Stéphane Chazelas
          Dec 2 '12 at 20:10

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f6800%2fpwd-without-symlinks%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

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay