Linux find命令

本文介绍Linux下find命令的实用技巧,包括文件查找、删除、按类型及修改时间筛选等操作。通过具体示例,帮助读者掌握find命令的强大功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先用find命令查找,再用‘| xargs rm -f ’进行删除,如果有目录用‘-rf’  ## 配合 "| xargs .."

2.同上,用‘-exec rm -f {} \; ’有目录用‘-rf’  ## -exec .. {} \; 传递语法

3.find命令,查看一分钟内修改过的文件:

find . -cmin -1  ##或写作 find . -mmin -1

4.其他

## 根据类型查看

       -type c
              File is of type c:

              b      block (buffered) special

              c      character (unbuffered) special

              d      directory

              p      named pipe (FIFO)

              f      regular file

              l      symbolic  link;  this  is  never  true  if the -L option or the -follow option is in effect,
                     unless the symbolic link is broken.  If you want to search for symbolic links when -L is  in
                     effect, use -xtype.

              s      socket

              D      door (Solaris)

## 设置检索结果的最大目录层级数和最小目录层级数

      -maxdepth levels
              Descend at most levels (a non-negative integer) levels of directories below the command line  argu-
              ments.  -maxdepth 0
               means only apply the tests and actions to the command line arguments.

       -mindepth levels
              Do not apply any tests or actions at levels less than levels (a non-negative integer).  -mindepth 1
              means process all files except the command line arguments.

## 数字参数的作用

       Numeric arguments can be specified as

       +n     for greater than n,

       -n     for less than n,

       n      for exactly n.  ## 确切地

## 根据修改时间进行查询

       -ctime n
              File’s  status  was  last  changed  n*24  hours ago.  See the comments for -atime to understand how
              rounding affects the interpretation of file status change times.

       -ctime n
              File’s  status  was  last  changed  n*24  hours ago.  See the comments for -atime to understand how
              rounding affects the interpretation of file status change times.

       -empty

              File is empty and is either a regular file or a directory.

       -mmin n
              File’s data was last modified n minutes ago.

       -mtime n
              File’s data was last modified n*24 hours ago.  See the comments for -atime to understand how round-
              ing affects the interpretation of file modification times.

       -size n[cwbkMG]
              File uses n units of space.  The following suffixes can be used:  ## suffixes 后缀

              ‘b’    for 512-byte blocks (this is the default if no suffix is used)

              ‘c’    for bytes

              ‘w’    for two-byte words

              ‘k’    for Kilobytes (units of 1024 bytes)

              ‘M’    for Megabytes (units of 1048576 bytes)

              ‘G’    for Gigabytes (units of 1073741824 bytes)

              The size does not count indirect blocks, but it does count blocks in  sparse  files  that  are  not
              actually allocated.  Bear in mind that the ‘%k’ and ‘%b’ format specifiers of -printf handle sparse
              files differently.  The ‘b’ suffix always denotes 512-byte blocks  and  never  1  Kilobyte  blocks,
              which is different to the behaviour of -ls.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值