-1

I saw some shell scripts that cd into some file path that starts with an alias and have /../../ in between, for example: $exampleroot/../../folder/subfolder/filename.zip

i understand that /../ means root path but what does this /../../ refer to? does it mean capturing all misc sub folders in between regardless of the folders name?

Thanks

unacorn
  • 827
  • 10
  • 27
  • .. is the parent directory. ../.. is the grandparent. – Shawn May 22 '22 at 05:45
  • Perhaps see also [Difference between `./` and `~/`](https://stackoverflow.com/a/55342466/874188) which discusses the actual differences between absolute and relative paths, and thus the definition of the filesystem root. – tripleee May 22 '22 at 07:19

2 Answers2

2

An example might help. Suppose $exampleroot is /one/two/three/four (and this is a directory). Then:

  • $exampleroot/.. is equivalent to /one/two/three
  • $exampleroot/../.. is /one/two
  • $exampleroot/../../folder is /one/two/folder
  • $exampleroot/../../folder/subfolder/filename.zip is /one/two/folder/subfolder/filename.zip

(Note: If /one/two/three/four is not a directory, then /one/two/three/four/.. is not a valid path. And there are some weird exceptions if there's something like a symbolic link in the path, because going up a level in the directory hierarchy is not the same as un-following a symbolic link.)

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
1

.. means the parent directory, i.e. the one that contains $exampleroot. ../../ is therefore two levels up:

$ pwd
/tmp
$ mkdir -pv foo/bar
mkdir: created directory 'foo/bar'
$ cd foo/bar/
$ pwd
/tmp/foo/bar
$ cd ../..
$ pwd
/tmp
ndc85430
  • 1,395
  • 3
  • 11
  • 17
  • i understand that .. is parent directory but i am confused when it all put together. why do they still put the $exampleroot in front? do you mean with that they are referring to the folders 2 levels up within the $exampleroot path? for e.g. if $exampleroot is "/home/user/abc/def/ghi, then $exampleroot/../../ means /home/user/abc? – unacorn May 22 '22 at 06:03
  • 1
    Well, `..` is the parent directory of `$exampleroot` of course. It's a relative path, not an absolute one. So after you edited that comment: yes. You can of course try this on the command line to check your understanding. – ndc85430 May 22 '22 at 06:05
  • good point thanks for clarifying! – unacorn May 22 '22 at 06:14