2.23/2.24/2.25 find命令 2.26 文件名后缀

find命令


搜索工具 which :用于查找可执行文件的绝对路径;

[root@linux-128 ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls

whereis:通过预先生成的一个文件列表库查找与给出的文件名相关的文件; 格式: whereis [选项] 文件名 -b:只查找二进制文件; -m:只查找帮助文件; -s:只查找源代码文件;

[root@linux-128 ~]# whereis -b ls
ls: /usr/bin/ls
[root@linux-128 ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

locate:和whereis类似,也是通过查找预先生成的文件列表库来查找文件在哪里,后面直接跟文件名;需要安装mlocate软件包:

[root@linux-128 ~]# yum install -y mlocate
[root@linux-128 ~]# updatedb
[root@linux-128 ~]# locate yum.log
/var/log/yum.log

安装好后,第一次运行locate会报错,需要运行updatedb命令立即生成或者更新这个库文件;默认情况下这个库每周更新一次;locate不适合精准查找。


find命令

格式:find [路径] [参数]

  • -type 文件类型:f(文件)d(目录)l(软链接)s(sock)d(块设备)c(串口设备键盘鼠标等)
  • -name 文件名
  • -size 文件大小(10K;10M等)
  • -mmin +- 分钟数
  • -inum 跟inode,通过inode来查找一个文件的硬链接
  • -o 或者
  • -exec <执行指令>:假设find指令的回传值为True,就执行该指令。
  • -atime +n/-n 表示访问或执行时间大于或小于n天的文件。
  • -ctime +n/-n 表示更改inode属性(如更改所有者,权限或者链接)的时间大于或小于n天的文件。
  • -mtime +n/-n 表示创建或者修改文件时间大于或小于n天的文件,该参数用得最多
  • -1 小于1天;1天以内
  • +1 大于1天;1天以前
  • 不能等于1

例子:

  • 查找1天内创建或修改的后缀名为.conf的文件
[root@linux-128 ~]# find /etc/ -type f -mtime -1 -name "*.conf"
/etc/resolv.conf
  • 查找root目录下1天内创建或修改的文件
[root@linux-128 ~]# find /root/ -type f -mtime -1
/root/.bash_history
/root/321.txt
  • 查找root目录下10分钟内创建的文件
[root@linux-128 ~]# find /root/ -type f -mmin -10
/root/11.txt
  • 查找root目录下10分钟创建或修改的文件,并且显示出具体修改时间;
[root@linux-128 ~]# find /root/ -type f -mmin -10 -exec ls -l {} \;
-rw-r--r-- 1 root root 0 10月 27 22:03 /root/11.txt

小知识:{}表示前面列出来的文件,\脱意符号,;换行符

  • 查找目录/root/下1天内修改的文件,并且备份一份。
[root@linux-128 ~]# find /root/ -type f -mtime -1 -exec cp {} {}.bak \;
[root@linux-128 ~]# ls -al /root/
总用量 84
dr-xr-x---.  4 root root   288 10月 27 22:13 .
dr-xr-xr-x. 17 root root   265 10月 19 15:07 ..
-rw-r--r--   1 root root     0 10月 27 22:03 11.txt
-rw-r--r--   1 root root     0 10月 27 22:13 11.txt.bak
lrwxrwxrwx   1 root root     9 10月 27 01:12 12 -> /tmp/111/
drwxr-xr-x   2 root root     6 10月 27 22:03 123
-rw-------.  2 root root     0 10月 17 03:40 1.log
-rw-r--r--   1 root root 16816 10月 27 01:31 321.txt
-rw-r--r--   1 root root 16816 10月 27 22:13 321.txt.bak
-rw-------.  1 root root  1422 10月 17 03:51 anaconda-ks.cfg
-rw-------.  1 root root  6339 10月 27 01:40 .bash_history
-rw-------   1 root root  6339 10月 27 22:13 .bash_history.bak
-rw-r--r--.  1 root root    18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root   176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root   176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root   100 12月 29 2013 .cshrc
-rw-------   1 root root    41 10月 25 00:48 .lesshst
drwx------.  2 root root    80 10月 19 17:04 .ssh
-rw-r--r--.  1 root root   129 12月 29 2013 .tcshrc
  • 查看root目录下小于6k的文件,并且列出它具体的大小
[root@linux-128 ~]# find /root/ -type f -size -6k -exec ls -lh {} \;
-rw-r--r--. 1 root root 18 12月 29 2013 /root/.bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 /root/.bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 /root/.bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 /root/.cshrc
-rw-r--r--. 1 root root 129 12月 29 2013 /root/.tcshrc
-rw-------. 1 root root 1.4K 10月 17 03:51 /root/anaconda-ks.cfg
-rw-r--r--. 1 root root 806 10月 18 19:41 /root/.ssh/authorized_keys
-rw-r--r-- 1 root root 176 10月 19 16:24 /root/.ssh/known_hosts
-rw------- 1 root root 1.7K 10月 19 17:04 /root/.ssh/id_rsa
-rw-r--r-- 1 root root 396 10月 19 17:04 /root/.ssh/id_rsa.pub
-rw------- 1 root root 41 10月 25 00:48 /root/.lesshst
-rw-------. 2 root root 0 10月 17 03:40 /root/1.log
-rw-r--r-- 1 root root 0 10月 27 22:03 /root/11.txt
-rw-r--r-- 1 root root 0 10月 27 22:13 /root/11.txt.bak
  • 通过inode来查找一个文件的硬链接;
[root@linux-128 ~]# ls -i 1.log
8388681 1.log
[root@linux-128 ~]# find -inum 8388681
./1.log
[root@linux-128 ~]# find / -inum 8388681
/root/1.log
/tmp/yum.log

stat命令

stat命令可以列出文件的atime,mtime,ctime;

[root@linux-128 ~]# stat 11.txt
  文件:"11.txt"
  大小:0         	块:0          IO 块:4096   普通空文件
设备:803h/2051d	Inode:16799023    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2017-10-27 22:13:47.084544630 +0800  //atime 
最近更改:2017-10-27 22:03:41.825691647 +0800  //mtime
最近改动:2017-10-27 22:03:41.825691647 +0800  //ctime
创建时间:-

linux文件后缀名 在linux系统中,文件的后缀名没有具体的意义,加或者不加都无所谓。


linux和window互传文件

工具:xshell securecet
安装lrzsz包

yum install -y lrzsz
命令:sz 文件名   linux上传到windows
         rz 直接回车,windows上传文件到linux,传到当前目录中

转载于:https://my.oschina.net/u/3866516/blog/1827126

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值