linux(二)文件属性

linux(二)文件属性

[root@localhost ceshi]# ll README
-  rwx   rwx   rwx   .   1   root ll    1160   8月5 10:26 README
|   |     |     |        |    |    |      |          |       |
|   |     |     |        |    |    |      |          |   filename
|   |     |     |        |    |    |      | date/time lastmodified
|   |     |     |        |    |    |    size
|   |     |     |        |    | group name
|   |     |     |        | user(owner)name
|   |     |     |     number of hard links
|   |     |  other                            r   w   x
|   |   group                                 |   |  执行
|  user                                       |file type

常见文件类型

文件类型标识文件类型
-普通文件
d目录
l符号链接
s套接字
b块设备
c字符设备
p管道

file查看文件类型

[ll@localhost ceshi]$ file passwd.bak
passwd.bak: ASCII text
[ll@localhost ceshi]$ file ceshi
ceshi: directory

find查找文件

在指定/home目录中查找name为passwd.bak的文件
[ll@localhost /]$ find /home -name passwd.bak
/home/ll/ceshi/passwd.bak

find其他常用参数

[ll@localhost ceshi]$ ls -lh
总用量 44K
drwxrwxr-x. 2 ll ll    6 84 22:20 ceshi
-rw-r--r--. 1 ll ll  18K 84 21:35 functions
-rwxr-xr-x. 1 ll ll 4.5K 84 21:35 netconsole
-rwxr-xr-x. 1 ll ll 7.8K 84 21:35 network
-rw-r--r--. 1 ll ll 2.3K 84 21:44 passwd.bak
-rw-r--r--. 1 ll ll 1.2K 84 21:36 README
在当前目录查找大于15k的文件
[ll@localhost ceshi]$ find . -size +15k
./functions
在当前目录查找小于2k的文件
[ll@localhost ceshi]$ find . -size -2k
.
./ceshi


find / -empty   # 查找在系统中为空的文件或者文件夹
find / -group name  # 查找在系统中属于 groupname的文件
find / -mmin -2   # 查找在系统中最后2分钟里修改过的文件
find / -user ll #查找在系统中属于ll这个用户的文件

su与su - 切换用户

[root@localhost ~]# su - ll
上一次登录:五 85 10:14:16 CST 2022:0 上
[ll@localhost ~]$
[ll@localhost ~]$ su - root  #输入root密码
密码:
上一次登录:五 85 10:16:31 CST 2022pts/0 上
[root@localhost ~]#

su 与su -的区别,su切换了用户但并没有完全切换。env查看环境变量。

[ll@localhost ~]$ su root
密码:
[root@localhost ll]# env
XDG_SESSION_ID=2
HOSTNAME=localhost.localdomain
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
USER=ll
...
HOME=/root
SHLVL=2
LOGNAME=ll
XDG_DATA_DIRS=/home/ll/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/bin/env


[ll@localhost ~]$ su - root
密码:
上一次登录:五 85 10:18:36 CST 2022pts/0 上
[root@localhost ~]# env
XDG_SESSION_ID=2
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
USER=root
...
HOME=/root
LOGNAME=root
XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/bin/env

浅谈文件的读、写、执行

r:Read 读

w:Write 写

x:eXecute 执行

owner 属主,缩写u

group 属组,缩写g

other 其他,缩写o

                   读   写    执行      读   写    执行     读   写    执行
字符                r   w      x         r   w      x      r   w      x
数字表示            4   2      1         4   2      1      4   2      1
                   文件所有者            文件所属组用户      其他用户 

常用权限

444 r--r--r--
600 rw-------
644 rw-r--r--
666 rw-rw-rw-
777 rwxrwxrwx

chmod改变文件权限

[ll@localhost ceshi]$ chmod 000 README
[ll@localhost ceshi]$ ll README
----------. 1 ll ll 1160 85 10:26 README
[ll@localhost ceshi]$ chmod 777 README
[ll@localhost ceshi]$ ll README
-rwxrwxrwx. 1 ll ll 1160 85 10:26 README

chown更改文件的所有者或组(change owner)

-R 递归式地改变指定目录及其下的所有子目录和文件的拥有者。

[root@localhost ceshi]# ll
总用量 4
-rwxrwxrwx. 1 ll ll 1160 85 10:26 README
[root@localhost ceshi]# chown root:root README
[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root root 1160 85 10:26 README

chgrp改变用户的组

[root@localhost ceshi]# chgrp ll README
[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root ll 1160 85 10:26 README

umask查看默认文件权限

[root@localhost ceshi]# umask
0022

特殊权限

setuid

命令功能: **临时使用命令的属主权限执行该命令。**即如果文件有suid权限时,那么普通用户去执行该文件时,会以该文件的所属用户的身份去执行.

会在属主权限位的执行权限上写个s。 如果该属主权限位上有执行权限,则会在属主权限位的执行权限上写个s(小写); 如果该属主权限位上没有执行权限,则会在属主权限位的执行权限上写个S(大写)

数字权限是4000

[root@localhost ceshi]# chmod 4777 README
[root@localhost ceshi]# ll
总用量 4
-rwsrwxrwx. 1 root ll 1160 8月   5 10:26 README
[root@localhost ceshi]# chmod u-s README
[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root ll 1160 8月   5 10:26 README

setgid

命令功能: **临时使用命令的属组权限执行该命令。**即如果文件有suid权限时,那么普通用户去执行该文件时,会以该文件的所属用户的身份去执行.

会在属组权限位的执行权限上写个s。 如果该属组权限位上有执行权限,则会在属组权限位的执行权限上写个s(小写); 如果该属组权限位上没有执行权限,则会在属主权限位的执行权限上写个S(大写)

数字权限是2000

[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root ll 1160 8月   5 10:26 README
[root@localhost ceshi]# chmod 2777 README
[root@localhost ceshi]# ll README
-rwxrwsrwx. 1 root ll 1160 8月   5 10:26 README
[root@localhost ceshi]# chmod g-s README
[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root ll 1160 8月   5 10:26 README

sticky(sbit)粘滞位

命令功能:粘滞位,只对目录有效,对某目录设置粘滞位后,普通用户就算有w权限也只能删除该目录下自己建立的文件,而不能删除其他用户建立的文件。

如果该其他用户权限位上有执行权限,则会在其他用户权限位的执行权限上写个t(小写); 如果该其它用户权限位上没有执行权限,则会在其他用户权限位的执行权限上写个T(大写)。

系统中存在的/tmp目录是经典的粘滞位目录,谁都有写权限,因此安全成问题,常常是木马第一手跳板。

sbit数字权限是1000

[root@localhost ceshi]# chmod 1777 README
[root@localhost ceshi]# ll README
-rwxrwxrwt. 1 root ll 1160 85 10:26 README
[root@localhost ceshi]# chmod o-t README
[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root ll 1160 85 10:26 README

chattr更改文件的扩展属性

比chmod更改的rwx更底层

一些参数
A:Atime,告诉系统不要修改对这个文件的最后访问时间。
a:Append Only,系统只允许在这个文件之后追加数据,不允许任何进程覆盖,不允许删除任何文件。
i:即Immutable,系统不允许对这个文件进行任何的修改。
R:递归修改目录属性
V:显示命令执行过程

经典之保护文件不允许修改

[root@localhost ceshi]# chattr +i README
[root@localhost ceshi]# ll README
-rwxrwxrwx. 1 root ll 1160 85 10:26 README
[root@localhost ceshi]# lsattr README
----i----------- README

经典之只允许文件追加信息,比如日志文件

[root@localhost ceshi]# chattr +a README
[root@localhost ceshi]# lsattr README
-----a---------- README

lsattr查看文件的扩展属性

一些参数
-R 递归列出目录及其下内容属性
-V 显示程序版本
-a 列出所有内容包含.开头的文件
-v 显示文件版本
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值