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

效率更好

相关推荐
tf的测试笔记38 分钟前
测试团队UI自动化实施方案
运维·自动化
TDD_06281 小时前
【运维】Centos硬盘满导致开机时处于加载状态无法开机解决办法
linux·运维·经验分享·centos
x66ccff1 小时前
vLLM 启动 GGUF 模型踩坑记:从报错到 100% GPU 占用的原因解析
linux
头孢头孢1 小时前
k8s常用总结
运维·后端·k8s
遇码1 小时前
单机快速部署开源、免费的分布式任务调度系统——DolphinScheduler
大数据·运维·分布式·开源·定时任务·dolphin·scheduler
William.csj1 小时前
Linux——开发板显示器显示不出来,vscode远程登录不进去,内存满了的解决办法
linux·vscode
爱编程的王小美2 小时前
Docker基础详解
运维·docker·容器
KeithTsui2 小时前
GCC RISCV 后端 -- 控制流(Control Flow)的一些理解
linux·c语言·开发语言·c++·算法
森叶2 小时前
linux如何与windows进行共享文件夹开发,不用来回用git进行拉来拉去,这个对于swoole开发者来说特别重要
linux·git·swoole
liulilittle2 小时前
Linux 高级路由策略控制配置:两个不同路由子网间通信
linux·网络·智能路由器