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
Published 2023-10-04 |
$1.00 CAD |
Intro To 'nproc' Command In Linux
Published 2023-07-15 |
Intro To 'comm' Command In Linux
Published 2023-09-06 |
How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
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
Published 2019-08-01 |
Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|