Using Grep Include/Exclude Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Grep Include/Exclude Files
# 1  
Old 10-27-2011
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

Code:
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

Code:
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.

Code:
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
# 2  
Old 10-27-2011
Try adding -a for and:

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

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 10-27-2011
Many thanks for the reply:

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

Regards

Last edited by metallica1973; 10-27-2011 at 10:06 PM..
# 4  
Old 10-27-2011
Try -mtime -1 instead of -mtime 0

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

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 10-28-2011
many many thanks,one more question:

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

Code:
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
# 6  
Old 10-28-2011
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.

Code:
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.

Code:
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.

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

# 7  
Old 10-28-2011
I tried

Code:
[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:

Code:
/home/*/.*

and ran:

Code:
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude multiple lines using grep

Hi, I'm working on a shell script that reports service status on a database server. There are some services that are in disabled status that the script should ignore and only check the services that are in Enabled status. I output the service configuration to a file and use that information to... (5 Replies)
Discussion started by: senthil3d
5 Replies

2. Shell Programming and Scripting

Rsync exclude & include?

hi I have a few folders and a few files , for example Directory A B C D E Files 1 2 3 4 5 I want B directory and "2" File that does not sync But other directories and file sync What is the solution ? Is there a way to sync time is under one minute? os centos 6.8 thanks... (5 Replies)
Discussion started by: mnnn
5 Replies

3. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

4. UNIX for Dummies Questions & Answers

Is there a good way to grep multiple directories without --include?

Hello. I consider myself a journeyman Unix user. I can handle most day to day tasks and have created some fairly complicated command queries, but this problem has defeated me so far. Any help would be greatly appreciated! We keep an archive in the file system with a directory structure in... (5 Replies)
Discussion started by: pauliesyllabic
5 Replies

5. Red Hat

SFTP user include/exclude without preventing SSH login

I have been asked to see if we can restrict SFTP access to authorised users only. There will be business users who will log on with SSH, but they are locked into a menu. They will have write access to the production data to do their job, but we don't want them to have access to read/write the... (8 Replies)
Discussion started by: rbatte1
8 Replies

6. Shell Programming and Scripting

Exclude dash in grep

Hi, I must be overlooking something, but I don't understand why this doesn't work. I'm trying to grep on a date, excluding all the lines starting with a dash: testfile: #2013-12-31 2013-12-31code: grep '^2013-12-31' testfileI'm expecting to see just the second line '2013-12-31' but I don't... (3 Replies)
Discussion started by: Subbeh
3 Replies

7. Shell Programming and Scripting

Grep for a srting & exclude two folders

Hi, Below is the command to grep for a string under grep -r "redeem" /home/tom Need to make it case insensitive and exclude logs & tmp folders under /home/tom directory in my Search. Need this in Linux. (1 Reply)
Discussion started by: mohtashims
1 Replies

8. Shell Programming and Scripting

grep a string with include next 100 line

Hi, I have a log file which has number of lines from that i have to grep a string like this 03:22:19,287 while greping this string i have to grep next lines to the maximum of finding the word (MORE...) the stack is like this ************* 22/11/2011 03:22:19,287 232290646 ERROR... (2 Replies)
Discussion started by: thelakbe
2 Replies

9. UNIX for Advanced & Expert Users

grep source code and exclude comments

I often find myself grepping source code for a variable name and many times the name would be present in comment lines that I 'd prefer not to see. Do you guys know any tricks to filter out comments? Example: snippet of the source code /*** * type comment 1 ***/ void ... (7 Replies)
Discussion started by: migurus
7 Replies

10. UNIX for Advanced & Expert Users

how to exclude the GREP command from GREP

I am doing "ps -f" to see my process. but I get lines that one of it represents the ps command itself. I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself : I would like to exclude # ps -f UID PID PPID C STIME TTY TIME CMD... (2 Replies)
Discussion started by: yamsin789
2 Replies
Login or Register to Ask a Question