In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the file system path in the Linux system". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the file system path in the Linux system".
1. The Linux file system starts from /
In the file management of Linux operating system, the file or directory management in command line mode (under console or terminal) involves the concept of path, which is the most basic basis of Linux command line operation. If we understand the concept of path, we can go to any directory and do what we want.
Linux file system, is a tree structure, is from as an entry, / (also known as the root directory) there are subdirectories, such as etc, usr, lib, etc., in each subdirectory there are files or subdirectories, so that the formation of a tree structure, this tree structure is relatively simple. What about the Windows file system? It introduces the similar disk concept of C disk and D disk, so that when users who are used to Windows operation turn to Linux, they will find that Linux has no concept of C disk and D disk at all, and sometimes they don't even know what to do.
2. The purpose of understanding the concept of path
The ultimate purpose of introducing the concept of path is to find the directory or file we need. For example, if we want to edit a file.txt file, we first need to know where it is stored, that is, we need to point out his location, and then we need to use the path.
3. The elements of the path.
The path is made up of directories or directories and file names. For example, / etc/X11 is a path, and / etc/X11/xorg.conf is also a path. In other words, the path can be a combination of directories, graded into it, or it can be composed of records and files. For example, if we want to edit the xorg.conf file with vi, type vi / etc/X11/xorg.conf at the command line, and if we want to enter the / etc/X11 directory, we can do it through cd / etc/X11.
4. Classification of paths
Paths are divided into absolute paths and relative paths.
4.1 absolute path
In Linux, absolute paths start with / (also known as root), such as / usr, / etc/X11. If a path starts from /, it must be an absolute path, so it is easy to understand
The code is as follows:
[root@localhost ~] # pwd
Note: determine the current location of the user, that is to say, where is he?
The code is as follows:
/ root
Note: the user is currently located at / root
The code is as follows:
[root@localhost ~] # cd / usr/share/doc/
Note: we enter the / usr/share/doc directory by absolute path
The code is as follows:
[root@localhost doc] # pwd
Note: determine the current location of the user
The code is as follows:
/ usr/share/doc
Note: the user is located at / usr/share/doc, which seems to have achieved our goal.
4.2 relative path
The relative path is based on. Or; or It started. Represents the location of the user's current operation, and.. Represents the parent directory; in the path,. Represents the directory where the user is currently located, and.. The superior directory needs to be transferred. And... Look at it as a catalog.
The code is as follows:
[root@localhost ~] # pwd
Note: use pwd to determine the location of the current user
The code is as follows:
/ root
Note: the directory is in the / root directory.
The code is as follows:
[root@localhost] # cd.
Note: we enter.
The code is as follows:
[root@localhost ~] # pwd
Note: determine the location of the current user
The code is as follows:
/ root
Note: it is concluded that in the / root directory
The code is as follows:
[root@localhost] # cd.
Note: we cut into the parent directory of / root
The code is as follows:
[root@localhost /] # pwd
Note: determine the location of the current user.
/ Note: the user is currently in / (root directory)
5. Description of some special symbols in the path
These symbols are used in relative paths, and these symbols can bring us convenience, so it is necessary to talk about them.
. Represents the current directory where the user is located
.. Represents the parent directory
~ represents the current user's own home directory
~ USER indicates that the user name is the home directory of USER, where USER is the user name that exists in / etc/passwd
5.1 symbol. Application example
Let's enhance it through the following example. The meaning expressed
The code is as follows:
[root@localhost ~] # pwd
Note: determine the directory where the user is currently located
The code is as follows:
/ root
Note: located in the / root directory
The code is as follows:
[root@localhost] # cd.
Note: enter. Catalogue, here. Is the current location of the user
The code is as follows:
[root@localhost ~] # pwd
Note: where is it?
The code is as follows:
/ root
Note: in / root.
Understand the meaning of. /
The code is as follows:
[root@localhost ~] # pwd
Note: determine the directory where the user is currently located
The code is as follows:
/ root
Note: located in the / root directory
The code is as follows:
[root@localhost ~] # ls
Note: display the files and subdirectories of the user's / root directory; you can also use ls.
Or
The code is as follows:
[root@localhost] # ls.
Mkuml-2004.07.17-ananas.tar.bz2 mydir openQreadme.txt sun.txt tmp upgrade.log
The code is as follows:
[root@localhost ~] # ls. / tmp/
View the contents of the tmp directory under the current directory where the user lives
The code is as follows:
KernelBak youdir
Or
The code is as follows:
[root@localhost ~] # ls tmp/
KernelBak youdir
[root@localhost ~] #
In some documents, we see examples like. / filename to run a script or program. In fact, it runs under the user's current directory; see the following example
The code is as follows:
[root@localhost ~] # pwd
Note: determine the directory where the user is currently located; r / > / root Note: located in / root directory
The code is as follows:
[root@localhost ~] # touch lsfile.sh
Note: create a file named lsfile.sh
The code is as follows:
[root@localhost ~] # chmod 755 lsfile.sh
Note: modify permissions to make them executable
The code is as follows:
[root@localhost ~] # echo "ls-la" > lsfile.sh
Note: add a ls-la instruction to the lsfile.sh file
The code is as follows:
[root@localhost ~] # more lsfile.sh
Note: use the more tool to view the contents of the lsfile.sh file
The code is as follows:
Ls-la
The code is as follows:
[root@localhost ~] #. / lsfile.sh
Note: run lsfile.sh, here using a relative path
The code is as follows:
[root@localhost ~] # / root/lsfile.sh
Note: this is the absolute path to run the lsfile.sh script
5.2 symbol.. Application example
The code is as follows:
[root@localhost ~] # pwd
Note: determine the directory where the user is currently located
The code is as follows:
/ root
[root@localhost ~] # cd / etc/X11/
Note: enter the X11 directory under the etc directory under the / directory
The code is as follows:
[root@localhost X11] # pwd
Note: determine the directory where the user is currently located
The code is as follows:
/ etc/X11
Note: it seems that the user is really in the / etc/X11 directory.
The code is as follows:
[root@localhost X11] # cd..
Note: go back to the superior directory
The code is as follows:
[root@localhost etc] # pwd
Note: determine the directory where the user is currently located
The code is as follows:
/ etc
The code is as follows:
[root@localhost etc] # cd.. / root/
Note: go back to the parent directory, that is, to /, and then enter the root directory
The code is as follows:
[root@localhost ~] # pwd
Determine if you are entering the root directory under the / directory?
The code is as follows:
/ root
Note: it is indeed realized.
5.3symbol ~ and ~ USER example
~ represents the home directory of the current operating user, see the following example
The code is as follows:
[root@localhost ~] # id
Note: view the user information of the current user; which user do we use to operate the command?
The code is as follows:
Uid=0 (root) gid=0 (root) groups=0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm), 6 (disk), 10 (wheel)
Note: yes, it's a root user.
The code is as follows:
[root@localhost ~] # finger root
Note: view the information of root users
The code is as follows:
Login: root Name: root
Directory: / root
Note: this means that the home directory of the root user is located in the / root directory Shell: / bin/bash
The code is as follows:
[root@localhost ~] # pwd
Note: determine the directory where the user is located
The code is as follows:
/ root
Note: yes / root directory
The code is as follows:
[root@localhost ~] # cd / etc/X11/
Note: enter / etc/X11
The code is as follows:
[root@localhost X11] # pwd
Note: determine the directory where the user is located
The code is as follows:
/ etc/X11
Note: it seems to have arrived / etc/X11
The code is as follows:
[root@localhost X11] # cd
~ Note: we return the home directory of the root user
The code is as follows:
[root@localhost ~] # pwd
/ root
Note: did you return?
Example of ~ USER
If we add a user, the system will add a user record to the / etc/passwd file, so / etc/passwd is the user's management file; the USER in ~ USER is the user who must "register" in / etc/passwd, so that the USER in ~ USER is valid. How to "register", of course, is the user management tool to add users. For user management tools, please refer to "introduction to Linux user Management tools"
To illustrate the application of ~ USER, let's first add a new user
The code is as follows:
[root@localhost ~] # adduser linuxsirorg
Note: add linuxsirorg as a user
The code is as follows:
[root@localhost ~] # passwd linuxsirorg
Note: set the password for linuxsirorg
The code is as follows:
Changing password for user linuxsirorg.
New UNIX password:
Note: add linuxsirorg user password
The code is as follows:
Retype new UNIX password:
Note: enter again
The code is as follows:
Passwd: all authentication tokens updated successfully.
Note: user added successfully
The code is as follows:
[root@localhost ~] # finger linuxsirorg
Note: view linuxsirorg user information
The code is as follows:
Login: linuxsirorg Name: (null)
Directory: / home/linuxsirorg Shell: / bin/bash
Note: we see the newly added user home directory at / home/linuxsirorg
Example of ~ USER
For example, I operate with the root user and are in the / root directory; I want to enter the home directory of the linuxsirorg user
The code is as follows:
[root@localhost ~] # pwd
/ root
[root@localhost ~] # cd ~ linuxsirorg/
Note: enter the linuxsirorg user's home directory; the equivalent command is cd / home/linuxsirorg
The code is as follows:
[root@localhost linuxsirorg] # pwd
Note: determine the location of the user
The code is as follows:
/ home/linuxsirorg
The code is as follows:
[root@localhost linuxsirorg] # cd ~ root
Note: equivalent to cd / root or equivalent cd ~; indicates that the home directory of root is returned
6. Cd the instruction to switch the user's current directory
The instruction for a user to enter another directory from the current directory is to use cd; we have applied a lot in the previous example, so I won't say any more here.
Usage:
The code is as follows:
# cd path
For example:
The code is as follows:
[root@localhost ~] # cd / usr/share/man/
For more help, please refer to man cd or cd-help
7. The instruction pwd to determine the working directory in which the user is currently located
The pwd instruction is used to show the current location of the user, which we have talked about a lot earlier.
Example:
The code is as follows:
[root@localhost man] # pwd
Note: determine the directory where the user is currently located
The code is as follows:
/ usr/share/man
Note: located in / usr/share/man
8. About the setting of user environment variable PATH
In general, files in the bin or sbin directory in the Linux file system are executable. Sometimes we need to set the user's environment variable PATH in order to make it easier to invoke instructions or tools without entering a path.
Look at the following example:
The code is as follows:
[root@localhost ~] # ls
Adduml.sh lsfile.sh mkuml-2004.07.17 mkuml-2004.07.17-ananas.tar.bz2 mydir openQreadme.txt sun.txt tmp upgrade.log
[root@localhost ~] # / bin/ls
Adduml.sh lsfile.sh mkuml-2004.07.17 mkuml-2004.07.17-ananas.tar.bz2 mydir openQreadme.txt sun.txt tmp upgrade.log
In the above example, the first instruction is to run the ls command directly to display the files and subdirectories in the current directory; the second / bin/ls instruction is run with the ls of the absolute path; the results of both modes appear to be the same.
In the forum, some brothers always I have installed so-and-so software package, but do not have a command. It's really about setting environment variables. If you enter an instruction directly that does not exist, there are two solutions, one is to specify the absolute path to the executable file (or relative path, how convenient to use it), and the other is to set the user's environment variables.
We can use export PATH to set environment variables. For example, add the following line to the .bashrc or .profile file in the user's home directory
The code is as follows:
Export PATH= ".: / bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin"
Explanation: you can find the absolute paths to all bin or sbin directories in the Linux file system and separate them with a: sign, such as the one set above. First。 Represents the directory in which the user is currently located
After adding it, let's run source again, that is:
The code is as follows:
# source .bashrc
Or
The code is as follows:
# source .profile
If you find that the instruction is run only with root permission, you need to use su;. If you are using an ordinary user, you may not have the right to view the contents of some files' directories, and you also need to use su to cut.
Thank you for your reading, the above is the content of "what is the file system path in the Linux system". After the study of this article, I believe you have a deeper understanding of what the file system path in the Linux system is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.