Linux的find命令使用

简介: 【5月更文挑战第11天】Linux的find命令使用

find 命令在 Linux 系统中用于在指定路径下查找文件和目录。它的基本语法如下:

find [路径] [选项] [操作]
  • [路径]:指定查找的路径,默认为当前目录。
  • [选项]:可以是一系列控制 find 行为的选项,例如 -name-type 等。
  • [操作]:可以是对找到的文件执行的操作,例如 -print

以下是一些常用的 find 命令选项和示例用法:

  1. 按文件名查找:

    find /path/to/search -name "filename"
    

    这将在 /path/to/search 目录中查找名为 "filename" 的文件。

  2. 按类型查找:

    find /path/to/search -type f
    

    这将在 /path/to/search 目录中查找普通文件。

  3. 按大小查找:

    find /path/to/search -size +10M
    

    这将在 /path/to/search 目录中查找大于 10MB 的文件。

  4. 按权限查找:

    find /path/to/search -perm 644
    

    这将在 /path/to/search 目录中查找权限为 644 的文件。

  5. 按时间查找:

    find /path/to/search -mtime -7
    

    这将在 /path/to/search 目录中查找最近 7 天内修改过的文件。

  6. 组合条件查找:

    find /path/to/search -name "*.txt" -size +1M
    

    这将在 /path/to/search 目录中查找大于 1MB 的 .txt 文件。

  7. 执行操作:

    find /path/to/search -name "*.log" -exec rm {
         } \;
    

    这将在 /path/to/search 目录中查找 .log 文件并删除它们。

  8. 显示结果:

    find /path/to/search -name "*.txt" -print
    

    这将在 /path/to/search 目录中查找 .txt 文件并显示它们的路径。

find 命令还有许多其他选项和用法,你可以使用 man find 命令查看完整的 find 命令手册以获取更多信息。

目录
相关文章
|
2天前
|
Linux
Linux常用命令包括
Linux常用命令包括
10 5
|
2天前
|
Linux
Linux命令
Linux命令
13 5
|
6天前
|
Linux Python Perl
Linux命令删除文件里的字符串
Linux命令删除文件里的字符串
18 7
|
6天前
|
Shell Linux
Linux shell编程学习笔记82:w命令——一览无余
Linux shell编程学习笔记82:w命令——一览无余
|
8天前
|
Linux Perl
Linux之sed命令
Linux之sed命令
|
8天前
|
Linux
深入理解Linux中的cp命令:文件与目录的复制利器
深入理解Linux中的cp命令:文件与目录的复制利器
|
18天前
|
存储 Linux Shell
linux查找技巧: find grep xargs
linux查找技巧: find grep xargs
26 13
|
8天前
|
Linux Docker 容器
9. 同步执行Linux多条命令
9. 同步执行Linux多条命令
|
8天前
|
Linux Shell
10-10|linux命令查询 关键字在文本中出现的行数
10-10|linux命令查询 关键字在文本中出现的行数
|
9天前
|
存储 Linux Shell
常用vim命令和vim基本使用及Linux用户的管理,用户和组相关文件
这篇文章介绍了Vim编辑器的基本使用、常用命令和模式,以及Linux系统中用户和组的管理方法,包括用户和组相关文件如/etc/passwd、/etc/shadow和/etc/group的说明。
常用vim命令和vim基本使用及Linux用户的管理,用户和组相关文件
下一篇
无影云桌面