find命令/文件名后缀

简介: 2.23/2.24/2.25 find命令 2.26 文件名后缀   find 搜索文件的命令: which   它是从环境变量中找: [root@centos_1 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls   ...

 2.23/2.24/2.25 find命令

2.26 文件名后缀

 

find

搜索文件的命令:

which   它是从环境变量中找:

[root@centos_1 ~]# which ls

alias ls='ls --color=auto'

/usr/bin/ls

 

环境变量:

[root@centos_1 ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin

 

whereis  ls 查看文件的位置,但是查找的不全:

[root@centos_1 ~]# whereis ls

ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

 

跟whereis 很像的还有一个mlocate:

安装mlocate

 yum install  -y mlocate

 

更新一下文件数据库才行:

[root@centos_1 ~]# updatedb

 

查找: locate  finename

locate  xiaobofile

 

find 查找:find  路径  -name 文件名

[root@centos_1 ~]# find /etc/ -name "sshd_config"

/etc/ssh/sshd_config

 

 

find   路径  -type  文件类型    -name  文件名

查找目录文件:-type    d

find  /etc/    -type   d   -name "sshd*" 

[root@centos_1 ~]# find  /etc/  -type d -name "ssdh*"

查找文件类型:-type  f

[root@centos_1 ~]# find  /etc/  -type f -name "ssdh*"

 

都可以查找文件类型:

-type  l  软链接文件

-type   d 目录文件

-type   f  (-) 文件

-type   c   字符设备文件

-type   s  socket文件

-type  b  block块文件(b文件)

 

 

终端操作命令:

ctrl + l 光标移动到第一行;

ctrl + d 登出(没有输入命令下)

ctrl + u 删除光标前面的字符

ctrl + d 删除光标后面的字符

ctrl + a 光标移到到开头

ctrl + e 光标移动到末尾

 

 

 

 

stat 查看文件具体信息 : 3个time:atime  mtime  ctime  比ls更清楚:

[root@centos_1 ~]# stat anaconda-ks.cfg.1 

  文件:"anaconda-ks.cfg.1"

  大小:3360      块:8          IO 块:4096   普通文件

设备:803h/2051d Inode:67172258    硬链接:1

权限:(0600/-rw-------)  Uid:( 1000/  xiaobo)   Gid:( 1000/  xiaobo)

最近访问:2017-11-17 08:43:29.453703489 +0800

最近更改:2017-11-17 08:43:29.453703489 +0800

最近改动:2017-11-20 20:48:05.866081882 +0800

创建时间:-

 


文件名后缀 

更改为英文:LANG=en

[root@centos_1 ~]# LANG=en

[root@centos_1 ~]# stat anaconda-ks.cfg.1 

  File: 'anaconda-ks.cfg.1'

  Size: 3360      Blocks: 8          IO Block: 4096   regular file

Device: 803h/2051d Inode: 67172258    Links: 1

Access: (0600/-rw-------)  Uid: ( 1000/  xiaobo)   Gid: ( 1000/  xiaobo)

Access: 2017-11-17 08:43:29.453703489 +0800

Modify: 2017-11-17 08:43:29.453703489 +0800

Change: 2017-11-20 20:48:05.866081882 +0800

 Birth: -

 

Access 最近访问atime

Modify最近修改mtime

Change最近改动ctime

 

 

查找1天以内最近修改的文件

find  /  -type  f   -mtime   -1   (-mtime最近修改,-1一天以内)

[root@centos_1 ~]# find /etc/  -type  f -mtime -1

/etc/resolv.conf

/etc/group

/etc/gshadow

/etc/passwd

/etc/passwd-

/etc/shadow

/etc/shadow-

/etc/ld.so.cache

/etc/group-

/etc/gshadow-

/etc/tuned/active_profile

 

find  /  -type  f   -atime   -1   一天内最近访问的文件

find  /  -type  f   -ctime   -1  一天内最近改动的文件

查找.conf类型的 最近1天修改的文件:

[root@centos_1 ~]# find /etc/  -type  f -mtime -1  -name ".conf"

 

查找最近1天内修改的文件,或者最近一天内修改的文件 文件类型是.conf的(其中-o是或者)

[root@centos_1 ~]# find /etc/  -type  f -o -mtime -1  -o -name ".conf"

 

 

 

关于查找硬链接文件:

 

[root@centos_1 ~]# ln 1.txt  /tmp/1.txt.bak

[root@centos_1 ~]# ls -l /tmp/1.txt.bak 

-rw-r--r-- 2 root root 103 11月 21 04:51 /tmp/1.txt.bak

[root@centos_1 ~]# ls -i !$

ls -i /tmp/1.txt.bak

67246931 /tmp/1.txt.bak

[root@centos_1 ~]# 

 

查找文件的硬链接:

find /  -inum 67246931(后面数字是inode号)

[root@centos_1 ~]# find  /  -inum 67246931

/root/1.txt

/tmp/1.txt.bak

 

 

查找一个小时内(60分钟内)的文件:

[root@centos_1 ~]# find /root/ -type  f -mmin -60

 

查找一个小时以内的文件并同时执行ls  -l 列出详细信息

[root@centos_1 ~]# find /root/ -type  f -mmin -60 -exec ls -l {} \;

 

其中{}表示列出的列表;

 

查找一个小时内的文件并同时执行mv进行重命名

[root@centos_1 ~]# find /root/ -type  f -mmin -60 -exec mv {} {}.bak \;

[root@centos_1 ~]# find /root/ -type  f -mmin -60 

/root/1.txt.bak

 

 

查找文件大于10k的文件,并同时列出

[root@centos_1 ~]# find /root/ -size +10k -exec ls -lh {} \;

-rw-------. 1 root root 11K 11月 21 07:11 /root/.bash_history

 

查找文件小于10K的文件,并同时列出:

[root@centos_1 ~]# find /root/ -size -10k -exec ls -lh {} \;

 

查找文件大于10M,并同时列出

[root@centos_1 ~]# find /root/ -size -10M -exec ls -lh {} \;

 

总结:

find  -type    -mtime   -mmin    -size    -o (或者)   -exec     -name

                      修改的      分钟      大小     或者         执行      名字

 

 

 

 

 

目录
相关文章
|
云安全 数据采集 机器学习/深度学习
云安全 | 学习笔记
快速学习云安全,重点介绍了如何在 Linux 下进行安全防护,并从用户系统安全、SSH 安全、恶意文件安全和云安全四个角度诠释如何提升系统的安全性。
云安全 | 学习笔记
|
机器学习/深度学习 监控 数据可视化
【超详细】MMLab分类任务mmclassification:环境配置说明、训练、预测及模型结果可视化展示(3)
【超详细】MMLab分类任务mmclassification:环境配置说明、训练、预测及模型结果可视化展示
|
9月前
|
Web App开发 机器学习/深度学习 人工智能
Magic Copy:开源的 AI 抠图工具,在浏览器中自动识别图像进行抠图
Magic Copy 是一款开源的 AI 抠图工具,支持 Chrome 浏览器扩展。它基于 Meta 的 Segment Anything Model 技术,能够自动识别图像中的前景对象并提取出来,简化用户从图片中提取特定元素的过程,提高工作效率。
435 7
Magic Copy:开源的 AI 抠图工具,在浏览器中自动识别图像进行抠图
|
10月前
|
监控 IDE 开发工具
「Mac畅玩鸿蒙与硬件5」鸿蒙开发环境配置篇5 - 熟悉DevEco Studio界面
本篇将详细介绍 DevEco Studio 的界面布局和主要功能模块,帮助开发者熟悉开发环境,提高开发效率。通过了解各个界面区域,开发者可以顺利找到所需工具,流畅开展鸿蒙应用开发。
401 2
「Mac畅玩鸿蒙与硬件5」鸿蒙开发环境配置篇5 - 熟悉DevEco Studio界面
|
11月前
|
监控 网络协议 安全
|
存储 缓存 Java
Java中的延时队列(Delay Queue)
Java中的延时队列(Delay Queue)
456 3
|
监控
Chrony命令如何使用
【5月更文挑战第15天】Chrony命令如何使用
577 3
|
Java Linux 网络安全
vscode 远程服务器 java 无法跳转
【2月更文挑战第4天】
838 3
|
移动开发 安全 前端开发
〔支付接入〕微信的 h5 支付和 jsapi 支付
学会微信支付,打开你的财富之门
425 2
〔支付接入〕微信的 h5 支付和 jsapi 支付