I am trying to figure out in what condition would two different cd commands lead to the same directory. For example: Under what condition do both cd /b/c/d/e and cd d/e change to the same directory?
Could someone help me with this as I do not quite understand how to figure this out.
Say you are at the pwd
(present working directory) of /b/c
Then cd /b/c/d/e
will bring you to the same location as cd d/e
In the first you are defining the absolute path, whereas in the second you are defining the relative path.
Let's see the examples:
cd b/c/d/e
cd d/e
Both of them are using relative paths to e/ In fact, we can assume that in the seconds one, you are in the directory c
When I say relative path, it's because you don't have a / at the beggining of the path, and it means that cd will look for the path you're providing, from your current directory ( . or $PWD ).
cd ./b/c/d/e
cd ./d/e
or
cd "$PWD"/b/c/d/e
cd "$PWD"/d/e
You can get your current directory with the pwd
command. It will give you the value of the PWD environment variable
If you create a symbolic link to directory "d" in the directory below b:
eg
/temp/b/c/d/e is the directory structure
cd /temp
ln -s /temp/b/c/d
now inside of temp you will have two directories, one real and one a symbolic link to d.
/temp$ ls -al
total 12
drwxrwxr-x 3 temp temp 4096 Oct 5 18:25 .
drwxr-xr-x 34 temp temp 4096 Oct 5 18:24 ..
drwxrwxr-x 3 temp temp 4096 Oct 5 18:24 b
lrwxrwxrwx 1 temp temp 20 Oct 5 18:25 d -> /temp/b/c/d
and you can do
cd b/c/d/e
or
cd d/e
and get to the same directory.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.