Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 7827  / 2 Years ago, fri, december 3, 2021, 4:31:02

What do these two commands mean?



cd ../


cd /..


I am ending up in two directories upwards the tree on the first command and in the root directory from the second command. Why does that happen?


More From » filesystem

 Answers
1

A / at the end of the name of a directory/folder is optional. Most of the time, including or omitting the final slash in a directory name does not change the effect of a command.



So cd ../ is equivalent to cd ...



Paths that don't start with a / are relative paths; they are resolved relative to the current directory.



Every directory has two special entries:




  • a directory entry called . that resolves to the directory itself

  • a directory entry called .. that resolves to the directory's parent (i.e., the directory that contains that directory)



Therefore cd ../ and cd .. change directory to the parent of the current directory. Thus, if you start out in /home/fazlan and run cd .. or cd ../, you'll end up in /home.



In contrast, /.. is an absolute path (albeit an unusual one). / is the filesystem root--the directory you get to if you go up in the directory hierarchy all the way. (Using the same parent and child metaphor, we say / is the ancestor of everything in the filesystem.)



Since .. means "the parent directory of this directory" and / means "the top of the filesystem," /.. means "the parent directory of the top of the filesystem."



But what does it mean to talk about the directory that contains /? Well, / is an exception. Since no directory contains it, we say that /'s parent is itself. Therefore, in /, .. is /. Consequently, /.. is the same as /.



This is why cd ../ brings you up one directory from where you started, while cd /.. brings you to the very top. More elegant and easily read ways to do these things are cd .. and cd /, respectively.


[#31917] Saturday, December 4, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lowstonnequ

Total Points: 279
Total Questions: 125
Total Answers: 123

Location: Finland
Member since Sun, Dec 5, 2021
2 Years ago
;