find command search only non hidden directories

≯℡__Kan透↙ 提交于 2019-12-23 08:59:53

问题


In the following command i want to search only only the directories which are non hidden how can i do this using the following command .Iwant to ignore hidden directories while searching the log file

      find /home/tom/project/ -name '.log.txt'


   ls /home/tom/project/
   dir1
   dir2
   .backup
   .snapshot/
   .ignore/

回答1:


Try

find /home/tom/project -type d -name '.*' -prune -o -name .log.txt -print



回答2:


This will find all files but ignore those that start with a dot so hidden files.

find /home/tom/project/ -type f \( -iname ".log.txt" ! -iname ".*" \)

EDIT: If the above those not work, this should do the trick. It has a better regex.

find /home/tom/project/ \( ! -regex '.*/\..*' \) -type f -name ".log.txt"

EDIT2:

The following will exclude hidden folders but will search for the hidden files that have the requested pattern:

find /home/tom/project/ \( ! -regex '.*/\..*/..*' \) -type f -name ".log.txt"

EDIT3:

The grep solution :) if this doesn't work i'm lost :)

find /home/tom/project/ \( ! -regex '.*/\..*/..*' \) -exec grep -l ".log.txt" {} \;

EDIT4:

Have you tried the simple solutions?

find /home/tom/project/ -type f -name ".log.txt"

OR

find /home/tom/project/ -type f -name "*" -exec grep -l ".log.txt" {} \;


来源:https://stackoverflow.com/questions/9901738/find-command-search-only-non-hidden-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!