find command search only non hidden directories

2019-06-19 00:39发布

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/

2条回答
虎瘦雄心在
2楼-- · 2019-06-19 01:08

Try

find /home/tom/project -type d -name '.*' -prune -o -name .log.txt -print
查看更多
别忘想泡老子
3楼-- · 2019-06-19 01:22

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" {} \;
查看更多
登录 后发表回答