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

Vue implements the method example of tab routing switching component

Preface This article introduces the use of vue-ro...

WeChat applet canvas implements signature function

In the WeChat applet project, the development mod...

Two ways to create SSH server aliases in Linux

Preface If you frequently access many different r...

Notes on element's form components

Element form and code display For details, please...

HTML form_PowerNode Java Academy

1. Form 1. The role of the form HTML forms are us...

MySQL multi-instance deployment and installation guide under Linux

What is MySQL multi-instance Simply put, MySQL mu...

JavaScript Basics: Error Capture Mechanism

Table of contents Preface Error Object throw try…...

Vue calls the PC camera to realize the photo function

This article example shares the specific code of ...

Getting Started with Mysql--sql execution process

Table of contents 1. Process 2. Core Architecture...

Detailed explanation of the TARGET attribute of the HTML hyperlink tag A

The hyperlink <a> tag represents a link poin...

An article tells you how to implement Vue front-end paging and back-end paging

Table of contents 1: Front-end handwritten paging...

Introduction to the use of this in HTML tags

For example: Copy code The code is as follows: <...

mysql query data for today, this week, this month, and last month

today select * from table name where to_days(time...

TypeScript Mapping Type Details

Table of contents 1. Mapped Types 2. Mapping Modi...