1、设备名称的识别
find 参数 | |
---|---|
-name | 名字 |
-user | 用户 |
-group | 组 |
-type | 类型 f:文件 l:符号连接 d:目录 c:字符设备 b:块设备 s:套接字 |
exec | 执行 |
-maxdepth | 最大深度 |
-mindepth | 最小深度 |
-cmin | 最近更改的文件 1 :1分钟, +1:大于1分钟, -1:1分钟之内 |
-o | 或者 |
-a | 而且 |
not | 相反 |
size | 大小 |
实验环境:
[root@node1 mnt]# useradd lee
[root@node1 mnt]# chown westos.lee westosfile1
[root@node1 mnt]# chown westos.westos westosfile2
[root@node1 mnt]# chown lee.lee westosfile3
[root@node1 mnt]# ll
total 0
-rw-r--r--. 1 westos lee 0 Oct 18 14:39 westosfile1
-rw-r--r--. 1 westos westos 0 Oct 18 14:39 westosfile2
-rw-r--r--. 1 lee lee 0 Oct 18 14:39 westosfile3
-rw-r--r--. 1 root root 0 Oct 18 14:39 westosfile4
-rw-r--r--. 1 root root 0 Oct 18 14:39 westosfile5
实验:
[root@node1 mnt]# find /mnt/ -name "*westos*" 查找文件
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
[root@node1 mnt]# mkdir westosdir
[root@node1 mnt]# touch westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -name westosfile1 查找目录里面的,和子目录里面的文件都能查找到
/mnt/westosfile1
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -maxdepth 1 -name westosfile1 最大深度为1层
/mnt/westosfile1
[root@node1 mnt]# find /mnt/ -maxdepth 2 -name westosfile1 最大深度为2层
/mnt/westosfile1
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -mindepth 2 -maxdepth 2 -name westosfile1 指定第2层
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -type f 查看文件
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -type d 查看目录
/mnt/
/mnt/westosdir
[root@node1 mnt]# find /mnt/ -user lee 查看用户
/mnt/westosfile3
[root@node1 mnt]# find /mnt/ -user lee -o -user westos -o表示或者 ,查询多个用户文件
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
[root@node1 mnt]# find /mnt/ -user lee -a -user lee -a 表示并且 ,-a也可以不加
/mnt/westosfile3
[root@node1 mnt]# find /mnt/ -user westos -group westos 用户和组都是westos
/mnt/westosfile2
[root@node1 mnt]# find /mnt/ -user westos -not -group westos 用户是westos,组不是westos
/mnt/westosfile1
用文件大小查找文件
制作指定文件大小
[root@node1 mnt]# dd if=/dev/zero of=/mnt/westosfile1 bs=1M count=10 bs 表示拷贝块的大小 ,count表示有多少块,dd:用指定大小的块拷贝一个文件 if=模板文件
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0484184 s, 217 MB/s
[root@node1 mnt]# dd if=/dev/zero of=/mnt/westosfile2 bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB, 20 MiB) copied, 0.0120816 s, 1.7 GB/s
[root@node1 mnt]# dd if=/dev/zero of=/mnt/westosfile3 bs=1M count=30
30+0 records in
30+0 records out
31457280 bytes (31 MB, 30 MiB) copied, 0.0175175 s, 1.8 GB/s
[root@node1 mnt]# du -sh westosfile1
10M westosfile1
[root@node1 mnt]# du -sh westosfile2
20M westosfile2
[root@node1 mnt]# du -sh westosfile3
30M westosfile3
[root@node1 mnt]# find /mnt/ -size 20M 等于20M
/mnt/westosfile2
[root@node1 mnt]# find /mnt/ -size -20M 小于20M
/mnt/
/mnt/westosfile1
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -size +20M 大与20M
/mnt/westosfile3
时间查找文件
[root@node1 mnt]# touch westosfile6
[root@node1 mnt]# find /mnt/ -cmin 1 分钟
/mnt/
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -cmin -1 1分钟以内的
/mnt/
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -cmin +1 大于1分钟的
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
权限查找文件
[root@node1 mnt]# chmod g-r /mnt/westosfile2
[root@node1 mnt]# chmod o-r /mnt/westosfile3
[root@node1 mnt]# ll
total 61440
drwxr-xr-x. 2 root root 25 Oct 18 15:12 westosdir
-rw-r--r--. 1 westos lee 10485760 Oct 18 16:41 westosfile1
-rw----r--. 1 westos westos 20971520 Oct 18 16:41 westosfile2
-rw-r-----. 1 lee lee 31457280 Oct 18 16:41 westosfile3
-rw-r--r--. 1 root root 0 Oct 18 14:39 westosfile4
-rw-r--r--. 1 root root 0 Oct 18 14:39 westosfile5
-r-r--r--. 1 root root 0 Oct 18 17:12 westosfile6
[root@node1 mnt]# find /mnt/ -perm 444 表示u位,g位,o位都必须只是r权限
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm -444 -444表示u 位,g位,o位都开启r权限
/mnt/
/mnt/westosfile1
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm /444 /444表示u位或者g位或者o位开启了r权限
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm /755 总共7个条件 rwxr-xr-x 或的关系
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm /777 总管9个条件
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm -002 表示o位有写的权限
[root@node1 mnt]# chmod 777 westosfile5
[root@node1 mnt]# ll
-rwxrwxrwx. 1 root root 0 Oct 18 14:39 westosfile5
[root@node1 mnt]# find /mnt/ -perm -002 -exec chmod u-w {} \; \表示转译符 注释分号的作用 ,-exec表示可以执行的动作
[root@node1 mnt]# find /mnt/ -name \*westos\* -exec rm -fr {} \; 删除带有westos的文件; {}表示find命令查找的结果
find: ‘/mnt/westosdir’: No such file or directory
2、设备的查看命令
设备接入系统后都是以文件的形式存在
设备名称 | ####### |
---|---|
SATA/SAS/USB | /dev/sda,/dev/sdb s=STAT ,d=DISK ,a=第几块 |
IDE | /dev/hd0,/dev/hsd1 ##h=hard |
VIRTIO-BLOCK | /dev/vda, /dev/vdb #v=virtio |
M2 (SSD) | /dev/nvme0,.dev/nvme1 #nvme=m2 |
SD/MMC/EMMC(卡) | /dev/mmcblk0,/dev/mmcblk1 # mmcblk=mmc卡 |
光驱 | /dev/cdrom,/dev/sr0,/dev/sr1 |
2.1设备查看
fdisk -l :查看磁盘分区情况 (真实存在的设备)
lsblk:设备使用情况
blkid:设备管理方式及设备id
df:查看正在被系统挂载的设备
cat /proc/partitions:查看系统识别设备 (系统识别的设备与系统识别的设备存在差异,没有uuid。无驱动,需要被提醒,)
[root@node1 mnt]# fdisk -l 查看磁盘分区情况
Disk /dev/vda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x657e7edc
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 1026047 1024000 500M 83 Linux
/dev/vda2 1026048 2050047 1024000 500M 82 Linux swap / Solaris
/dev/vda3 2050048 16777215 14727168 7G 83 Linux
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@node1 mnt]# lsblk 查看系统中识别设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 8G 0 disk
├─vda1 253:1 0 500M 0 part /boot
├─vda2 253:2 0 500M 0 part [SWAP]
└─vda3 253:3 0 7G 0 part /
vdb 253:16 0 5G 0 disk
[root@node1 mnt]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 8G 0 disk
├─vda1 253:1 0 500M 0 part /boot
├─vda2 253:2 0 500M 0 part [SWAP]
└─vda3 253:3 0 7G 0 part /
vdb 253:16 0 5G 0 disk
[root@node1 mnt]# cat /proc/partitions 查看系统中识别设备
major minor #blocks name
253 0 8388608 vda
253 1 512000 vda1
253 2 512000 vda2
253 3 7363584 vda3
253 16 5242880 vdb
[root@node1 mnt]# df 系统中被使用挂载的设备
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 907424 0 907424 0% /dev
tmpfs 935220 0 935220 0% /dev/shm
tmpfs 935220 9336 925884 1% /run
tmpfs 935220 0 935220 0% /sys/fs/cgroup
/dev/vda3 7353344 4372764 2980580 60% /
/dev/vda1 506528 218600 287928 44% /boot
tmpfs 187044 1180 185864 1% /run/user/42
tmpfs 187044 4 187040 1% /run/user/0
[root&