1. 使用标准的正则表达式语法:
  • -regextype posix-extended -regex
find src -regextype posix-extended -regex '.*\.(ts|scss|vue)' | xargs wc -l | tail -1


  • mac 下的默认find工具不支持regextype参数,需要下载linux 下find工具
  • brew install coreutils
  • brew install findutils


find . -name "*.php" -print -exec wc -l {} \; | awk '{a+=$1}END{print a}'


3.指定时间

  • -mtime: 修改时间,单位为24小时
  • -atime: 读时间,单位为24小时
 find /var/log/ -mtime +3 -type f -print  


4.指定文件类型

  • -type f


其他用法举例:

find . -iname "*.jpg"


# To find directories:

find . -type d 


# To find files:

find . -type f


# To find files by octal permission:

find . -type f -perm 777


# To find files with setuid bit set:

find . -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l


# To find files with extension '.txt' and remove them:

find ./path/ -name '*.txt' -exec rm '{}' \;


# To find files with extension '.txt' and look for a string into them:

find ./path/ -name '*.txt' | xargs grep 'string'


# To find files with size bigger than 5 Mb and sort them by size:

find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z


# To find files bigger thank 2 MB and list them:

find . -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'


# To find files modified more than 7 days ago and list file information

find . -type f -mtime +7d -ls


# To find symlinks owned by a user and list file information

find . -type l --user=username -ls


# To search for and delete empty directories

find . -type d -empty -exec rmdir {} \;


# To search for directories named build at a max depth of 2 directories

find . -maxdepth 2 -name build -type d


# To search all files who are not in .git directory

find . ! -iwholename '*.git*' -type f


# To find all files that have the same node (hard link) as MY_FILE_HERE

find . -type f -samefile MY_FILE_HERE 2>/dev/null


# To find all files in the current directory and modify their permissions

find . -type f -exec chmod 644 {} \;


# To find files with extension '.txt.' and edit all of them with vim

# vim is started only once for all files

find . -iname '*.txt' -exec vim {} \+


find用法集锦

find用法集锦

2018-12-23 17:14:31 1 89
author 王小波 3个分享文章
这里是评论

相关推荐