Using Grep Include/Exclude Files

I wrote this korn script and ran into a hole. I can use find to exclude all the hidden directories and to use my include file/exclude files for running a full backup

find / -depth -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs

but when I try and look for file modification within 24hr, it doesn't work.I want to see if there are any differences within 24 hours of the same Include/Exclude directories

find / -depth -mtime 0 -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs

it just spits out the opposite of what I want. Eventually i will pass this to CPIO and create an archive.

find / -depth -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs | cpio -oavc > /backup/directory/full.cpio

find / -depth -mtime 0 -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs | cpio -oavc > /backup/directory/incremental.cpio

regards

Try adding -a for and:

find / -depth -mtime 0 -a \( -ipath '/home/testuser/.*' -prune -o -print \) | grep -f include.mydirs | grep -v -f exclude.mydirs
1 Like

Many thanks for the reply:

it did work. I made an adjustment in my exclude.mydir. i was blocking my test directory.

Regards

Try -mtime -1 instead of -mtime 0

find / -depth -mtime -1 -a \( -ipath '/home/testuser/.*' -prune -o -print \) | grep -f include.mydirs | grep -v -f exclude.mydirs
1 Like

many many thanks,one more question:

How can I exclude all hidden directories from everyones home directories when using find:

find /home -depth -path '*/.*' -prune -o -print

I want to remove all ".*" hidden junk from all the home directories:

/home/user1/.*
/home/user2/.*
/home/user3/.*

thanks

This will ignore any hidden file or directory (begining with a dot) in user's home directory, or any depth of sub-directory below that.

find /home -depth -path '/home/*/.*' -prune -o -print

This just excludes any hidden file in user's home directory, or any depth of sub-directory below that.

find /home -depth -name '.*' -prune -o -print

I don't think you can exclude just .files in the home directory using find. You man have to throw a grep/awk/sed in the pipeline.

find /home -depth | grep -v '^/home/[^/]*/\.[^/]*$'

I tried

[root@home]# find /home -depth | grep -v '^/home/[^/]*/\.[^/]*$'
/home/wireless/.mozilla/plugins
/home/wireless/.mozilla/extensions
/home/wireless
/home/noble/.mozilla/plugins
/home/noble/.mozilla/extensions
/home/noble
/home/lost+found
/home/becky/.mozilla/plugins
/home/becky/.mozilla/extensions
/home/becky
/home/gary/.mozilla/plugins
/home/gary/.mozilla/extensions
/home/gary
/home/dabeast/.openoffice.org/3/user/config/styles_cs.sod
/home/dabeast/.openoffice.org/3/user/config/styles_en-US.sod

and it doesnt seem to work. ?

---------- Post updated at 12:45 AM ---------- Previous update was at 12:38 AM ----------

i tried just adding to my exclude file:

/home/*/.*

and ran:

sudo find /home -depth -mtime 0 -print | grep -f include_home | grep -v -f exclude_home

and it didnt display anything at all but when I removed it all was normal again.
It should work what am I missing?

Try this for excluding the hidden files...

find /home ! -path "*/\.*"

--ahamed

1 Like

this worked:

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

but it would be nice to just use the exclude file for this stuff.

---------- Post updated at 01:03 AM ---------- Previous update was at 12:58 AM ----------

wow to easy. good stuff. I just attempted to add that to my exclude file using grep and it didnt work. There is some trick to the format in this exclude file that would make this alot easier. Regardless many thanks:b:

---------- Post updated at 01:08 AM ---------- Previous update was at 01:03 AM ----------

this seem to have worked:

sudo find /home -depth -mtime 0 ! -path "*/\.*" -print | grep -f include_home | grep -v -f exclude_home

I still have this itch with the exclude file. I need to dig a little further into that for it would make things easier.

regards