Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'pwd' Command In Linux

2023-04-27 - By Robert Elder

     I use the 'pwd' command to print the current working directory:

cd /home/robert/important
pwd

     Outputs:

/home/robert/important

     The current working directory is one of the most important aspects of using a command-line environment.  The 'pwd' command, as well as the '$PWD' variable will both show you the current working directory:

pwd
echo $PWD

     Outputs:

/home/robert/important
/home/robert/important

     Let's set up some example files and directories to illustrate some uses of the 'pwd' command:

mkdir files
ln -s files indirect-dir
touch files/README.txt
touch files/foo.jpg
touch foo.txt

     Anytime that you specify a relative file name on the command line, it's usually assumed that the full path of the file will be relative to the current working directory.

ls foo.txt

     Outputs:

foo.txt

     If we check the status of all files in the current directory using this command:

ls -latr

     the output is the following:

total 12
drwxr-xr-x 49 robert robert 4096 Apr 28 20:44 ..
lrwxrwxrwx  1 robert robert    5 Apr 28 23:16 indirect-dir -> files
drwxrwxr-x  2 robert robert 4096 Apr 28 23:16 files
-rw-rw-r--  1 robert robert    0 Apr 28 23:20 foo.txt
drwxrwxr-x  3 robert robert 4096 Apr 28 23:20 .

     Note that the 'indirect-dir' is actually a symlink that points to a directory.  Let's move into that symlink:

cd indirect-dir

     I can use the '-P' flag to show the physical path:

pwd -P

     and the output is:

/home/robert/important/files

     I can also use the '-L' flag to show the logical path:

pwd -L

     and the output is:

/home/robert/important/indirect-dir

     These two paths usually have the same value but they can be different if the path includes symlinks.

     And that's why the 'pwd' command is my favorite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use