day09-Linux文件类型及查找文件

1. 文件属性

bash 复制代码
[root@oldboy ~]# ls -il
总用量 16
33574978 -rw-------. 1 root root 1438 11月 26 21:25 anaconda-ks.cfg

1:索引节点

2:文件类型和权限,第一个表示文件类型,中间表示文件权限,最后的.表示selinux-高级安全组件

plaintext 复制代码
# linux文件类型
- 普通文件
d 目录 directory
l 软连接(快捷方式) link
c 字符设备 char
b 块设备 block
s socket文件

3:硬链接数量

4:所属用户

5:所属用户组

6:文件大小

789:日期,月 日 时:分

10:文件名


查看文件类型:

bash 复制代码
[root@oldboy ~]# file a.txt 
a.txt: ASCII text

文件的三种时间:

2. wc命令

显示文件的行数、单词数和字节大小

bash 复制代码
[root@oldboy ~]# wc a.txt 
 30  30 277 a.txt

-l :显示行数

bash 复制代码
[root@oldboy ~]# wc -l a.txt
30 a.txt

-c :显示文件的字节数

bash 复制代码
[root@oldboy ~]# wc -c a.txt
277 a.txt

-L:查看最长行的字符数

bash 复制代码
[root@oldboy ~]# wc -L a.txt
9 a.txt

3. find 查找命令

在根目录下按照文件名查找文件位置,文件名用双引号:

bash 复制代码
[root@oldboy ~]# find / -name "hosts"
/etc/hosts
bash 复制代码
[root@oldboy ~]# find / -name "a.*t" #可以使用通配符查找
/root/a.txt

按文件类型查找,查找/root目录下的文件或目录:

普通文件类型用f

bash 复制代码
[root@oldboy ~]# find /root -type f
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/anaconda-ks.cfg
/root/.bash_history
/root/.lesshst
/root/test.txt
/root/uniq
/root/a.txt
/root/.viminfo
/root/wc
bash 复制代码
[root@oldboy ~]# find /root -type d
/root
/root/.pki
/root/.pki/nssdb

组合查找

bash 复制代码
[root@oldboy ~]# find /root -type f -name "a.txt"
/root/a.txt
-----------------------------
[root@oldboy ~]# find /root -type f -a -name "a.txt"
/root/a.txt

默认就是取交集(-a),取并集用-o

bash 复制代码
[root@oldboy ~]# find /root -name "*.txt" -o -name "a.txt"
/root/test.txt
/root/a.txt

取反,用!

bash 复制代码
[root@oldboy ~]# find /root ! -name "a.txt"
/root
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/anaconda-ks.cfg
/root/.bash_history
/root/.lesshst
/root/.pki
/root/.pki/nssdb
/root/test.txt
/root/uniq
/root/.viminfo
/root/wc

按大小查找:

bash 复制代码
[root@oldboy ~]# find /root -size -1k #查找小于1K字节的文件
/root/wc

按修改时间查找 ,-mtime:

后续处理

-exec

将查找到的文件删掉,{}表示接收查找的结果

bash 复制代码
[root@oldboy ~]# find ./ -name "*.txt" -exec rm -f {} \;
[root@oldboy ~]# ll
总用量 16
-rw-------. 1 root root 1438 11月 26 21:25 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 12月 19 21:13 rm
-rw-r--r--. 1 root root  126 12月 18 21:27 uniq

原理:

rm -f a.txt

rm -f test.txt

方法二:

bash 复制代码
 find ./ -name "*.txt" | xargs -i rm -f {}

原理:

rm -f a.txt test.txt

效率更好

相关推荐
数巨小码人7 分钟前
Linux下文件权限与安全
linux
yuanbenshidiaos14 分钟前
【进程 】
linux
ChoSeitaku1 小时前
12.重复内容去重|添加日志|部署服务到Linux上(C++)
linux·c++·windows
一颗小树x2 小时前
Llama 3.1 本地电脑部署 Linux系统 【轻松简易】
linux·llama·本地部署·3.1
技术小齐2 小时前
网络运维学习笔记 017HCIA-Datacom综合实验01
运维·网络·学习
大囚长2 小时前
AI工作流+专业知识库+系统API的全流程任务自动化
运维·人工智能·自动化
Struggle Sheep2 小时前
linux安装redis
linux·运维·redis
butteringing3 小时前
BuildFarm Worker 简要分析
linux·软件构建·bazel·re api
saynaihe4 小时前
2025吐槽季第一弹---腾讯云EO边缘安全加速平台服务
运维·安全·云计算·腾讯云
@#---4 小时前
删除驱动精灵的详细过程
运维·服务器