您的位置:首页 > 其它

10.众里寻他千百度- Find命令和文件后缀

2017-12-23 10:52 155 查看
二周第五次课(12月22日)

2.23/2.24/2.25 find命令

2.26 文件名后缀

快捷键:
Ctrl + l  :清屏
Ctrl + d :退出终端(相当于执行了:exit 或logout)
Ctrl + c : 强制中断
Ctrl + u : 在命令输入行,删除光标前的字符串
Ctrl + e :  光标移到末尾
Ctrl + a :  光标移到开始

find命令

which :搜索命令,查找可执行文件的绝对路径(从echo $PATH环境变量下的目录查找)

whereis 命令通过预先生成的一个文件列表库查找与给出的文件名相关的文件,类似于模糊查找

locate命令类似于whereis,这个命令使用前要安装mlocate软件包



用来定位指令的二进制程序、源代码文件和man手册页等相关文件的路径。

find :搜索文件,在指定目录下查找文件
根据文件类型进行搜索
find -type/-name

[root@xavi-001 ~]# yum install -y mlocate
已加载插件:fastestmirror, langpacks

[root@xavi-001 ~]# find /etc/ -name "sshd_config"
/etc/ssh/sshd_config
[root@xavi-001 ~]# find /etc/ -name "sshd*"
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd

f 普通文件

[root@xavi-001 ~]# find /etc/ -type f -name "sshd*"
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/etc/pam.d/sshd

l 链接文件,软链接即为该类型

[root@xavi-001 ~]# find /etc/ -type l




d 目录

c 字符设备文件,也叫串行端口设备,鼠标,键盘,打印机

b 块设备

[root@xavi-001 ~]# find /dev/ -type b
/dev/sr0
/dev/sda3
/dev/sda2
/dev/sda1
/dev/sda

s socket套接字文件,用于进程之间的通信,MySQL时会用到

p Fifo

stat 文件 查看信息









根据文件时间戳进行搜索

atime +n/-n 天,-amin/分 :用户最近一次访问或执行时间。

-mtime +n/-n天,-mmin/分:文件最后一次写入,修改时间。

ctime +n/-n 天,-cmin/分 :文件数据(例如权限等)最后一次修改时间。

举例:

[root@xavi-001 ~]# find /etc/ -type f -mtime -1
/etc/resolv.conf
/etc/tuned/active_profile


查找f类型文件,1天之内,且文件为.conf的文件
[root@xavi-001 ~]# find /etc/ -type f -ctime -1 -name "*.conf"
/etc/resolv.conf


or表示为o,或者,==但此处运行失败==

[root@xavi-001 ~]# [root@xavi-001 ~]# find /etc/ -type f -o -mtime -1 -o -name "*.conf"
bash: [root@xavi-001: command not found...


用find查找硬链接



find缩小查找范围到分钟,然后查看文件



exec 加命令 find的扩展用法



find查找大于5k,和小于5k的文件

[root@xavi-001 ~]# find /root/ -size +5k
/root/.bash_history
[root@xavi-001 ~]# find /root/ -size -5k
/root/
/root/.bash_logout


find 查找同时验证其大小 -exec ls -lh {} \
[root@xavi-001 ~]# find /root/ -type f -size -10k -exec ls -lh {} \;
-rw-r--r--. 1 root root 18 Dec 29  2013 /root/.bash_logout
-rw-r--r--. 1 root root 176 Dec 29  2013 /root/.bash_profile
-rw-r--r--. 1 root root 176 Dec 29  2013 /root/.bashrc
-rw-r--r--. 1 root root 100 Dec 29  2013 /root/.cshrc
-rw-r--r--. 1 root root 129 Dec 29  2013 /root/.tcshrc
-rw-r--r--. 1 root root 1.7K Aug  9 00:17 /root/initial-setup-ks.cfg


二 文件名后缀

Linux下的文件有后缀名,但不代表文件的类型,不像Windows下比如file.txt是文本文档、file.exe是可执行程序。
为了方便识别,要求使用统一的后缀名

.sh       脚本或批处理文件
.bz2     bzip2的压缩文件
.gz       gzip的压缩文件
.tar       tar打包文件
.tbz      tar打包并用bzip压缩文件
.tgz      tar打包并用gzip压缩的文件
.conf    配置文件
.lock     LOCK文件(用来判断一个文件或设备是否被使用)
.rpm     REDHATPackage.Manager文件(套件包或软件包)
.c         C源程序代码文件
.cpp     C++源程序代码文件
.h         C或C++程序的头文件
.o         程序目标文件
.pl        perl脚本文件
.so       类库文件


修改支持显示中文 zh_CM.UTF-8

[root@xavi-001 ~]# LANG=zh_CN.utf-8
[root@xavi-001 ~]# stat 2.txt
stat: 无法获取"2.txt" 的文件状态(stat): 没有那个文件或目录

三 Linux 和Windows互传文件

安装软件包 lrzsz

[root@xavi-001 ~]# yum install -y lrzsz


sz命令,从linux 传到 windows



rz命令 ,从windows传到linux,



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  find 文件后缀