Results 1 to 4 of 4

Thread: Recursively search files with exclusions and inclusions

  1. #1
    Join Date
    Jun 2011
    Beans
    29

    Recursively search files with exclusions and inclusions

    Hello everybody

    I would like to use find to recursively search files and print them to a file. I imagine a command like this:

    Code:
        find /local/data/ --exclude 'database/session*' --include='database/session_*.db' > temp.txt
    This command does not work. How can I use exclusion and inclusion that work? database/session* and database/session_*.db appear as part of a path, i.e. /local/data/.../database/session..../... and /local/data/database/session_*.db.

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    21,032
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Recursively search files with exclusions and inclusions

    find is one of those commands where seeing a few examples is crazy helpful. Also, don't be afraid to pipeline.
    Code:
     find /local/data/ -type f -name session_\*db -print | egrep -v 'some-regex-to-exclude'
    If you show examples of the files to be excluded and included, perhaps a regex can be crafted. Don't forget that other file properties can be used like the create time, owner, and permissions.

  3. #3
    Join Date
    Jun 2011
    Beans
    29

    Re: Recursively search files with exclusions and inclusions

    Thank you so much. Here is the directory structure:

    Code:
    /local/data/folder1
             exception1.exception
             exception2.exception
             info.txt
             otherFile.txt
             /database
                 session1.db
                 session2.db
                 ....
                 session1000.db
        
    /local/data/folder2
             exception1.exception
             info.txt
             otherFile.txt
             /database
                 /session_198
                         session_198.00000034.db.tmp
                         session_198.00000035.db.tmp
                         ...
                         upload_fff344dbf979363020d1b874a8ee7bef.db
                 session1.db
                 session2.db
    I would like to find all files except for the files in /database/session_*. Is there a regex for that?

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    21,032
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Recursively search files with exclusions and inclusions

    Code:
    find /local/data/ -type f -name 'session[0-9]+*db' -print
    Appears to be what you want, but not what is being described.

Bookmarks

Posting Permissions

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