01. Overview Absolute paths and relative paths are often encountered in shell environments, and each has its own uses. Sometimes relative paths are more convenient, and sometimes absolute paths are more convenient. 02. Absolute Pathname An absolute path must start with **/** The absolute path points to the location of the file/file. At any time, we can use the absolute path to find the file we want Example Example 1: /home/deng Example 2: /usr/share/man 03. Relative Pathnames Relative paths do not start with **/** The relative path is relative to the current location and points to the destination. Usually a relative path is shorter than an absolute path and can be used as a shortcut to quickly find files/files. Example 1: ../test/itcast Example 2: ./test 04. Purpose 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! 05. 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. 06. Divergent thinking Question: When a relative path is given, how does the system identify its corresponding absolute path? In fact, the relative path is based on the PATH environment variable to find the absolute path. For example, I am currently in /home/itcast, the home directory of the itcast user. I want to view the data of the .bashrc file in it, using the more command, which is in /bin/more. The usual command writing is: [itcast@localhost ~]$ more .bashrc And since the value of the PATH variable is: [deng@localhost ~]$ echo $PATH /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/deng/.local/bin:/home/deng/bin [deng@localhost ~]$ When executing the more command, the shell will search sequentially according to the path of the PATH variable. Once a match is found (in this case, the match should be /bin/more), /bin/more .bashrc will be executed. This is the process of searching for the absolute path from the relative path when executing a command. So we can understand why the format for executing the executable program in the current directory should be: [deng@localhost ~]$ ./test.sh Instead of using test.sh directly. Because usually the PATH variable does not contain the current path. If ./ is not added, the command in relative path format will not be able to find the absolute path. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
>>: How to use anti-shake and throttling in Vue
The pre element defines preformatted text. Text en...
Table of contents Preface: Ubuntu 18.04 changes a...
The installation process is omitted (I installed ...
The MySQL query result row field splicing can be ...
The complete steps of Centos7 bridge network conf...
Table of contents 1. The simplest example 2. Cust...
Docker daemon socket The Docker daemon can listen...
People who often use MySQL may encounter the foll...
Table of contents question Server layer and stora...
1. Introduction to Macvlan Before the emergence o...
Table of contents 1: Single machine password-free...
MySQL is an open source, small relational databas...
All blogs listed below are original and uniquely ...
I encountered this problem before when developing...
<br />User experience is increasingly valued...