ORIGIN

Absolute path and Relative path

Linux 1 min145 words

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

TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|