What does linux user directory mean?

藏色散人
Release: 2023-03-20 10:35:54
Original
3536 people have browsed it

The Linux user directory is a directory created by the system administrator when adding users. Each user has his own home directory. The home directories of different users are generally different from each other; when a user first logs in to the system, other The working directory is the user's home directory, usually the same as the user's login name; users can reference their home directory through a "~" character.

What does linux user directory mean?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What does the linux user directory mean?

~ represents the user’s home directory in Linux

For general users, ~ represents /home/ (user name)

For root users, ~ represents /root

If you want to see the true appearance of ~, you can first enter the ~ directory, and then use the pwd -P command to view the absolute path of ~

cd ~
pwd -P
Copy after login

The user's home directory can be in /etc/passwd Item 6 finds

[root@www ~]# head -n 4 /etc/passwdroot:x:0:0:root:/root:/bin/bash  <==等一下做为底下说明用
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
Copy after login

Home directory:
This is the user’s home directory. Taking the above example, root’s home directory is in /root, so when root logs in, it will immediately go to /root It’s in the catalog! hehe! If you have an account with a particularly large space, what should you do if you want to move the account's home directory to another hard drive? correct! You can make modifications in this field! The default user home directory is in The /home/yourIDname

directory is a special file for organizing files in the Linux system. To enable users to better use directories, we introduce some basic concepts about directories.

(1) Working directory and user home directory
Logically speaking, after the user logs in to the Linux system, he is in a certain directory at all times. This directory
The directory is called the working directory or current directory (Working Directory). The working directory can be changed at any time. When a user initially logs into the system, his home directory (Home
Directory) becomes his working directory. The working directory is represented by "." and its parent directory is represented by "..".
The user home directory is created by the system administrator when adding users (it can also be changed later). Each user has his own home directory. The home directories of different users are generally different from each other.
When a user first logs in to the system, his working directory is the user's home directory, which is usually the same as the user's login name.
Users can reference their home directory through a ~ character.
For example, the command
/home/WANG$ cat ~/class/software_1
has the same meaning as the following command
/home/WANG$ cat /home/WANG/class/software_1
. The shell will replace the ~ character with the name of the user's home directory. After the directory hierarchy is created, users can put relevant files into the corresponding directories to organize the files.

(2)路径 
顾名思义,路径是指从树型目录中的某个目录层次到某个文件的一条道路。此路径的主要构成是目录名称,中间用“/”分开。任一个文件在文件系统中的位置都是由相应的路径决定的。 
用户在对文件进行访问时,要给出文件所在的路径。 路径又分相对路径和绝对路径。 绝对路径是指从“根”开始的路径,也称为完全路径;相对路径是从用户工作目录开始的路径。 
应该注意到,在树型目录结构中到某个确定文件的绝对路径和相对路径均只有一条。绝对路径是确定不变的,而相对路径则随着用户工作目录的变化而不断变化。这一点对于我们以后使用某些命令如cp和tar等大有好处。 
用户要访问一个文件时,可以通过路径名来引用,并且可以根据要访问的文件与用户工作
目录的相对位置来引用它,而不需要列出这个文件的完整路径名。例如,用户WANG有一个名为class的目录,该目录中有两个文件:software_1
和hardware_1。若用户WANG想显示出其class目录中的名为software_1的文件,可以使用下列命令: 
/home/WANG$ cat /home/WANG/class/software_1
用户也可以根据文件software_1与当前工作目录的相对位置来引用该文件。

这时命令为: 

  /home/WANG$ cat class/software_1
Copy after login

Linux中用 pwd 命令来查看”当前工作目录“的完整路径。 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录。

在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置。

命令格式:

pwd [选项]
Copy after login

命令功能:

查看”当前工作目录“的完整路径

常用参数:

一般情况下不带任何参数

如果目录是链接时:

格式:pwd -P 显示出实际路径,而非使用连接(link)路径。

常用实例:

1:用 pwd 命令查看默认工作目录的完整路径

[root@localhost ~]# pwd
/root
[root@localhost ~]#
Copy after login

实例2:

[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# pwd 
/opt/soft
[root@localhost soft]#
Copy after login

实例三:目录连接链接时,pwd -P 显示出实际路径,而非使用连接(link)路径;pwd显示的是连接路径

命令:

输出:

[root@localhost soft]# cd /etc/init.d 
[root@localhost init.d]# pwd
/etc/init.d
[root@localhost init.d]# pwd -P
/etc/rc.d/init.d
[root@localhost init.d]#
Copy after login

实例4:/bin/pwd

命令:

/bin/pwd [选项]
Copy after login

选项:

目录连接链接时,输出连接路径 输出物理路径输出:

[root@localhost init.d]# /bin/pwd 
/etc/rc.d/init.d
[root@localhost init.d]# /bin/pwd --help
[root@localhost init.d]# /bin/pwd -P
/etc/rc.d/init.d
[root@localhost init.d]# /bin/pwd -L
/etc/init.d
[root@localhost init.d]#
Copy after login

实例五:当前目录被删除了,而pwd命令仍然显示那个目录

输出:

[root@localhost init.d]# cd /opt/soft
[root@localhost soft]# mkdir removed
[root@localhost soft]# cd removed/
[root@localhost removed]# pwd
/opt/soft/removed
[root@localhost removed]# rm ../removed -rf
[root@localhost removed]# pwd
/opt/soft/removed
[root@localhost removed]# /bin/pwd
/bin/pwd: couldn&#39;t find directory entry in “..” with matching i-node
[root@localhost removed]# cd 
[root@localhost ~]# pwd
/root
[root@localhost ~]#
Copy after login

推荐学习:《linux视频教程

The above is the detailed content of What does linux user directory mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!