简体   繁体   中英

Exclude hidden files and folders in linux find

I am trying to exclude hidden files and folders when doing a find in linux.

I have to exclude files or folders that start with a dot (.hidden) but also have to exclude folders that start with an @ (like @eaDir).

So far I have the following command which seems to work but maybe there is a more elegant way?

find /path/to/start/search/ -not -path '*@eaDir*' -not -path "*/\.*" -type f -mtime -2 

I did see examples using regular expression like so:

find . \( ! -regex '.*/\..*' \) -type f

but not sure how I would also exclude @eaDir directories with the -regex option?

I believe there can also be hidden files that start with two dots? like "..hidden"? Is this already covered with my command or would I simply add a third option like -not -path "*/\..*" to exclude those as well?

Then I saw some examples of using -prune so that find won't descend in hidden directories, however I am unsure how I would use this correclty in my example. I would be interested in this to speed things up.

Thanks!

Use -not -name '.*' . This will exclude any names that begin with . .

Exclude files and folders starting with a . or an @ :

find /path/to/start/search/ -not -path '*/[@.]*' -type f -mtime -2

Exclude files starting with a . and files and folders starting with a . or an @ :

find /path/to/start/search/ -not -path '*/.*' -type f -mtime -2 | grep -v '/@.*/.*'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM