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

效率更好

相关推荐
许白掰1 小时前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器
longze_75 小时前
Ubuntu连接不上网络问题(Network is unreachable)
linux·服务器·ubuntu
Dirschs5 小时前
【Ubuntu22.04安装ROS Noetic】
linux·ubuntu·ros
qianshanxue115 小时前
ubuntu 操作记录
linux
AmosTian8 小时前
【系统与工具】Linux——Linux简介、安装、简单使用
linux·运维·服务器
YC运维9 小时前
RIP实验以及核心原理
运维·网络·智能路由器
leo__52010 小时前
自动化运维:使用Ansible简化日常任务
运维·自动化·ansible
霖0010 小时前
C++学习笔记三
运维·开发语言·c++·笔记·学习·fpga开发
CodeWithMe11 小时前
【Note】《Kafka: The Definitive Guide》 第九章:Kafka 管理与运维实战
运维·分布式·kafka