What is the difference between absolute path and relative path in linux

WBOY
Release: 2022-03-11 11:50:58
Original
19527 people have browsed it

The difference between absolute paths and relative paths in Linux is: the absolute path starts from the bottom root directory "/" in Linux, and definitely starts with "/"; while the relative path is The path is calculated relative to the current position, not starting with "/".

What is the difference between absolute path and relative path in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the difference between absolute paths and relative paths in Linux

In Linux systems, absolute paths must start from the root directory /.

The relative path is not written from the root directory / , but from the current working directory (you can use the pwd command to view the current working directory).

So, a simple judgment, if the path after a command starts with /, it is an absolute path, otherwise, it is a relative path. For example, cd /home/test, /home/test is an absolute path; cd test, test refers to the test directory under the current working directory, which is a relative path.

The relative path is calculated relative to the current path you are on.

The absolute path is calculated from the bottom root (/) of Linux.

Among them: In Linux, the absolute path starts from / (root directory). If the path starts with /, it is an absolute path.

The relative path is calculated by directly entering the folder under the current path or starting with . or .. , . represents the location where the user is currently operating, and .. represents the upper-level directory.

For example:

/home/oracle This path is an absolute path

./home/oracle This is a relative path. For example, under the /test path, this The path converted to an absolute path is /test/home/oracle

../home/oracel. This is also a relative path. For example, under the /test path, this path converted to an absolute path is: /home/ oracel

Pay attention to the comparison of the last two,...it is to return to the previous level and then calculate backward.

Use the pwd command to view the current absolute path. ‘

As the question raised in the title, the answer is as follows:

Since it is not clear which path the relative path is relative to, the default here is in the / directory.

Use relative path name to jump from usr/bin to /home/staff/john/project

Answer: cd ../../home/staff/john/project or cd /home /staff/john/project

Use absolute path name to jump from usr/bin to /temp

Answer: cd ../../temp or cd /temp

Use relative path name to jump from usr/bin to /etc/rc.d

Answer: cd ../../etc/rc.d or cd /etc/rc.d

Jump The path can be directly entered as an absolute path

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the difference between absolute path and relative path in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template