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

效率更好

相关推荐
地衣君5 小时前
RISC-V 开发板 + Ubuntu 23.04 部署 open_vins 过程
linux·ubuntu·risc-v
5:005 小时前
云备份项目
linux·开发语言·c++
码农101号5 小时前
Linux中shell编程表达式和数组讲解
linux·运维·服务器
powerfulzyh6 小时前
非Root用户启动SSH服务经验小结
运维·ssh
云道轩6 小时前
升级centos 7.9内核到 5.4.x
linux·运维·centos
是小满满满满吗6 小时前
传输层:udp与tcp协议
linux·服务器·网络
爱学习的小道长6 小时前
Ubuntu Cursor升级成v1.0
linux·运维·ubuntu
EelBarb6 小时前
seafile:ubuntu搭建社区版seafile12.0
linux·运维·ubuntu
Xam_d_LM6 小时前
【Latex】Windows/Ubuntu 绘制 eps 矢量图通用方法(drawio),支持插入 Latex 数学公式
linux·ubuntu·科研·矢量图·drawio
402 Payment Required6 小时前
serv00 ssh登录保活脚本-邮件通知版
运维·chrome·ssh