Find the answer to your Linux question:
Results 1 to 4 of 4
I have spent the last hour searching for a solution to this, but I can't get it to work. Here is what I am trying to do: I have directories ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    9

    [SOLVED] Excluding Files From find


    I have spent the last hour searching for a solution to this, but I can't get it to work. Here is what I am trying to do:

    I have directories for different months in one folder. So for example
    Code:
    ../folder/Jan/
    ../folder/Aug/
    etc.
    Some of the folders have a dot in front of the month as so:
    Code:
    ../folder/.Sep/
    ../folder/.Oct/
    etc.
    Each folder has a .csv file representing each day of that month. It looks like this:
    Code:
    ../folder/Jan/Jan01.csv
    ../folder/Jan/Jan02.csv
    ../folder/.Oct/Oct01.csv
    ../folder/.Oct/Oct02.csv
    I am trying to find all the csv files EXCEPT those in a folder that has a dot.
    For example I want all the csv files in ../folder/Jan/ but I want none in ../folder/.Oct/.

    I also want to exclude all the files in the /Aug/ folder that represent days 10-31.

    Here is what I have so far:
    Code:
    find /some_path/folder/ \( ! -name "Aug[10-31]*.csv" ! -path "/.*/" -name "*.csv" \) | more
    This command lists all the .csv files except those in the /Aug/ files. So it just ignores the /Aug/ folder completely but lists every other .csv file.

    Thanks for any help.

    PS I also tried using prune, but I probably implemented it incorrectly, because it would not work.
    Last edited by whocares357; 10-22-2010 at 09:22 PM.

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    I guess the tricky part is filtering out hidden stuff. You may try the following
    Code:
    find /some_path/folder/ \( ! -name "Aug[10-31]*.csv" -name "*.csv" \) | grep -v "^.*/\..*/.*"
    and keep us informed. I haven't fully tried it but it seems to be what you wish on some quickly created files. This is just filtering litteral data through grep.
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  3. #3
    Just Joined!
    Join Date
    Feb 2006
    Posts
    7
    here's the 'prune' version:


    Code:
    $ find . -name '*.txt' -print
    ./.1/file.txt
    ./.2/file.txt
    ./.3/file.txt
    ./1/file.txt
    ./2/file.txt
    ./3/file.txt
    $ find . -path './.*' -prune -o -name '*.txt' -print
    ./1/file.txt
    ./2/file.txt
    ./3/file.txt

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Oct 2010
    Posts
    9
    I ended up just using some of the and/or operators to target the few individual ones I didn't need. Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •