Search code examples
unixcommand-line-argumentscd

Regarding the cd command in UNIX


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.


Solution

  • If you create a symbolic link to directory "d" in the directory below b:

    e.g.

    /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.