創建一個用戶名為test211的普通用戶
[23:35:09 root@C8[ ~]#useradd test211
[23:37:37 root@C8[ ~]#getent passwd test211
test211:x:1000:1000::/home/test211:/bin/bash
創建成功后發現test211家目錄中已經有3個隱藏文件
[23:37:51 root@C8[ ~]#ll -a /home/test211/
total 12
drwx------. 2 test211 test211 62 Jul 12 23:37 .
drwxr-xr-x. 3 root root 21 Jul 12 23:37 ..
-rw-r--r--. 1 test211 test211 18 Nov 9 2019 .bash_logout
-rw-r--r--. 1 test211 test211 141 Nov 9 2019 .bash_profile
-rw-r--r--. 1 test211 test211 312 Nov 9 2019 .bashrc
刪除test211的家目錄
[23:38:17 root@C8[ ~]#rm -rf /home/test211/
[23:38:46 root@C8[ ~]#ll -a /home/test211/
ls: cannot access '/home/test211/': No such file or directory
給test211一個密碼用來登錄
[23:40:28 root@C8[ ~]#echo 666 | passwd --stdin test211
Changing password for user test211.
passwd: all authentication tokens updated successfully.
再另一側使用test211登錄后顯示找不到家目錄
Activate the web console with: systemctl enable --now cockpit.socket
Could not chdir to home directory /home/test211: No such file or directory
[23:42:31 test211@C8[ /]$pwd
/
手動創建test211家目錄
[23:47:54 root@C8[ ~]#mkdir /home/test211
[23:49:29 root@C8[ ~]#ll -a /home/test211
total 0
drwxr-xr-x. 2 root root 6 Jul 12 23:49 .
drwxr-xr-x. 3 root root 21 Jul 12 23:49 ..
用戶test211登錄,家中還是沒有文件
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Sun Jul 12 23:42:31 2020 from 192.168.50.200
[23:58:00 test211@C8[ ~]$ll -a
total 0
drwxr-xr-x. 2 root root 6 Jul 12 23:49 .
drwxr-xr-x. 3 root root 21 Jul 12 23:49 ..
創建用戶時同時創建的家目錄中的默認模板文件來在/etc/skel/
[23:47:47 root@C8[ ~]#ll -a /etc/skel/
total 24
drwxr-xr-x. 2 root root 62 Mar 16 13:51 .
drwxr-xr-x. 103 root root 8192 Jul 12 23:42 ..
-rw-r--r--. 1 root root 18 Nov 9 2019 .bash_logout
-rw-r--r--. 1 root root 141 Nov 9 2019 .bash_profile
-rw-r--r--. 1 root root 312 Nov 9 2019 .bashrc
我們將skel中的文件拷貝過去
使用cp -r /[路徑]/.[^.]* 拷貝目錄下所有隱藏文件,只拷貝隱藏文件因為是點開頭
[00:02:10 root@C8[ ~]#cp -r /etc/skel/.[^.]* /home/test211/
[00:03:03 root@C8[ ~]#ll -a /home/test211/
total 12
drwxr-xr-x. 2 root root 62 Jul 13 00:02 .
drwxr-xr-x. 3 root root 21 Jul 12 23:49 ..
-rw-r--r--. 1 root root 18 Jul 13 00:03 .bash_logout
-rw-r--r--. 1 root root 141 Jul 13 00:03 .bash_profile
-rw-r--r--. 1 root root 312 Jul 13 00:03 .bashrc
如果想同時拷貝非隱藏文件,只需加一個點即可
使用cp -r /[路徑]/. 即可以拷貝隱藏及非隱藏文件
[00:03:54 root@C8[ ~]#touch /etc/skel/null.test ##創建一個文件
[00:07:44 root@C8[ ~]#ll -a /etc/skel/
total 24
drwxr-xr-x. 2 root root 79 Jul 13 00:07 .
drwxr-xr-x. 103 root root 8192 Jul 12 23:42 ..
-rw-r--r--. 1 root root 18 Nov 9 2019 .bash_logout
-rw-r--r--. 1 root root 141 Nov 9 2019 .bash_profile
-rw-r--r--. 1 root root 312 Nov 9 2019 .bashrc
-rw-r--r--. 1 root root 0 Jul 13 00:07 null.test
[00:11:34 root@C8[ ~]#rm -rf /home/test211/*.* ##刪掉文件夾下所有文件
[00:11:53 root@C8[ ~]#ll -a /home/test211/
total 0
drwxr-xr-x. 2 root root 6 Jul 13 00:11 .
drwxr-xr-x. 3 root root 21 Jul 12 23:49 ..
[00:12:09 root@C8[ ~]#cp -r /etc/skel/. /home/test211/ ##拷貝skel下所有隱藏和非隱藏文件到用戶test211家目錄下
[00:13:04 root@C8[ ~]#ll -a /home/test211/
total 12
drwxr-xr-x. 2 root root 79 Jul 13 00:13 .
drwxr-xr-x. 3 root root 21 Jul 12 23:49 ..
-rw-r--r--. 1 root root 18 Jul 13 00:13 .bash_logout
-rw-r--r--. 1 root root 141 Jul 13 00:13 .bash_profile
-rw-r--r--. 1 root root 312 Jul 13 00:13 .bashrc
-rw-r--r--. 1 root root 0 Jul 13 00:13 null.test
點 "." 包括隱藏和非隱藏文件
可以拷文件夾過去改個名即可
[00:13:13 root@C8[ ~]#rm -rf /home/test211/
[00:16:36 root@C8[ ~]#cp -r /etc/skel /home/test211
[00:16:59 root@C8[ ~]#ll -a /home/test211/
total 12
drwxr-xr-x. 2 root root 79 Jul 13 00:16 .
drwxr-xr-x. 3 root root 21 Jul 13 00:16 ..
-rw-r--r--. 1 root root 18 Jul 13 00:16 .bash_logout
-rw-r--r--. 1 root root 141 Jul 13 00:16 .bash_profile
-rw-r--r--. 1 root root 312 Jul 13 00:16 .bashrc
-rw-r--r--. 1 root root 0 Jul 13 00:16 null.test