要想成功,永远比别人多做一点点,早做一点点,做好一点点.
文件属性 比如 大小 用户 组 权限 创建时间
三种时间
最近访问:2021-05-12 12:13:30 access 访问,浏览,针对内容
最近更改:2021-05-10 10:31:31 modify 最后更改时间,针对内容
最近改动:2021-05-10 10:31:31 change 状态改变,属性改变
使用ls -li 查看的详细信息,每一列是干什么用的
35111123 -rwx-w---x. 1 root root 188 May 12 16:20 oldboy.txt
第一列 索引节点(数字)
第二列 首字符代表文件类型 中间9个字符,文件权限 .和selinux(高级安全组建)相关符号
第三列 硬链接数
第四列 文件对应的用户
第五列 文件对应的用户组
第六列 文件大小(目录不是)
第七-九列 文件访问时间
第十列 文件名
Linux文件类型 不根据扩展名确定类型,但是依然会有扩展名,为了给人看.一眼看清楚,系统不识别扩展名
ls -li 第二列首字符代表文件类型
一切皆文件
- ----> 普通文件 ***** 白色
d ----> 目录 directory **** 浅蓝色
l ----> 软链接文件(快捷方式) link **** ln -s 创建软链接 ls -l /bin
c ----> 字符设备
b ----> 块设备文件 **** 磁盘 /dev/sd*
s ----> socket文件 进程通信才会用到 /dev/log
file可以查看文件类型
wc 查看行数,字符数等
wc -l 查看行数
wc -L 查看字符数
wc -w 查看单词数
查找命令:
1.which 查看二进制命令所在路径(从PATH环境变量路径里查找)
特殊注意:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
1)分隔符为冒号:
2)路径都是命令
2.whereis 查看文件及文件的帮助等路径
-b 查看二进制 命令所在路径 = which
3.locate 查找文件 以及相关内容(内置数据库,通过 updatedb)
yum -y install mlocate
locate XXX
4.find 查找
1.find按名字查找
find 路径 -name " 文件名 "
模糊查找*表示所有
find / -name "ho*ts"
2.find按类型查找
参数 f 文件 d 目录 l 链接 b 块设备 c 字符设备 s 套接字文件
find 路径 -type f/d/l/b/c/s
man find 搜/-type
组合查找:默认取交集(-a) ,并集(-o)
查文件类型为文件,并且名字为hosts
find / -name "hosts" -type f
取反: !
find 路径 ! -name " " -type f
3.find按大小查找
find 路径 -size (-)+5M((小于)大于5M) k G
4.find按时间查找
find 路径 -mtime 按修改时间查找
find 路径 -atime 按访问时间查找
find 路径 -ctime 按改变时间查找
查找7天以前的文件(不会打印当天的文件)
find ./ -type f -mtime +7
查找最近7天的文件,不建议使用(会打印当天的文件)
find ./ -type f -mtime -7
查找第7天文件(不会打印当天的文件)
find ./ -type f -mtime 7
查找后排序
find . -mtime +7|sort -n -t"e" -k2
不重要
5.find按用户查找(用户跟组)
-user 用户
-group 组
-nouser 没有用户
-nogroup 没有组
find . -user xxx
6.find按权限查找
find / -perm XXX
精确匹配XXX权限
find / -perm -XXX
包含XXX权限即可
查找全局可写(每位权限必须包含w)
find / -perm -222
包含set uid
find /usr/sbin -perm -4000
包含set gid
find /usr/sbin -perm -2000
对找到的东西进行处理
方法一
-exec 执行动作
find /data/ -name "file*" -mtime -7 -exec rm -f {} \; 查找到的文件删除
原理: rm -rf file{24..30}
find /data/ -name "file*" -mtime 7 -exec rm -f {} \; 查找到的文件删除
==rm -rf file23
find /data/ -name "file*" -mtime +7 -exec rm -f {} \; 查找到的文件删除
==rm -rf file{01..22}
方法二
命令行 :$(命令) 或'命令', 拼路径拼命令
rm -f $(find /data -name "file*" -type f -mtime +7)
rm -f $(find /data -name "file*" -type f -mtime 7)
rm -f $(find /data -name "file*" -type f -mtime -7)
方法三
xargs -n 分组
xargs -i 可以让后面的{}接收搜索到的内容
简短的:find /data/ -name "file*" -mtime -7 | xargs rm -f
find /data/ -name "file*" -mtime -7 | xargs -i rm -f {}
原理: rm -f file01 file02..file30
find /data/ -name "file*" -mtime 7 | xargs -i rm -f {}
find /data/ -name "file*" -mtime +7 | xargs -i rm -f {}