创建一个用户名为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

最新文章

  1. DropDownList实现可输入可选择
  2. ftp常用命令
  3. TortoiseGit使用手册
  4. DataFormatString 转
  5. css3创建3D场景
  6. (转)Python实例手册
  7. CentOS修改主机名和网络信息
  8. hbase的rowkey简单设计
  9. POJ3126Prime Path
  10. 工作流Jpbm4.4工作流知识点总结(工作流开发宝典)
  11. SharePoint 2016 安装配置流程及需要注意的地方
  12. [SCOI 2016]背单词
  13. PHP实现微信模板消息发送给指定用户
  14. DNS压力测试
  15. Python3中Urllib库基本使用
  16. linux shell 脚本攻略学习6-xargs详解
  17. javascript 中解析json
  18. Debian Linux 下安装pip3
  19. Emitting signals
  20. Import SQL into MySQL with a progress meter

热门文章

  1. [LeetCode]647. 回文子串(DP)
  2. 1.3Hadoop版本说明
  3. CentOS7使用yum时File contains no section headers.解决办法
  4. 使用PyCharm引入需要使用的包
  5. 【答疑解惑】为什么你的 Charles 会抓包失败?
  6. pwnable.kr-coin1-witeup
  7. Tomcat 第四篇:请求处理流程(上)
  8. burp suite 之 Scanner(漏洞扫描)
  9. Arduino 串口的一些高级用法
  10. [WC 2011]最大Xor和路径