How to express relative paths in Linux

How to express relative paths in Linux

For example, if your current path is /var/log and you want to go to the /usr directory, you can execute the following command:

cd ../../usr #Use the relative path to first exit to the /var directory, then exit to /, and finally enter /usr

The paths are relative to the current directory.

../ # indicates the parent directory

./ # indicates the current directory

./XXX # indicates the XXX file or XXX directory in the current directory

Using relative paths does not necessarily require backing into a directory.

If the current path is /var/log, you want to go to /var/run/

cd ../run #First exit to the /var directory, then enter the run directory under the /var directory

Knowledge point expansion:

Uses of relative paths

So what's the big deal about relative paths and absolute paths? drink! That's really amazing! Suppose you have written a software that requires three directories, namely etc, bin, and man. However, different people like to install the software in different directories. Suppose Person A installs the software in /usr/local/packages/etc, /usr/local/packages/bin, and /usr/local/packages/man, but Person B likes to install the software in /home/packages/etc, /home/packages/bin, and /home/packages/man. If absolute paths are required, will it be troublesome? Yes! In this way, it is difficult to match the contents in each directory! At this time, the writing of relative paths is particularly important!

In addition, if you are like me, and like to write long path names so that you know what the directory is for, for example: the directory /cluster/raid/output/taiwan2006/smoke, and another directory is /cluster/raid/output/taiwan2006/cctm, then if I want to go from the first to the second directory, how should I write it more conveniently? Of course cd.../cctm is more convenient! Right!

Purpose of absolute path

However, regarding the correctness of the file name, "the accuracy of the absolute path is better~". Generally speaking, I would recommend that you use absolute paths when writing shell scripts to manage your system. How to say it? Although it is more troublesome to write an absolute path, it is certain that there will be no problem with this writing method. If you use relative paths in your program, some problems may occur due to the different working environments you are running in.

This is the end of this article about how to represent relative paths in Linux. For more information about how to represent relative paths in Linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  js realizes the effect of Tanabata confession barrage, jQuery realizes barrage technology

>>:  MySQL 8.0.18 installation and configuration method graphic tutorial (linux)

Recommend

Detailed explanation of long transaction examples in MySQL

Preface: The "Getting Started with MySQL&quo...

Let's learn about JavaScript object-oriented

Table of contents JavaScript prototype chain Obje...

Implementing simple chat room dialogue based on websocket

This article shares the specific code for impleme...

Docker deployment springboot project example analysis

This article mainly introduces the example analys...

The Complete Guide to Grid Layout in CSS

Grid is a two-dimensional grid layout system. Wit...

echars 3D map solution for custom colors of regions

Table of contents question extend Solving the pro...

Ubuntu 18.04 MySQL 8.0 installation and configuration method graphic tutorial

This article shares the installation and configur...

How to install MySQL 5.7.28 binary mode under CentOS 7.4

Linux system version: CentOS7.4 MySQL version: 5....

Vue implements tab label (label exceeds automatic scrolling)

When the created tab label exceeds the visible ar...

MySQL 8.0.12 Simple Installation Tutorial

This article shares the installation tutorial of ...

Basic tutorial on controlling Turtlebot3 mobile robot with ROS

Chinese Tutorial https://www.ncnynl.com/category/...

Detailed explanation of three ways to set borders in HTML

Three ways to set borders in HTML border-width: 1...

How to use React to implement image recognition app

Let me show you the effect picture first. Persona...

Related commands to completely uninstall nginx under ubuntu16.04

nginx Overview nginx is a free, open source, high...