Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between linux absolute path and relative path

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you what is the difference between the absolute path and the relative path of linux, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In linux, the difference between an absolute path and a relative path is that the absolute path starts from the lowest root directory "/" in the linux, absolutely starting with "/" as the path, while the relative path starts with the path relative to the current location, not with "/" as the beginning of the path.

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

The difference between absolute path and relative path in linux

In Linux systems, the absolute path must start with the root directory / start.

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

So, to make a simple judgment, if the path after a command begins with /, it is an absolute path, no, or relative path. For example, cd / home/test, / home/test is the absolute path; cd test, test refers to the test directory under the current working directory, that is, the relative path.

The relative path starts to calculate relative to your current path.

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

Among them: in Linux, the absolute path starts from / (root directory), and the absolute path is preceded by /.

The relative path is entered directly into the folder under the current path or as. Or; or It started to count. Indicates the location of the user's current operation. Represents the directory at the previous level.

For example:

/ home/oracle this path is the absolute path

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

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

Pay attention to the comparison of the latter two. Is to go back to the next level and calculate later.

Use the pwd command to see the absolute path you are currently in.'

For the questions raised in the question, the answers are as follows:

Since it is not clear which path the relative path is relative to, it is under the / directory by default.

Jump from usr/bin to / home/staff/john/project with relative pathname

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

Jump from usr/bin to / temp with absolute pathname

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

Jump from usr/bin to / etc/rc.d with relative pathname

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

Jump path can be entered directly into absolute path

The above is all the content of the article "what is the difference between the absolute path and the relative path of linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report