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

效率更好

相关推荐
小刘不想改BUG几秒前
LeetCode LCR 015. 找到字符串中所有字母异位词 (Java)
linux·算法·leetcode
Hi2024021726 分钟前
如何通过partclone克隆Ubuntu 22系统
运维·服务器·ubuntu
Li_yizYa1 小时前
网络原理 | 网络基础概念复习
运维·服务器·网络·计算机网络
s_little_monster1 小时前
【Linux】socket网络编程基础
linux·运维·网络·笔记·学习·php·学习方法
猴子请来的逗比4891 小时前
nginx负载均衡及keepalive高可用
运维·学习·nginx·负载均衡
FL171713142 小时前
UR5e机器人Matlab仿真
linux·matlab·机器人
不知几秋6 小时前
数字取证-内存取证(volatility)
java·linux·前端
欧先生^_^9 小时前
Linux内核可配置的参数
linux·服务器·数据库
海尔辛10 小时前
学习黑客5 分钟读懂Linux Permissions 101
linux·学习·安全
王RuaRua11 小时前
[数据结构]5. 栈-Stack
linux·数据结构·数据库·链表