This is the answer I got from my question yesterday. I don’t understand what it means. There is a home in the root directory and a home in the login directory. Is that so? Because you are entering the "/home" directory, not the "home directory". Usually the "home directory" (the official Chinese translation is "home directory", "home directory", etc.) is usually located in "/home/your username".
黄舟2017-05-16 13:26:15
/home
目录下就是用户目录,例如 /home/用户名
但是 root 用户的目录是 /root
你是哪个用户登录上去之后就进到 /home/对应用户
的这个目录
要是 root 用户,那么登录上去就是 /root
cd ~ is a shortcut command that directly goes to the personal directory of the currently logged in user
習慣沉默2017-05-16 13:26:15
In fact, the so-called home目录
, 只是代表用户登录时, 默认进入的目录而已; 当我们在创建用户
时, 如果没有指定home目录
, 系统则会为我们分配默认值, 非root
用户就是默认在/home/用户名
, 而root
则是/root
. 每次我们登陆系统, 登陆程序就会根据系统的/etc/passwd
文件里面的字段, 为我们初始化信息, 包括登陆之后的shell环境(最后一个字段)
,家目录(第六个字段)
.
我们完全可以自定义家目录: useradd testtest -d /tmp/home/test
, 通过-d选项为新增用户创建新目录
甚至可以通过 -M
来指定不创建, 通常用于有些程序运行的账号, 完全就没有必要登陆和家目录的, 我们就能通过这些选项去创建这样的用户.
如果用户已经创建了, 我们也能通过修改/etc/passwd
sixth field of the file, assuming
将
testtest:x:507:507::/tmp/test_home/:/bin/bash
改成
testtest:x:507:507::/tmp/:/bin/bash
Then log intesttest
用户时, 它就默认进入/tmp
later, because that is its home directory.
PHPz2017-05-16 13:26:15
The home directory of each user is just below /home/用户名
下,通过cd ~
就可以进入。只有root用户的home目录特殊,在/root
.
黄舟2017-05-16 13:26:15
You will understand the difference after installing one Chinese version and one English version
A directory is home, and the folder/directory is called home in lowercase. It is under the / directory, which is the home directory, and is a necessary directory.
You can see that there are system-level directories such as tmp and var in the same directory. Use pwd to check the absolute path and you can see that it is located in the home directory
The other is the Home directory. The Chinese distribution version will be called the home directory/home directory. Under the Users/username/ directory, it is the directory that follows the user
You can see through pwd that it is located under the user directory
If there is no ordinary user account in your system and only one root user, then the Home directory does not exist by default. Once a new account is created, especially after the GUI interface is installed, you create an account accordingly. A new Home directory will be created under the account directory, and the name of this Home directory is the name of your new account.
Have you seen this house icon? This is the Home directory. My account is called a, so the name of this Home directory, which is the home directory, is a. Click on this house (Home directory)
You can see that the folders inside are all user folders. If you create a new user, say b, then there will be a Home directory called b under the Users/ directory, which contains the user file. .
If there are 100 accounts in your system, there will be 100 home directories, but there is only one home directory under the home directory (default). This is the biggest difference.