Pass not to the find command

Posted on 2004-11-09
Last Modified: 2010-04-21
How do you pass NOT to the find command.  I want to find all files within a directory that do not match (files that do not match  *.04_11_09).
and then gzip them.
Question by:theoradically

    Author Comment

    As where I would run

    find . -name *.04_11_09, to find all files in the current working dir that matched *.04_11_09

    I want to do a find that match all files that do not match the criteria.  Sounds simple, but I don't think the find command
    does that and my scripting is poor.  I'm working on my scripting skills with this groups help.  Thank You
    LVL 23

    Expert Comment

    Use the  -not  switch to negate the value of an expression:

    find -not -name "*.04_11_09" -exec gzip {} \;

    LVL 23

    Assisted Solution

    Oops, forgot the start directory to find:

    find . -not -name "*.04_11_09" -exec gzip {} \;

    LVL 20

    Accepted Solution

    -not isn't available with all versions of find; In which case, you use "!"

    find . ! -name "*.04_11_09" -exec gzip {} \;

    Author Comment

    Thanks helpers,

    I looked in the find man pages before posting this, but did not find this until I went back looking fo how to do an "and"

         2)   ! expression
               The negation of a primary (! is the unary  not  opera-
         3)  expression [-a] expression
               Concatenation  of  primaries  (the  and  operation  is
               implied by the juxtaposition of two primaries).
         4)  expression -o expression
               Alternation of primaries (-o is the or operator).

    The -not did not work for Solaris, but I did not specify the flavor.  The ! did work.  Thanks again both of you for your quick response.  I am going to split the points.

    Author Comment


    Here is how I found multiple instances of not

    find . ! -name "*.04_11_09" -a ! -name "2004_11_09" -a ! -name "04_11_9" -exec gzip {} \;

    Expert Comment

    find ./ -print | grep -v 04_11_09

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
    Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now