There are two ways to represents a directory, Absolute path and Relative path.
path | start | start sign |
---|---|---|
Absolute | root directory | / |
Relative | current directory | ~ |
For example, when I open the terminal at first time, the default directory is /home/user
I want to see the folder “name1” under /user/names
1 | cd /home/user/names/name1 // Absolute |
or type
1 | cd names/name1 |
Now we are at name1, and we want to go to name2 at /user/names/name2
1 | cd ../names2 |
.. represents the previous one directory of the current directory.
If I’m at names2, then “..” is names.
1 | pwd // to check your current directory |
1 | cd ~ // goes back to /home/user |
to return the last directory(the one that your last command affect on)
1 | cd - |
It will also show it’s physical path. Like ~/Yao/Study/Blog
Or you can use
1 | cd $OLDPWD |
It’s the same to cd -.