LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-16-2015, 12:43 AM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Rep: Reputation: 177Reputation: 177
Need find syntax to exclude files and directories


I have the following find command:

Code:
find /mnt/hd/Windows -type d \( -path /mnt/hd/Windows/System32/config \
        -o -path /mnt/hd/Windows/Prefetch \
        -o -path /mnt/hd/Windows/System32/LogFiles \
        -o -path /mnt/hd/Windows/System32/wdi/LogFiles \
        -o -path /mnt/hd/Windows/System32/winevt/Logs \
        -o -path /mnt/hd/Windows/security \) -prune -o \
        -o -not /mnt/hd/Windows/rescache/rc0011/ResCache.hit \
        -not /mnt/hd/Windows/WindowsUpdate.log -print
Excluding the directories works fine, but the bit underlined does not. I've tried various things. Can someone help?
 
Old 09-16-2015, 02:44 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
You are looking for directories according to -type d thus I wonder why it prints files.
You also have a double -o before the ResCache.hit line.

Can you please provide some output the command generates?
 
Old 09-16-2015, 07:08 AM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Original Poster
Rep: Reputation: 177Reputation: 177
Quote:
Originally Posted by zhjim View Post
You are looking for directories according to -type d thus I wonder why it prints files.
There is a "-prune" after the list of directories. That part works; i.e. the find works if you remove the underlined part.

Quote:
You also have a double -o before the ResCache.hit line.
Good catch. I took that out and still have the error.

Quote:
Can you please provide some output the command generates?
Code:
find: paths must precede expression: /mnt/hd/Windows/rescache/rc0011/ResCache.hit
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
 
Old 09-16-2015, 07:24 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by mfoley View Post
I have the following find command:

Code:
find /mnt/hd/Windows -type d \( -path /mnt/hd/Windows/System32/config \
        -o -path /mnt/hd/Windows/Prefetch \
        -o -path /mnt/hd/Windows/System32/LogFiles \
        -o -path /mnt/hd/Windows/System32/wdi/LogFiles \
        -o -path /mnt/hd/Windows/System32/winevt/Logs \
        -o -path /mnt/hd/Windows/security \) -prune -o \
        -o -not /mnt/hd/Windows/rescache/rc0011/ResCache.hit \
        -not /mnt/hd/Windows/WindowsUpdate.log -print
Excluding the directories works fine, but the bit underlined does not. I've tried various things. Can someone help?
what is it that you are trying to get.

i think you are trying to check for the existence of these directories:
/mnt/hd/Windows/System32/config
/mnt/hd/Windows/Prefetch
/mnt/hd/Windows/System32/LogFiles
/mnt/hd/Windows/System32/wdi/LogFiles
/mnt/hd/Windows/System32/winevt/Logs
/mnt/hd/Windows/security


or list any sub-directory not under /mnt/hd/Windows/rescache/rc0011/ResCache.hit nor /mnt/hd/Windows/WindowsUpdate.log :
Code:
find /mnt/hd/Windows -type d \( -path /mnt/hd/Windows/System32/config \
        -o -path /mnt/hd/Windows/Prefetch \
        -o -path /mnt/hd/Windows/System32/LogFiles \
        -o -path /mnt/hd/Windows/System32/wdi/LogFiles \
        -o -path /mnt/hd/Windows/System32/winevt/Logs \
        -o -path /mnt/hd/Windows/security \) -prune \
        -o ! /mnt/hd/Windows/rescache/rc0011/ResCache.hit \
        -o ! /mnt/hd/Windows/WindowsUpdate.log
 
Old 09-16-2015, 09:33 AM   #5
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
@schneidz Hes trying to exclude the directories given and ignore two files.

If possible leave out the -type d option. Cause it tells find to only look at directories.

To get a working list you might also pipe the output to grep and ignore the 2 files. So this is only usuable if you only have those 2 files you want to ignore.
 
1 members found this post helpful.
Old 09-16-2015, 11:09 AM   #6
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Original Poster
Rep: Reputation: 177Reputation: 177
Quote:
Originally Posted by zhjim View Post
@schneidz Hes trying to exclude the directories given and ignore two files.
Exactly!

[quote]If possible leave out the -type d option. Cause it tells find to only look at directories.{/quote]

Didn't work, same error message.

Quote:
To get a working list you might also pipe the output to grep and ignore the 2 files. So this is only usuable if you only have those 2 files you want to ignore.
Yeah, not usable that way - will likely have more than those files, plus I'm really running -exec not -print, so not really easy to grep.

What about:

Code:
    find /mnt/hd/Windows -type d \( -path /mnt/hd/Windows/System32/config \
        -o -path /mnt/hd/Windows/Prefetch \
        -o -path /mnt/hd/Windows/System32/LogFiles \
        -o -path /mnt/hd/Windows/System32/wdi/LogFiles \
        -o -path /mnt/hd/Windows/System32/winevt/Logs \
        -o -path /mnt/hd/Windows/SoftwareDistribution/DataStore/Logs \
        -o -path /mnt/hd/Windows/Logs \
        -o -path /mnt/hd/Windows/Temp \
        -o -path /mnt/hd/Windows/security \) -prune -o \
      -type f \( -path /mnt/hd/Windows/rescache/rc0011/ResCache.hit \
        -o -path /mnt/hd/Windows/WindowsUpdate.log \) -prune -o -print
I'll try that and post back ...
 
Old 09-16-2015, 11:52 AM   #7
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Original Poster
Rep: Reputation: 177Reputation: 177
OK, I think I've got it!

Code:
    find /mnt/hd/Windows -type d \( -path /mnt/hd/Windows/System32/config \
        -o -path /mnt/hd/Windows/Prefetch \
        -o -path /mnt/hd/Windows/Temp \
        -o -path /mnt/hd/Windows/security \
        -o -iregex ".*/Logs$" \
        -o -iregex ".*\.Log$" \) -prune -o \
      -type f \( -path /mnt/hd/Windows/rescache/rc0011/ResCache.hit \
        -o -iregex ".*\.log$" \) -prune -o -print
The "-type f" expression took care of the multi-file exclusion, and the -iregex let me eliminate files (and directories) by wildcard, so I don't need as big a list in either "-type d" or "-type f" sets.
 
1 members found this post helpful.
Old 09-17-2015, 01:27 AM   #8
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Nice. Good job.
 
  


Reply

Tags
find command



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Exclude directories with find to clean up a filesystem running redhat6.6. linux_nerd Linux - Software 5 08-26-2015 07:48 PM
exclude hidden files and directories from rsync rayalab Linux - General 1 07-29-2015 12:18 PM
[SOLVED] Exclude directories when searching for files Jakkie Linux - Newbie 6 02-14-2012 11:02 PM
[SOLVED] How do I exclude multiple directories in awk with find? Damarr Linux - Newbie 11 05-24-2010 02:52 PM
exclude directories from find noir911 Linux - General 3 11-22-2006 06:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration