9月18日任务node
2.23/2.24/2.25 find命令数据库
2.26 文件名后缀express
which 搜索可执行文件,必须在PATH环境变量目录中!!不然没法搜到!vim
[root@centos7 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls
用来查找一个命令相关的文件(二进制文件、源文件和manual文件)centos
[root@centos7 ~]# whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
默认系统未安装 使用 yum install -y mlocate 安装;locate会搜索包含命令后续所给参数的全部文件!!bash
初次完装须要初始化数据库:updatedbui
[root@centos7 ~]# yum install -y mlocate [root@centos7 ~]# updatedb [root@centos7 ~]# locate ls /boot/grub2/i386-pc/blscfg.mod /boot/grub2/i386-pc/cbls.mod /boot/grub2/i386-pc/command.lst /boot/grub2/i386-pc/crypto.lst ...
默认在天天凌晨4点会自动执行数据库的更新;centos7
注意:在更新后新建立的文件、目录,使用locate命令将没法搜索到,这时手动执行 updatedb 后才能搜索到!spa
ctrl + d 暂停执行的命令3d
ctrl + c 中止执行的命令
ctrl + u 删除光标前至开头的输入
ctrl + a 移动光标至行首
ctrl + e 移动光标至行尾
stat命令能够显示文件、目录的三个时间
atime 访问时间
mtime 更改时间(改的是内容)
ctime 改动时间(权限、名称、inode号)
修改了内容,其mtime会变,同时ctime也会变(inode会随内容变化而变化),但atime不变。
cat命令只会更新atime
vim命令修改文件但不保存不更新三个time
vim命令修改文件并保存,三个time都更新
chmod修改权限更新ctime
touch命令三个time都更新(很特殊)
使用echo追加数据至文件,不改变atime!由于文件未被查看,也没被打开,可是文件的内容、inode都变了,所以mtime和ctime变了!
!!但凡更改了mtime,ctime会随之更改;但反过来更改ctime,mtime却不必定改变。(touch命令状况除外)
对文件内容进行修改,文件的inode号随之更改,所以ctime会改变;
而改变了文件的权限,文件的ctime会改变,可是只要文件的内容不变,mtime不会改变(touch除外)
一个功能强大的搜索命令
使用方法:find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
-name 按文件名来查找(-iname 忽略大小写)
-type 按文件类型来查找
-size 按文件大小来查找
-inum 按inode号来查找
-depth 大类
按目录深度来查找(具体有-maxdepth/-mindepth)
-time 大类 按时间来查找(具体有-amin/cmin/mmin,atime/ctime/mtime)
-executable 按是否可执行(有x权限)
-newer 按是否比参考文件更新(修改时间里如今更近),对应的有-older参数
-user/group 按文件的全部者/所属组来查找
-perm MODE 按文件权限(数字形式)
-uid/gid 按文件的uid/gid来查找
-delete 对查找的内容进行删除操做
# 配置-name使用,删除找到的文件/目录 [root@centos7 test]# find /test/ -name "*.txt" -delete
# 将大于100M的文件建立备份 # 注意命令最后的“\;” [root@centos7 test]# find / -type f -size +100M -exec cp {} {}.bak \;
# -print0打印时会将换行符也取消,显示内容的一部分会出如今下一个提示符行首 [root@centos7 test]# find /test -type d -print0 /test/test/dir1[root@centos7 test]# [root@centos7 test]# find /test -type d -print /test /test/dir1
配合管道和xargs
它会将目录的子目录下的文件也都显示出来!! [root@centos7 test]# find /test -type f | xargs ls -l -rw-r--r--. 2 root root 8 ... /test/1.txt -rw-r--r--. 2 root root 8 ... /test/2.txt -rw-r--r--. 1 root root 0 ... /test/dir1/test.txt
-a 同时知足多个条件
# 多个条件限定查找 [root@centos7 test]# find /root -type d -a -name "test" | xargs ls -ld drwxr-xr-x. 3 root root 162 ... /root/test
[root@centos7 test]# find /root -name "tmp" -o -name "test" | xargs ls -ld drwxr-xr-x. 3 root root 162 ... /root/test drwxr-xr-x. 2 root root 73 ... /root/tmp
Linux下的文件后缀没有什么实际意义,给文件添加后缀的目的是为了方便区分!!
使用stat命令能够查看文件类型!