Linux File System Path

Source: Internet
Author: User

Author:North South
From:Linuxsir. org
Abstract:In File Management of Linux operating systems, file or directory management in command line mode (in the console or terminal) involves the concept of path, this is the most basic foundation for Linux Command Line operations. If we understand the concept of path, we can access any directory as we like and do our work.


Directory

1. the Linux file system starts from;
2. Understanding the concept of path;
3. Path components;
4. Path classification;

 

4.1 Absolute path;
4.2 relative path;

5. Descriptions of some special symbols in the path;

5.1 symbol. application example;
5.2 symbol .. application example;
5.3 symbol ~ And ~ User example;

6. Switch the instruction CD of the user's current directory;
7. Command Pwd for determining the current working directory of the user;
8. Set the path of the user environment variable
9. Operation commands on directories;
10. About this article;
11. postscript;
12. references;
13. related documents;


++
Body
++


1. the Linux file system starts from;

In File Management of Linux operating systems, file or directory management in command line mode (in the console or terminal) involves the concept of path, this is the most basic foundation for Linux Command Line operations. If we understand the concept of path, we can enter any directory as we like and do what we want.

A Linux File System is a tree-like structure that uses/as the entry, And/(also known as the root directory) has subdirectories, such as etc, USR, and Lib, there are files or subdirectories under each subdirectory, which forms a tree structure, which is relatively simple. What about Windows file systems? It introduces the concept of disk C and disk D, so that users who are used to Windows operations will find that Linux has the concept of disk C and disk D, sometimes even at a loss.


2. Understanding the concept of path;

The purpose of introducing the concept of path is to find the directory or file we need. For example, if we want to edit the file.txt file, we first need to know where it is stored, that is, we need to point out its location, and then we need to use the path.


3. Path components;

A path consists of a directory or directory and a file name. For example,/etc/X11 is a path, and/etc/X11/Xorg. conf is also a path. That is to say, the path can be a combination of directories, which can be classified in depth or composed of file records and files. For example, we want to use VI to edit Xorg. CONF file. Enter VI/etc/X11/Xorg in the command line. conf. If you want to enter the/etc/X11 directory, you can use CD/etc/X11.


4. Path classification;

Paths are classified into absolute paths and relative paths;


4.1 Absolute path;

In Linux, the absolute path starts with/(also known as the root directory), such as/USR and/etc/X11. If a path starts from/, it must be an absolute path;

[Root @ localhost ~] # PWD Note: determine the user's current location, that is, where is the user's location?
/Root note: the user is currently located at/root;

[Root @ localhost ~] # Cd/usr/share/doc/Note: we enter the/usr/share/doc directory in an absolute path;
[Root @ localhost Doc] # PWD Note: determine the current user location
/Usr/share/DOC note: the user is located in/usr/share/doc, which seems to have achieved our goal;

 


4.2 relative path;

The relative path is. or .. start ,. indicates the location of the user's current operation, and .. indicates the parent directory. In the path ,. indicates the current directory of the user, and .. upper-level directory. and .. as a directory.

[Root @ localhost ~] # PWD Note: Pwd is used to determine the location of the current user;
/Root note: the directory is in the/root directory;

[Root @ localhost ~] # Cd. Note: we enter.
[Root @ localhost ~] # PWD Note: determine the location of the current user;
/Root note: obtained in the/root directory;

[Root @ localhost ~] # CD .. Note: We cut in to the/root parent directory.
[Root @ localhost/] # PWD Note: determine the location of the current user.
/Note: the user is currently in the/(root directory;

 


5. Descriptions of some special symbols in the path;

These symbols are applied in relative paths, which can be convenient for us, so it is necessary to talk about them;

. Indicates the current directory of the user;
.. Indicates the parent directory
~ Indicates the current user's home directory
~ User indicates the home directory where the user name is user. Here, the user name exists in/etc/passwd;

 


5.1 symbol. application example;

The following example shows how to enhance the meaning;

[Root @ localhost ~] # PWD Note: determine the current directory of the user;
/Root note: In the/root directory;

[Root @ localhost ~] # Cd. Note: Go to the. Directory, where. Is the current location of the user;
[Root @ localhost ~] # PWD Note: Where is it?
/Root note: In/root.

 

Understand the meaning;

[Root @ localhost ~] # PWD Note: determine the current directory of the user;
/Root note: In the/root directory;

[Root @ localhost ~] # Ls Note: displays the files and subdirectories of the user's/root directory. You can also use ls.
Or
[Root @ localhost ~] # Ls.
The mkuml-2004.07.17-ananas.tar.bz2 mydir openqreadme.txt sun.txt TMP upgrade. Log

[Root @ localhost ~] # Ls./tmp/view the content of the tmp directory in the current directory of the user
Kernelbak youdir

Or

[root@localhost ~]# ls tmp/
kernelBak  youdir
[root@localhost ~]#

 

In some documents, we see examples of running a script or program similar to./filename. In fact, it runs in the current user directory. See the following example;

[Root @ localhost ~] # PWD Note: determine the current directory of the user;
/Root note: In the/root directory;
[Root @ localhost ~] # Touch lsfile. Sh Note: create a file named lsfile. Sh;
[Root @ localhost ~] # Chmod 755 lsfile. Sh Note: Modify the permission to make it executable;
[Root @ localhost ~] # Echo "ls-La"> lsfile. Sh Note: add the LS-La command to the lsfile. Sh file.
[Root @ localhost ~] # More lsfile. Sh Note: use the more tool to view the content of the lsfile. Sh file;
Ls-la

[Root @ localhost ~] #./Lsfile. Sh Note: Run lsfile. Sh, where the relative path is used;
[Root @ localhost ~] #/Root/lsfile. Sh note: this is the absolute path to run the lsfile. Sh script;

 


5.2 symbol .. application example;

[Root @ localhost ~] # PWD Note: determine the current directory of the user;
/Root
[Root @ localhost ~] # Cd/etc/X11/Note: Go to the X11 directory under the etc directory under the/directory;
[Root @ localhost X11] # PWD Note: determine the current directory of the user;
/Etc/X11 Note: It seems that the user is in the/etc/X11 directory;
[Root @ localhost X11] # CD .. Note: return to the parent directory;
[Root @ localhost etc] # PWD Note: determine the current directory of the user;
/Etc
[Root @ localhost etc] # CD ../root/Note: return to the parent directory, that is, back to/, and then enter the root directory;
[Root @ localhost ~] # PWD: Do you want to enter the root directory under the/directory?
/Root note: it is indeed implemented.

 


5.3 symbol ~ And ~ User example;

~ Indicates the Home Directory of the current user. See the following example;

[Root @ localhost ~] # ID Note: view the user information of the current user. Which user does we use to operate the command?
Uid = 0 (Root) gid = 0 (Root) groups = 0 (Root), 1 (BIN), 2 (Daemon), 3 (sys), 4 (ADM ), 6 (Disk), 10 (wheel) Note: It is the root user;

[Root @ localhost ~] # Finger root note: view the root user information;
Login: Root name: Root
Directory:/root note: This indicates that the root user's home directory is located in the/root directory shell:/bin/bash

 

[Root @ localhost ~] # PWD Note: determine the user's directory;
/Root note: yes/root directory;

[Root @ localhost ~] # Cd/etc/X11/Note: Enter/etc/X11
[Root @ localhost X11] # PWD Note: determine the user's directory;
/Etc/X11 Note: It seems that/etc/X11 has been reached;

[Root @ localhost X11] # Cd ~ Note: The Home Directory of the root user is returned;
[Root @ localhost ~] # Pwd
/Root note: Is it returned ??

 

~ User example;

 

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 the user must be the "registered" user in/etc/passwd ~ The user is valid. "Register" is, of course, a user management tool to add users. For more information about user management tools, see Introduction to Linux User management tools.

For instructions ~ User application, we first Add a new user;

[Root @ localhost ~] # Adduser linuxsirorg Note: add the linuxsirorg user;
[Root @ localhost ~] # Passwd linuxsirorg note; set a password for linuxsirorg;
Changing password for user linuxsirorg.
New Unix Password: Note: add the linuxsirorg User Password
Retype new Unix Password: Note: Enter it again;
Passwd: All authentication tokens updated successfully. Note: The user is added successfully;

[Root @ localhost ~] # Finger linuxsirorg Note: View linuxsirorg user information;
Login: linuxsirorg name: (null)
Directory:/home/linuxsirorg shell:/bin/bash

Note: The newly added user's home directory is in/home/linuxsirorg;

 

~ User example;

For example, if I use the root user and am in the/root directory, I want to enter the home directory of the linuxsirorg user;

[Root @ localhost ~] # Pwd
/Root

[Root @ localhost ~] # Cd ~ Linuxsirorg/

Note: Enter the Home Directory of the linuxsirorg user. The equivalent command is CD/home/linuxsirorg;

[Root @ localhost linuxsirorg] # PWD Note: determine the user's location;
/Home/linuxsirorg

[Root @ localhost linuxsirorg] # Cd ~ Root Note: equivalent to CD/root, or similar Cd ~ ; Returns the root home directory;

 


6. Switch the instruction CD of the user's current directory;

When a user enters another directory from the current directory, the command is to use CD; we have applied a lot in the previous example, and I will not talk about it here;

Usage:

# Cd path

 

Example:

[root@localhost ~]# cd /usr/share/man/

 

For more help, see man CD or CD -- Help


7. Command Pwd for determining the current working directory of the user;

The PWD command is used to display the user's current location. We have mentioned a lot above.

Example:

[Root @ localhost Man] # PWD note; determine the current directory of the user;
/Usr/share/Man note: in/usr/share/man;

 


8. Set the path of the user environment variable;

In general, files in the bin or sbin directory of the Linux File System are executable. Sometimes we can call commands or tools without entering the path for convenience. In this case, we need to set the path of the user's environment variable.

Take the following example:

[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 preceding example, the first command directly runs the LS command to display the files and subdirectories in the current directory; the second/bin/LS command runs with the absolute path ls. The results of the two methods are the same.

On the Forum, some of my friends have always installed software packages without instructions. It is actually about setting environment variables. If you directly enter a command that does not exist, there are two solutions. One method is to specify the absolute path of the executable file (or relative path. How can this be convenient ), another method 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;

export PATH=".:/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin"

 

Explanation:You can find the absolute paths of all bin or sbin directories in the Linux File System, and separate them with:, as shown in the preceding figure. The first one indicates the current directory of the user;

After adding the source, run the following command:

# Source. bashrc
Or
# Source. Profile

 

If you find that the command runs only with the root permission, you need to use Su. If you are using a common user, you may not have the permission to view the contents of some file directories, you also need to use Su to switch identities. For details, refer to "Super permission control in Linux".


9. Operation commands on directories;

For operations on directories, such as creating, copying, moving, and deleting directories, see show, delete, copy, move, and rename Linux file and directory management. That is, the use of tools such as LS, mkdir, CP, MV, rmdir, and RM;


10. About this article;

Yesterday I wrote "display, delete, copy, move, and rename Linux file and directory management". Today I wrote this article. Any operation in the command line cannot leave the path. In this case, this article is also a basic article.

In my opinion, there should be a assumption before writing a document, that is, locking the reader's technical level. Based on this, the "Reader" in this article is not familiar with Linux.

Thank you ~~~


11. postscript;

Or write the file management documents .... ....


12. references;

Control of super permissions in Linux
Display, delete, copy, move, and rename Linux file and directory management


13. related documents;

Display, delete, copy, move, and rename Linux file and directory management
Brief Introduction to Linux File Types and file types
Brief Introduction to the directory structure of the Linux File System
Linux File System Overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.