Home  >  Article  >  System Tutorial  >  Commonly used CentOS directory processing commands

Commonly used CentOS directory processing commands

WBOY
WBOYforward
2024-01-05 15:11:471019browse

Relative path and absolute path

Absolute path: The path must be written starting from the root directory /, such as the directory /usr/share/doc.

Relative path: The path is written not starting with /. For example, when going from /usr/share/doc to /usr/share/man, it can be written as "cd ../man". This is how the relative path is written. . Relative paths are always relative to the current working path.

For the correctness of the file name, the correctness of the absolute path is better. When writing programs (shell scripts) to manage the system, be sure to use absolute paths. If you use relative paths in the program, some problems may occur due to the different working environment you are executing.

Directory related operations

Several common commands for processing directories:

 * cd: switch directory

 *pwd: Display the current directory

 *mkdir: Create a new directory

*rmdir: delete an empty directory

 cd(Change Directory)

 .   Represents this layer directory

.. Represents the upper level directory

 -  Represents the previous working directory

 ~  Represents the main folder where the "current user identity" is located

~account represents the home folder of the user account

 pwd(Display current directory, Print Working Directory)

-p Display the current path instead of using the connection path

When we use this command, we can add the -p parameter, which allows us to get the correct directory name instead of displaying it as the path to the connection file.

 mkdir (create a new directory, make directory)

 -m Forced to grant a new directory-related permissions Example: mkdir -m 711 test

 -p  Helps you directly create the required directories (including upper-level directories) recursively. Example: mkdir test1/test2

 rmdir (delete "empty" directory, remove directory)

 -p  The empty upper directory will also be deleted

 -r  Delete all files in the directory together. Example: rm -r test

About the variable of the execution file path: $PATH

Why can I execute the /bin/ls command anywhere? Why can some information be displayed when I enter ls in any directory without saying that the /bin/ls command cannot be found? This is because of the help of the environment variable PATH.

When we execute a command, for example "ls", the system will query the directory defined by PATH for the executable file named ls according to the PATH setting. If the directory contains multiple executable files named ls, the command with the same name found in the query will be executed first.

Execute the "echo $PATH" command ($ is followed by a variable) to display all configured PATH directories. "PATH="$PATH":/root", add the /root directory to the PATH variable

The above is the detailed content of Commonly used CentOS directory processing commands. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete