一、查看文件属性
[root@qulan ~]# ls -li
总用量 20
33574979 -rw-------. 1 root root 1437 3月 17 15:05 anaconda-ks.cfg
第1列:索引节点,形态是数字
第2列:首字符代表文件类型
中间9个字符,文件的权限
. 和selinux(高级安全组件)相关符号
第3列:硬链接数
第4列:用户【文件对应的用户】
第5列:用户组【文件的家庭成员】
第6列:文件大小【目录不是】
第7-9列:日期时间
第10列:文件名
二、Linux文件类型:
ls -li 第2列,首字符代表文件类型
d 目录
l 软链接文件
[root@qulan ~]# ln -s /etc/hosts /tmp/a.hosts 【源文件】【快捷方式】
[root@qulan ~]# cat /tmp/a.hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
c 字符设备
b 扩设备
[root@qulan ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8, 0 3月 21 08:25 /dev/sda
brw-rw----. 1 root disk 8, 1 3月 21 08:25 /dev/sda1
brw-rw----. 1 root disk 8, 2 3月 21 08:25 /dev/sda2
s socket文件
三、wc 查看行数,字符数
-l 查看行数
[root@qulan ~]# wc -l /etc/hosts
2 /etc/hosts
-m 查看字符数
[root@qulan ~]# echo qulan| wc -m
6
四、查找命令:
1、which 查看二进制命令所在路径
2、where 查看文件及文件的帮助等的路径
(1)-b 查看二进制命令所在路径 which
[root@qulan ~]# whereis -b cp
cp: /usr/bin/cp
3、find 查找*
find 路径 选项 【参数】
(1)按名字查找
[root@qulan ~]# find / -name "hosts" //按名字在根下查找
/etc/hosts
按名字模糊查找 *表示没有
[root@qulan ~]# find / -name "hos*s"
/etc/hosts
/usr/src/kernels/3.10.0-862.el7.x86_64/fs/hostfs
(2)按类型查找
- type
f d l c b s
[root@qulan ~]# find /root -type d //按d目录查找
/root
/root/qulan_dir
[root@qulan ~]# find /root -type f //按f文件查找
root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
① 组合查找:find默认就是取交集(-a),并集(-o)or
②取反:!
[root@qulan ~]# find /data/ -name "file1"
/data/file1
[root@qulan ~]# find /data/ ! -name "file1"
/data/
/data/file2
/data/file3
(3)按大小查找
-size +1M 大于1M
-size 1M 1M
-size -1M 小于1M
[root@qulan ~]# find ./ -size -10k
./
./.bash_logout
./.bash_profile
./.bashrc
(4)-mtime按修改时间查找
-atime 按【访问】时间查找
-ctime 按【改变】时间查找
-mtime +7 #7天以前的
-mtime 7 #第7天
-mtime -7 #最近7天
①测试:模拟每天创建一个文件,连续30天
for n in {01..30};do date -s "2030/05/0$n";touch /data/file$n;done
(5)-exec 执行动作
find / -name "qulan" -exec rm -f {} \;
(6)xargs
① -n 分组
[root@qulan data]# xargs -n 3 <qulan.txt
1 2 3
4 5 6
7 8 9
10
②-i