{"id":12155,"date":"2019-03-22T12:48:45","date_gmt":"2019-03-22T12:48:45","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12155"},"modified":"2019-03-22T12:48:45","modified_gmt":"2019-03-22T12:48:45","slug":"how-to-identify-working-directories-using-shell-characters-and-variables","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/how-to-identify-working-directories-using-shell-characters-and-variables\/","title":{"rendered":"How to Identify Working Directories Using Shell Characters and Variables"},"content":{"rendered":"<p>Some of the special directories that a Linux user is bound to work with so many times on a shell command line include the user\u2019s\u00a0<strong>home<\/strong>\u00a0directory, the current and previous working directories.<\/p>\n<p>Therefore, understanding how to easily access or pinpoint these directories using certain unique methods can be a bonus skill for a new or any Linux user.<\/p>\n<div id=\"attachment_22166\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Find-Linux-Working-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22166\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Find-Linux-Working-Directory.png\" alt=\"Identify Working Directories Using Shell Characters and Environment Variables\" width=\"720\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Identify Working Directories Using Shell Characters and Environment Variables<\/p>\n<\/div>\n<p>In this tips for newbies, we shall look at ways of how a user can identify his\/her home, current and previous working directories from the shell using special shell characters and environment variables.<\/p>\n<h3>1. Using Specific Shell Characters<\/h3>\n<p>There are certain specific characters that are understood by the shell when we are dealing with directories from the command line. The first character we shall look at is the\u00a0<code>tilde (~)<\/code>: it is used to access the current user\u2019s home directory:<\/p>\n<pre>$ echo ~\r\n<\/pre>\n<div id=\"attachment_22157\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/use-tilde-character.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22157\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/use-tilde-character.png\" alt=\"Display User Home Directory\" width=\"339\" height=\"53\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Display User Home Directory<\/p>\n<\/div>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">Learn \u2018echo\u2019 Command with This 15-Practical Examples<\/a><\/p>\n<p>The second is the dot\u00a0<code>(.)<\/code>\u00a0character: it represents the current directory that a user is in, on the command line. In the screen shot below, you can see that the command\u00a0<code>ls<\/code>\u00a0and\u00a0<code>ls .<\/code>\u00a0produce the same out put, listing the contents of the current working directory.<\/p>\n<pre>$ ls\r\n$ ls .\r\n<\/pre>\n<div id=\"attachment_22158\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/List-Content-of-Current-Working-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22158\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/List-Content-of-Current-Working-Directory.png\" alt=\"List Contents of Current Working Directory\" width=\"517\" height=\"206\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Contents of Current Working Directory<\/p>\n<\/div>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/15-basic-ls-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">Master \u2018ls\u2019 Command with This Basic 15-Practical Examples<\/a><\/p>\n<p>The third special characters are the double dots\u00a0<code>(..)<\/code>\u00a0which represent the directory directly above the current working directory that a user is in.<\/p>\n<p>In the image below, the directory above\u00a0<code>\/var<\/code>\u00a0is the root directory\u00a0<code>(\/)<\/code>, so when we use the\u00a0<code>ls<\/code>\u00a0command as follows, the contents of\u00a0<code>(\/)<\/code>\u00a0are listed:<\/p>\n<pre>$ ls ..\r\n<\/pre>\n<div id=\"attachment_22159\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-Contents-of-Parent-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22159\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-Contents-of-Parent-Directory.png\" alt=\"Print Contents of Parent Directory\" width=\"527\" height=\"111\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Print Contents of Parent Directory<\/p>\n<\/div>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-ls-command-tricks\/\" target=\"_blank\" rel=\"noopener\">7 Quirky \u2018ls\u2019 Command Tricks Every Linux User Should Know<\/a><\/p>\n<h3>2. Using Environmental Variables<\/h3>\n<p>Apart from the characters above, there are also certain\u00a0<strong>environmental variables<\/strong>\u00a0meant to work with the directories we are focusing on. In the next section, we shall walk through some of the important environmental variables for identifying directories from the command line.<\/p>\n<p><code>$HOME<\/code>: its value is the same as that of the\u00a0<code>tilde (~)<\/code>\u00a0character \u2013 the current user\u2019s home directory, you can test that by using the\u00a0<a href=\"https:\/\/www.tecmint.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">echo command<\/a>\u00a0as follows:<\/p>\n<pre>$ echo $HOME\r\n<\/pre>\n<div id=\"attachment_22160\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-User-Home-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22160\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-User-Home-Directory.png\" alt=\"Print User Home Directory\" width=\"493\" height=\"74\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Print User Home Directory<\/p>\n<\/div>\n<p><code>$PWD<\/code>: in full, it stands for \u2013\u00a0<strong>Print Working Directory<\/strong>\u00a0(<strong>PWD<\/strong>), as the name implies, it prints the absolute path of the current working directory in the shell command line as below:<\/p>\n<pre>$ echo $PWD \r\n<\/pre>\n<div id=\"attachment_22161\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-Present-Working-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22161\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-Present-Working-Directory.png\" alt=\"Print Present Working Directory\" width=\"501\" height=\"75\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Print Present Working Directory<\/p>\n<\/div>\n<p><code>$OLDPWD<\/code>: it points to the directory a user was in, just before moving to the current working directory. You can access its value as below:<\/p>\n<pre>$ echo $OLDPWD\r\n<\/pre>\n<div id=\"attachment_22162\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-Parent-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22162\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Print-Parent-Directory.png\" alt=\"Print Parent Directory\" width=\"419\" height=\"76\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Print Parent Directory<\/p>\n<\/div>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/pwd-command-examples\/\" target=\"_blank\" rel=\"noopener\">15 \u2018pwd\u2019 (Print Working Directory) Command Examples in Linux<\/a><\/p>\n<h3>3. Using Simple cd Commands<\/h3>\n<p>Additionally, you can also run some simple commands to quickly accessing your home directory and previous working directory. For example, when you are in any part of your file system on the command line, typing\u00a0<code>cd<\/code>and hitting\u00a0<strong>Enter<\/strong>\u00a0will move you to your home directory:<\/p>\n<pre>$ echo $PWD\r\n<strong>$ cd<\/strong>\r\n$ echo $PWD\r\n<\/pre>\n<div id=\"attachment_22163\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Switch-to-User-Home-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22163\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Switch-to-User-Home-Directory.png\" alt=\"Switch to User Home Directory\" width=\"411\" height=\"164\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Switch to User Home Directory<\/p>\n<\/div>\n<p>You can also move to the previous working directory using the command\u00a0<code>cd -<\/code>\u00a0command as below:<\/p>\n<pre>$ echo $PWD\r\n$ echo $OLDPWD\r\n<strong>$ cd -<\/strong> \r\n$ echo $PWD\r\n<\/pre>\n<div id=\"attachment_22164\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Switch-Previous-Working-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22164\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/08\/Switch-Previous-Working-Directory.png\" alt=\"Switch to Previous Working Directory\" width=\"464\" height=\"173\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Switch to Previous Working Directory<\/p>\n<\/div>\n<p>In this post, we moved through some simple yet\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-tricks\/\" target=\"_blank\" rel=\"noopener\">useful command line tips<\/a>\u00a0for new Linux users to identify certain special directories from within the shell command line.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/identify-working-directories-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some of the special directories that a Linux user is bound to work with so many times on a shell command line include the user\u2019s\u00a0home\u00a0directory, the current and previous working directories. Therefore, understanding how to easily access or pinpoint these directories using certain unique methods can be a bonus skill for a new or any &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/how-to-identify-working-directories-using-shell-characters-and-variables\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Identify Working Directories Using Shell Characters and Variables&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12155","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12155"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12155\/revisions"}],"predecessor-version":[{"id":12156,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12155\/revisions\/12156"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}