[toc]
find命令 和 文件名后缀
快捷键:
Ctrl + l :清屏
Ctrl + d :退出终端(相当于执行了:exit 或logout)
Ctrl + c : 强制中断
Ctrl + u : 在命令输入行,删除光标前的字符串
Ctrl + e : 光标移到末尾
Ctrl + a : 光标移到开始
一 find命令
先介绍在Linux中常用的几个快捷键:
Ctrl + l :清屏
Ctrl + d :退出终端(相当于执行了:exit 或logout)
Ctrl + c :强制中断
Ctrl + u :在命令输入行,删除光标前的字符串
Ctrl + e :光标移到末尾
Ctrl + a :光标移到开始
which :搜索命令,查找可执行文件的绝对路径(从echo $PATH环境变量下的目录查找)
whereis 命令通过预先生成的一个文件列表库查找与给出的文件名相关的文件,类似于模糊查找
locate命令类似于whereis,这个命令使用前要安装mlocate软件包,安装命令:yum install -y 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 文件 查看信息
cat之后只改变了atime
根据文件时间戳进行搜索- 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的文件,find /etc/ -type f -ctime -1 -name "*.conf"
[root@xavi-001 ~]# find /etc/ -type f -ctime -1 -name "*.conf"
/etc/resolv.conf
or表示为o,或者,find /tmp/ -type f -o -mtime -1 -o -name "aliases"
[root@xaviyunserver ~]# find /tmp/ -type f -o -mtime -1 -o -name "aliases"
/tmp/
/tmp/bin
/tmp/11.txt
/tmp/123
/tmp/123/1.txt
用find查找硬链接
find缩小查找范围到分钟,然后查看文件
exec 加命令 find的扩展用法 find /root/ -type f -mmin -700 -exec mv {} {} ;
find查找大于5k,和小于5k的文件, find /root/ -size +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,