#创建用户
useradd
#创建一个用户
例子1:useradd test1#设置密码,远程ssh连接是需要密码的,所以想让某个用户登录系统,必须设置密码
passwd
例子1:passwd test1
#用root用户给普通用户修改密码
[root@localhost ~]# passwd test1
更改用户 test1 的密码 。
新的 密码:123456
无效的密码: 密码是一个回文
重新输入新的 密码:123456
passwd:所有的身份验证令牌已经成功更新。
#普通用户自己修改密码
[test1@localhost ~]$ passwd # 给当前登录用户修改密码,root用户修改密码不需要输入旧密码,
普通用户需要输入旧密码
更改用户 test1 的密码 。
为 test1 更改 STRESS 密码。
(当前)UNIX 密码:
新的 密码:
无效的密码: 密码少于 8 个字符
新的 密码:
无效的密码: 密码少于 8 个字符
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
passwd: 已经超出服务重试的最多次数
# 一般linux的密码是有复杂度要求的,比如下面这种密码就可以通过:大小写组合、数字、特殊字符组合起
来超过8位。
XPcode666@qq.COM
XPcode666@WSX
例子3:
#免交互修改密码,这样不需要输入两次密码确认。echo是打印的意思,有结果输出给passwd命令来修改test1用户的密码
echo 123456|passwd --stdin test1
# 这种一般同时改多个Linux服务器系统的密码时比较方便。#检查用户是否存在
id
例子1:
#用户存在,系统的返回结果
[root@localhost ~]# id test1
uid=1000(test1) gid=1000(test1) 组=1000(test1)
#用户不存在,系统的返回结果
[root@localhost ~]# id test2
id: test2: no such user## 查看用户列表
cat /etc/passwd
#删除用户
userdel
例子1:
#被删除的用户还在登录状态,是不能删除的
[root@localhost ~]# userdel test1
userdel: user test1 is currently used by process 2356
#被删除的用户,退出登录之后,可以正常删除
[root@localhost ~]# userdel test1
'''
linux删除用户之后,/home/目录下对应的用户文件夹还在,如果还想加回来这个用户,那么会提示家目录存
在,不会从样板目录(skel)中复制任何文件了,通过ls -a /etc/skel,可以看到skel目录下的内容了。
还提示邮箱文件已经存在,ls /var/spool/mail下面
windows删除用户之后,c:\Users目录下的用户文件夹也还在
注意:删除之后的用户,再次创建出来,密码是需要重新设置的
'''
[root@localhost ~]# userdel -r test1 # 删除用户,并删除用户相关目录#修改用户信息,修改属性
usermod # modify 它有很多选项(参数),-L是锁定用户,通过命令 -h(或者--help,一个-后面一般跟一个字母即可,两个-后面一般跟完整单词),可以查看命令的各种选项的意思,比如usermod -h
#锁定用户(和windows的禁用用户一个意思)
例子1:
[root@localhost ~]# usermod -L test1 #被锁定的用户,下次就登录不上系统了。
[root@localhost ~]# usermod -U test1 #解锁用户
[root@localhost ~]# lchage -l test1 # 查看用户详细信息
帐号被锁。
至少: 0
至多: 99999
警告: 7
不活跃: 从不
最后一次改变: 2021年07月20日
密码过期: 从不
密码不活跃: 从不
帐号过期: 从不
#禁止用户登录(这个后面再说)
[root@localhost ~]# usermod -s /sbin/nologin test2
[root@localhost ~]# grep -w 'test2' /etc/passwd
test2:x:1001:1001::/home/test2:/sbin/nologinlchage
例子1:
[root@localhost ~]# lchage -l test1
帐号没被锁。
至少: 0
至多: 99999
警告: 7
不活跃: 从不
最后一次改变: 2021年07月20日
密码过期: 从不
密码不活跃: 从不
帐号过期: 从不
## 所有的用户信息存储在/etc/passwd文件中,每创建一个用户该文件就会多一行记录
## passwd文件解释
root:x:0:0:root:/root:/bin/bash
test1:x:1000:1000::/home/test1:/bin/bash
test2:x:1001:1001::/home/test2:/sbin/nologin
test3:x:1002:1000::/home/test3:/sbin/nologin
haha:x:1004:1004:putong user:/home/haha:/bin/bash
第一列:用户名
第二列:x
第三列:uid # root用户的uid是0,我们自己创建的用户uid是1000及之后的数值。
第四列:gid
第五列:注释,一般为空
第六列:家目录的位置
第七列:使用shell的名称,默认使用/bin/bash
## 有的用户密码信息存储/etc/shadow,设置了密码的长度比较长。密码是两层加密的,基本无法破解。但是如果黑客权限比较高,它可以用知道密码的shadow文件来替换这个文件,或者修改这个文件下某个用户的密码,只有root用户才有权力修改这个文件。
[root@localhost ~]# cat /etc/shadow
root:$6$QM3AHtFflOvGbCnt$2wTYZrnO8c66vycaxprE79G.I7hiy8EqXntG86FXxqlSawjtKoTjAnA
a9xFA3ad1QpFskJRPt0QeDPBnZZAdx0::0:99999:7:::
bin:*:18353:0:99999:7:::
daemon:*:18353:0:99999:7:::
adm:*:18353:0:99999:7:::
lp:*:18353:0:99999:7:::
sync:*:18353:0:99999:7:::
shutdown:*:18353:0:99999:7:::
halt:*:18353:0:99999:7:::
mail:*:18353:0:99999:7:::
operator:*:18353:0:99999:7:::
games:*:18353:0:99999:7:::
ftp:*:18353:0:99999:7:::
nobody:*:18353:0:99999:7:::
systemd-network:!!:18827::::::
dbus:!!:18827::::::
polkitd:!!:18827::::::## 本地登录:直接在主机上输入用户名和密码登录
## 远程登录:ssh远程登录
## windows默认只能同时一个用户登录,登录另外一个用户,前一个用户就会自动下线。
## linux支持多个用户在多个地方同时登录一个系统,每个用户都有一个终端来控制操作系统。终端的意思就是连接窗口。
# 查看当前登录了几个用户,或者打开了几个终端
w
结果:下面表示2个终端登录了
12:15:42 up 21 min, 2 users, load average: 0.00, 0.01, 0.03
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 12:15 6.00s 0.00s 0.00s -bash
root pts/0 192.168.61.1 11:55 6.00s 0.02s 0.01s w
# tty1表示本地登录的、pts/0表示远程登录的## 新建组和查看组:
groupadd 组名
例子:
[root@localhost tmp]# groupadd test
[root@localhost tmp]# cat /etc/group # 查看有哪些组#指定组来创建用户,如果没有指定组,那么创建用户的时候,linux会自动创建一个与用户名同名的组。
例子: 组的英文是group
[root@localhost tmp]# useradd -g test1 test3 #-g 是指定主组
[root@localhost tmp]# id test3
uid=1002(test3) gid=1000(test1) 组=1000(test1)
# gid表示用户的属组的主组
# 组=表示用户的属组,用户可以属于多个组,一个主组,多个其他组。# 删除组
groupdel 组名
例子:
[root@localhost tmp]# groupdel test
#如果组内有用户,会报错,需要先删除主组属于这个组的所有用户(userdel -r 用户名),或者将用户移到其他的组之后在删除组。
# 修改组名
# groupmod -n XPcode wulaoban # 将wulaoban组名改为XPcode# 修改用户所属的主组
usermod -g 组名
例子:
[root@localhost tmp]# usermod -g test XPcode #将XPcode用户的主组改为test
[root@localhost tmp]# groupdel XPcode # 就可以将XPcode组删除了。
# 将用户添加到多个其他组中
usermod -G
[root@localhost tmp]# usermod -G test wulaoban # 将wulaoban用户也添加到test组## root用户权限最高,所以一般对他不做什么权限设置。其他用户就要设定权限并且遵守权限了。文件权限:
#文件属性
[root@localhost ~]# ls -l /tmp/123.txt
-rw-r--r--. 1 root root 0 7月 20 23:17 /tmp/123.txt
#第一段的第一个字符,表示文件类型 -文件、d目录、l软链接(对应着windows快捷方式)、b块设备(ls /dev,可以看到硬盘sda等)
#第一段第2-4字符,表示该文件所属用户的权限
#第一段第5-7字符,表示该文件所属用户组的权限
#第一段第8-10字符,表示其他用户对该文件的权限
'''
r 4 代表读权限 read
w 2 代表写权限 write
x 1 代表可执行权限 executable
- 0 空权限位,表示没有这个权限,9位权限不能少,没有的权限就用-代替。
'''
权限值表
0 ---
1 --x
2 -w-
3 -wx
4 r--
5 r-x
6 rw-
7 rwx
ugo权限体系:
rw- r-- r--
user group other
## root没办法玩昂,因为默认权限太高。我们用普通用户来玩:用xshell开启多个窗口连接上这三个用户。
创建三个用户并设置密码:xpcode、wangwu、zhaoliu
[root@localhost ~]# useradd xpcode
[root@localhost ~]# passwd xpcode
更改用户 xpcode 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# useradd wangwu
[root@localhost ~]# passwd wangwu
更改用户 wangwu 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]#
[root@localhost ~]# useradd zhaoliu
[root@localhost ~]# passwd zhaoliu
更改用户 zhaoliu 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新
## 使用xpcode来登录,并创建个文件,将文件权限全部去掉,修改权限用chmod指令,全称change mode:
# 例如:chomd -r,就是去掉r权限,chomd +r就是加上读权限,chmod +wr就是加读写权限,chmod u+r,就是给文件属主用户添加读权限等
[xpcode@localhost ~]$ touch 1.txt
[xpcode@localhost ~]$ vi 1.txt
[xpcode@localhost ~]$ ls -l
总用量 4
-rw-rw-r--. 1 xpcode xpcode 12 3月 20 09:07 1.txt
[xpcode@localhost ~]$ chmod -rw 1.txt
[xpcode@localhost ~]$ ls -l
总用量 4
----------. 1 xpcode xpcode 12 3月 20 09:07 1.txt
## 现在这个文件是没有任何权限的,但是文件是xpcode创建的,文件属主还是xpcode,虽然显示xpcode也没有权限,但是实际上xpcode是可以修改文件权限的,其他用户(除了root)是没有权力修改这个文件权限的。读权限的作用:
## xpcode用户:
[xpcode@localhost ~]$ chmod -rw 1.txt
[xpcode@localhost ~]$ ls -l
总用量 4
----------. 1 xpcode xpcode 12 3月 20 09:07 1.txt
[xpcode@localhost ~]$ cat 1.txt
cat: 1.txt: 权限不够
[xpcode@localhost ~]$ chmod u+r 1.txt
[xpcode@localhost ~]$ ls -l
总用量 4
-r--------. 1 xpcode xpcode 12 3月 20 09:07 1.txt
[xpcode@localhost ~]$ cat 1.txt
hello XPcode1
## 为了方便其他用户查看,我们先将1.txt放到/tmp目录下。
[xpcode@localhost ~]$ mv 1.txt /tmp/
[xpcode@localhost ~]$ ls /tmp/
1.txt
## wangwu用户:
[wangwu@localhost ~]$ cd /tmp/
[wangwu@localhost tmp]$ cat 1.txt
cat: 1.txt: 权限不够
[wangwu@localhost tmp]$ chmod o+r 1.txt
chmod: 更改"1.txt" 的权限: 不允许的操作
## 切换到xpcode:给o加上r权限,再看效果
[xpcode@localhost ~]$ chmod o+r /tmp/1.txt
[xpcode@localhost ~]$ ls -l /tmp/
总用量 8
-r-----r--. 1 xpcode xpcode 12 3月 20 09:07 1.txt
## 再切换到wangwu来查看文件内容:
[wangwu@localhost tmp]$ cat 1.txt
hello XPcode
# 写权限的作用:
## 但是wangwu想编辑文件,也是没有权限的。可以vi打开,但是编辑之后不能保存。
## 再切换到xpcode,给o一个w权限,wangwu就可以编辑保存了。
[xpcode@localhost ~]$ chmod o+w /tmp/1.txt
[xpcode@localhost ~]$ ls -l /tmp/
总用量 8
-r-----rw-. 1 xpcode xpcode 12 3月 20 09:07 1.txt
wangwu编辑保存一下,查看内容:
[wangwu@localhost tmp]$ vi 1.txt
[wangwu@localhost tmp]$ cat 1.txt
hello XPcode
hello wangwu
## 可执行权限的作用:这个需要我们创建一个命令文件才能看效果,我复制某个命令文件过来,谁复制过来的,这个文件的属主就是谁,如下
. 代表当前目录
.. 代表上一级目录
## 切换到xpcode用户来复制ls文件到/tmp目录下,并将执行权限去掉,去掉执行权限的文件显示位白色,有执行权限的显示为绿色。
[xpcode@localhost ~]$ cd /tmp/
[xpcode@localhost tmp]$ cp /bin/ls .
[xpcode@localhost tmp]$ ls -l
-r-----rw-. 1 xpcode xpcode 25 3月 20 09:24 1.txt
-rwx------. 1 root root 836 3月 15 20:14 ks-script-ed2ODG
-rwxr-xr-x. 1 xpcode xpcode 117608 3月 20 09:29 ls
[xpcode@localhost tmp]$ chmod -x ls
[xpcode@localhost tmp]$ ls -l
-r-----rw-. 1 xpcode xpcode 25 3月 20 09:24 1.txt
-rwx------. 1 root root 836 3月 15 20:14 ks-script-ed2ODG
-rw-r--r--. 1 xpcode xpcode 117608 3月 20 09:29 ls
## 切换到wangwu来执行一下ls这个文件: 注意,不能直接ls,直接ls还是调用系统/bin/ls文件,需要写./ls才是使用当前目录下的ls文件,或者写这个文件的绝对路径/tmp/ls,或者将它放到某个特定目录下,就可以直接使用对应指令而不用管路径了,这个我在下面有补充说明。
[wangwu@localhost tmp]$ ./ls
-bash: ./ls: 权限不够
[wangwu@localhost tmp]$ /tmp/ls
-bash: /tmp/ls: 权限不够## 通过echo $PATH可以看到,类似于windows的环境变量中的PATH。反式放到这个目录中的命令程序,我们可以在任意目录下通过这个命令程序名称来直接调用命令来执行:
[xpcode@localhost tmp]$ echo $PATH # 下面这几个就是环境变量路径存放位置
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/xpcode/.local/bin:/home/xpcode/bin
xpcode@localhost tmp]$ cp ./ls /home/xpcode/bin/
[xpcode@localhost tmp]$ ls /home/xpcode/bin/
ls
[xpcode@localhost tmp]$ mv /home/xpcode/bin/ls /home/xpcode/bin/xxx
# 为了不和系统默认的ls冲突,我们改名为xxx
[xpcode@localhost tmp]$ ls /home/xpcode/bin/
xxx
[xpcode@localhost tmp]$ xxx
[xpcode@localhost tmp]$ xxx # 命令可以在任意目录下直接执行
1.txt
ls权限值:
r 4
w 2
x 1
- 0
权限值表
0 ---
1 --x
2 -w-
3 -wx
4 r--
5 r-x
6 rw-
7 rwx
## 修改权限举例
## 如果我们想将某个文件的:rwxr-xr-x权限改为--x-w-r--,如果按照前面我们chmod指定字母的形式来修改,就比较麻烦,直接使用权限对应的数字改就很方便:
rwxr-xr-x 对应的值为:755
--x-w-r-- 对应的值为:124
[xpcode@localhost tmp]$ chmod 124 1.txt
[xpcode@localhost tmp]$ ls -l
---x-w-r--. 1 xpcode xpcode 25 3月 20 09:24 1.txt
## 别人再问你,某个文件的权限是多少的时候,我们一般都是直接报数字值,比如它的权限是755
#改变文件的权限,例如:chomd -r,就是去掉r权限,chomd +r就是加上读权限
chmod
例子1:
#修改权限之前
[test1@localhost tmp]$ ls -l
-rw-rw----. 1 test1 test1 8 7月 20 17:20 test1.txt\
#修改权限
[test1@localhost tmp]$ chmod u+x test1.txt
#修改权限之后
[test1@localhost tmp]$ ls -l
-rwxrw----. 1 test1 test1 8 7月 20 17:20 test1.txt
例子2:
## 同时修改多个权限
[test1@localhost tmp]$ chmod u-x,g-x,o+x test1.txt
[test1@localhost tmp]$ ls -l
-rw-rw---x. 1 test1 test1 8 7月 20 17:20 test1.txt
例子3:
## 数字修改更方便
[test1@localhost tmp]$ chmod 777 test1.txt
[test1@localhost tmp]$ ls -l
-rwxrwxrwx. 1 test1 test1 8 7月 20 17:20 test1.txt#修改文件的所属,普通用户是不能修改其他用户文件的所属的,需要root用户,所以先切换到root用户来操作
chown例子1
## 修改所属用户和用户组,test2:test2,前面的test2表示用户,后面的test2是组
[root@localhost tmp]# chown test2:test2 ls
[root@localhost tmp]# ls -l
-rwxr-xr-x. 1 test2 test2 159024 7月 20 17:43 grep
-rwxr-xr-x. 1 test2 test2 117608 7月 20 17:38 ls
-rwxr-xr-x. 1 test1 test1 130360 7月 20 17:43 mv
-rw-rw-rw-. 1 test1 test1 14 7月 20 17:38 test1.txt
# chown -R nginx:nginx .
# 把当前文件夹所有文件及子文件都改成nginx用户和Nginx组的# 修改所属用户
[root@localhost tmp]# chown test1 ls
[root@localhost tmp]# ls -l
-rwxr-xr-x. 1 test2 test2 159024 7月 20 17:43 grep
-rwxr-xr-x. 1 test1 test2 117608 7月 20 17:38 ls
-rwxr-xr-x. 1 test1 test1 130360 7月 20 17:43 mv
-rw-rw-rw-. 1 test1 test1 14 7月 20 17:38 test1.txt例子3:文件夹(目录权限)
##用root用户创建一个文件夹,文件夹默认所属用户和组为root:root,那么普通用户是没全限制在这个目录中创建文件的。
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# mkdir XPcode
[root@localhost tmp]# ls -l
drwxr-xr-x. 2 root root 6 3月 20 11:36 XPcode
## 普通用户,比如xpcode想在里面创建文件:
[xpcode@localhost tmp]$ cd XPcode/
[xpcode@localhost XPcode]$ touch 2.txt
touch: 无法创建"2.txt": 权限不够
## 如何让xpcode有创建文件的权限呢?创建文件的权限就是目录写权限
## 首先要切换到root用户,然后用root用户修改目录权限,或者直接将目录的所属修改为xpcode修改权限:
[root@localhost tmp]# chmod o+w XPcode
[root@localhost tmp]# ls -l
drwxr-xrwx. 2 root root 6 3月 20 11:36 XPcode
## 切换到xpcode,创建文件:
[xpcode@localhost XPcode]$ touch 2.txt
[xpcode@localhost XPcode]$ ls
2.txt
## 修改所属:
[root@localhost tmp]# chmod o-w XPcode
[root@localhost tmp]# ls -l
drwxr-xr-x. 2 root root 19 3月 20 11:39 XPcode
[root@localhost tmp]# chown xpcode:xpcode XPcode
[root@localhost tmp]# ls -l
drwxr-xr-x. 2 xpcode xpcode 19 3月 20 11:39 XPcode
## 切换到xpcode:
[xpcode@localhost XPcode]$ touch 3.txt
[xpcode@localhost XPcode]$ ls
2.txt 3.txt
## xpcode也可以修改目录的权限了,因为它完全属于的xpcode:
[xpcode@localhost tmp]$ chmod o+w XPcode
[xpcode@localhost tmp]$ ls -l
drwxr-xrwx. 2 xpcode xpcode 32 3月 20 11:42 XPcode#使用uid和gid修改文件的所属用户和所属用户组 属主,属组
例子2:
[root@localhost tmp]# ls -l
-rwxr-xr-x. 1 test2 test2 159024 7月 20 17:43 grep
-rwxr-xr-x. 1 test1 test2 117608 7月 20 17:38 ls
-rwxr-xr-x. 1 test1 test1 130360 7月 20 17:43 mv
-rw-rw-rw-. 1 test1 test1 14 7月 20 17:38 test1.txt
[root@localhost tmp]# id test1
uid=1000(test1) gid=1000(test1) 组=1000(test1)
[root@localhost tmp]# id test2
uid=1001(test2) gid=1001(test2) 组=1001(test2)
[root@localhost tmp]# useradd -g test1 test3
[root@localhost tmp]# id test3
uid=1002(test3) gid=1000(test1) 组=1000(test1)
[root@localhost tmp]# chown 1001:1001 test1.txt
[root@localhost tmp]# ls -l
-rwxr-xr-x. 1 test2 test2 159024 7月 20 17:43 grep
-rwxr-xr-x. 1 test1 test2 117608 7月 20 17:38 ls
-rwxr-xr-x. 1 test1 test1 130360 7月 20 17:43 mv
-rw-rw-rw-. 1 test2 test2 14 7月 20 17:38 test1.txt## 文件权限: rwx 读写执行
## 目录的权限:
## rwx,r表示可以查看目录下有哪些文件
## x表示可以cd切换到该目录
## w表示可以在目录中创建、修改、删除文件等操作
## 为了安全操作:
## 文件权限默认: 644权限、狠一点就给600权限
## 目录权限默认: 755权限、狠一点就给700权限#文件属性
[root@localhost ~]# ls -l
-rw-rw-rw-. 1 xpcode xpcode 0 3月 20 16:00 222.txt
#第一段的第一个字符,表示文件类型
## -文件、
## d目录、
## l软链接(对应着windows快捷方式)、
## b块设备(ls /dev,可以看到硬盘sda等)
#第一段第2-4字符,表示该文件所属用户的权限
#第一段第5-7字符,表示该文件所属用户组的权限
#第一段第8-10字符,表示其他用户对该文件的权限
#第一段的第11个字符. ,表示开启selinux的状态下创建的,也证明selinux是开启状态的。
# 看到.表示这个文件受到selinux的保护,selinux:https://baike.baidu.com/item/SELinux/8865268?fr=aladdin,这个东西很安全,但是有了它变得很麻烦,安全和便利一般是冲突的。主要是红帽系的系统(redhat\centos\阿里的龙蜥\华为的欧拉)有这个机制。我们一般上来就是关闭它,安全方面我们通过其他方法来控制。查看selinux的指令:
# 查看状态
[xpcode@localhost tmp]$ sestatus
SELinux status: enabled # enabled表示开启状态,disabled表示禁用状态
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
# 关闭和开启selinux,需要root权限才能修改
[root@localhost tmp]# ls -l /etc/selinux/config
-rw-r--r--. 1 root root 543 3月 15 20:11 /etc/selinux/config
[root@localhost tmp]# vi /etc/selinux/config
把7行改为: SELINUX=disabled #然后保存退出,并且重启系统才会生效。
# 然后再登录创建文件,查看文件信息,就看不到.了
[root@localhost ~]# touch 1.txt
[root@localhost ~]# ls -l
-rw-r--r-- 1 root root 0 3月 20 13:32 1.txt
#第二段的数字,表示该文件的硬链接数量,其实这个和我们的安全没有太大关系,运维人员需要学习,ln是创建硬链接的指令。我们不提了
#第三段的字符串,表示该文件所属用户
#第四段的字符串,表示该文件所属用户组
#第五段的数字,表示该文件的大小,默认单位为B,如果想按照KB来显示,那么可以通过ls -lh指令来查看。h是human的意思,以人类可读的方式显示,会自动按照文件大小来设定显示单位。
#第六段到倒数第二段,都是该文件的修改时间,只要改动了文件内容,这个时间就会自动变为修改文件时的时间。
#其实linux系统会记录三个时间:
# 访问时间(access time) 文件被打开时自动变化这个时间
# 修改时间(modify time) 文件内容发生变化时自动改变这个时间,ls -l 显示的就是这个时间。
# 改变时间(change time) 文件属性发生变化时自动改变这个时间,文件大小也是文件的属性,所以修改文件内容导致大小变化的时候,这个时间也会自动改变。 #windows系统也会记录三个时间:访问时间、创建时间、修改时间
#linux下通过stat指令来查看:
[root@localhost ~]# stat 1.txt
文件:"1.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:801h/2049d Inode:67108933 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
最近访问:2023-03-20 13:32:34.333042228 +0800
最近更改:2023-03-20 13:32:34.333042228 +0800
最近改动:2023-03-20 13:32:34.333042228 +0800
创建时间:-
# 我们改一下文件权限,然后再看时间
[root@localhost ~]# chmod 777 1.txt
[root@localhost ~]# stat 1.txt
文件:"1.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:801h/2049d Inode:67108933 硬链接:1
权限:(0777/-rwxrwxrwx) Uid:( 0/ root) Gid:( 0/ root)
最近访问:2023-03-20 13:32:34.333042228 +0800
最近更改:2023-03-20 13:32:34.333042228 +0800
最近改动:2023-03-20 13:56:43.005634151 +0800 # 改动时间变了
创建时间:-
#最一段,该文件的名称希望这篇文章能够为你在探索 Linux系统的道路上提供有力的帮助,让你在操作 Linux 系统时更加得心应手。 我是
旺仔SeC,是一名热衷于系统技术的博主,对 Linux系统有着深入的研究和丰富的实践经验。我致力于分享各种系统相关的知识和技巧,帮助大家解决在使用过程中遇到的各种问题。如果你觉得这篇文章对你有所帮助,欢迎点赞、收藏和分享哦同时,也希望你能关注我的博客,我会持续为大家带来更多优质的系统技术文章,包括但不限于 Linux> 系统的深入探索、系统优化、故障排除以及各种有趣的实战案例。 如果你在学习和使用 Linux 系统的过程中遇到任何问题,或者对某些内容有疑问,欢迎在评论区留言,我会尽力为大家解答。让我们一起在系统技术的海洋中遨游,不断提升自己的技能水平,共同探索系统世界的奥秘 再次感谢大家的阅读,期待我们下次再见!