{"id":3212,"date":"2018-04-03T17:50:46","date_gmt":"2018-04-03T13:50:46","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-pwd-command\/"},"modified":"2018-04-03T17:50:46","modified_gmt":"2018-04-03T13:50:46","slug":"linux-pwd-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-pwd-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux pwd Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<div><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-pwd-command-tutorial-for-beginners-with-examples.gif\" class=\"ff-og-image-inserted\" alt=\"\" title=\"\"><\/div>\n<p>The pwd command, like ls and cd, is one of most frequently used Linux utilities. Regardless of the kind of user you are (newbie or pro), you&#8217;ll find yourself using this command line tool a lot. So in this tutorial, we will quickly discuss the basics of pwd through some easy to understand examples.<\/p>\n<p>But before we start doing that, it&#8217;s worth mentioning that all examples presented in this article have been tested on Ubuntu 16.04LTS.<\/p>\n<h2 id=\"linux-pwd-command\">Linux pwd command<\/h2>\n<p>The pwd tool prints the name of the present\/current working directory (PWD &#8211; Present Working Directory, got it?). Following is its syntax:<\/p>\n<p class=\"command\">pwd [OPTION]&#8230;<\/p>\n<p>And here&#8217;s how the utility&#8217;s man page describes it:<\/p>\n<pre>Print the full filename of the current working directory.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea of how the pwd command works.<\/p>\n<h2 id=\"q-how-pwd-command-works\">Q1. How pwd command works?<\/h2>\n<p>The basic usage, as is usually the case, is very easy. All you have to do is to run the &#8216;pwd&#8217; command without any options, and you&#8217;ll get the full path to the current working directory in output.<\/p>\n<p class=\"command\">pwd<\/p>\n<p>Here&#8217;s an example:<\/p>\n<pre><a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"b6dedfdbd7d8c5dec3f6d7d8c5de\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>:~$ pwd<br\/>\/home\/himanshu<\/pre>\n<p>It&#8217;s worth mentioning that most shells, including bash, have pwd built-in. Just execute the following command:<\/p>\n<p class=\"command\">type -a pwd<\/p>\n<p>And you should get the following output.<\/p>\n<pre>pwd is a shell builtin<br\/>pwd is \/bin\/pwd<\/pre>\n<h2 id=\"q-what-is-the-difference-between-pwd-and-binpwd\">Q2. What is the difference between pwd and \/bin\/pwd?<\/h2>\n<p>Well, pwd is a shell built-in, while \/bin\/pwd is the tool that comes with your Linux distribution. PWD&#8217;s man page explains it clearly:<\/p>\n<pre>NOTE: Your shell may have its own version of pwd, which usually supersedes the version described <br\/>here. Please refer to your shell's documentation for details about the options it supports.<\/pre>\n<h2 id=\"q-how-to-make-pwd-use-pwd-from-environment\">Q3. How to make pwd use PWD from environment?<\/h2>\n<p>This can be done using the <strong>-L<\/strong> command line option. To test this, create a symlink to the current directory (\/home\/himanshu in my case).<\/p>\n<p>For example:<\/p>\n<p class=\"command\">ln -s . dir_symlink<\/p>\n<p>and then enter it:<\/p>\n<p class=\"command\">cd dir_symlink<\/p>\n<p>Now, run the following command:<\/p>\n<p class=\"command\">\/bin\/pwd<\/p>\n<p>In my case, the got the following output:<\/p>\n<pre>\/home\/himanshu<\/pre>\n<p>Next, execute this command<\/p>\n<p class=\"command\">\/bin\/pwd -L<\/p>\n<p>I got the following output:<\/p>\n<pre>\/home\/himanshu\/dir_symlink<\/pre>\n<h2 id=\"q-how-to-make-pwd-avoid-all-symbolic-links\">Q4. How to make pwd avoid all symbolic links?<\/h2>\n<p>This can be done using the <strong>-P<\/strong> command line option. For example:<\/p>\n<p class=\"command\">\/bin\/pwd -L<\/p>\n<p>produces the following output:<\/p>\n<pre>\/home\/himanshu\/dir_symlink<\/pre>\n<p>But with -P<\/p>\n<p class=\"command\">\/bin\/pwd -L -P<\/p>\n<p>the output is:<\/p>\n<pre>\/home\/himanshu<\/pre>\n<p>It&#8217;s worth mentioning that If no option is specified, -P is assumed by default.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>So you can see, pwd is a fairly easy command line tool to understand and use. Mostly, you&#8217;ll find yourself using sans any option, but it&#8217;s good to know what all options it offers. For more info on pwd, head to its man page <a href=\"https:\/\/linux.die.net\/man\/1\/pwd\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The pwd command, like ls and cd, is one of most frequently used Linux utilities. Regardless of the kind of user you are (newbie or pro), you&#8217;ll find yourself using this command line tool a lot. So in this tutorial, we will quickly discuss the basics of pwd through some easy to understand examples. But &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3212","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3212"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3212\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}