More

    Find Exclude or Ignore Files (e.g. Ignore All Hidden.dot Files)

     

    How do I ignore all hidden .dot recordsdata whereas looking for recordsdata utilizing the discover command? How do I ignore or exclude sure recordsdata whereas working Linux or UNIX discover command?

    The discover command assist normal UNIX regex to match, embrace or exclude recordsdata. You possibly can write advanced queries simply with regex whereas discover command recursively descends the listing tree for every /file/to/path listed, evaluating an expression.

    ADVERTISEMENTS

     

    Discover command exclude or ignore recordsdata syntax

    The syntax is as follows:

    ##################
    ## Fundamental syntax ##
    ##################
    discover /dir/to/search/ -options -name ‘regex’ -action
    discover /dir/to/search/ -options -iname ‘regex’ -action
    discover /dir/to/search/ -type f -name ‘regex’ -print
    discover /dir/to/search/ -type f -name ( expression ) -print## ———————————————————————- ##
    ## The -and operator is the logical AND operator ##
    discover /dir/to/search/ -type f -name ‘expression -and expression’ -print

    ## ———————————————————————- ##
    ## The -or operator is the logical OR operator. The expression evaluates ##
    ## to true if both the primary or the second expression is true. ##
    discover /dir/to/search/ -type f -name ‘expression -or expression’ -print

    Examples: discover command and logical operators

    Discover any file whose identify ends with both ‘c’ or ‘asm’, enter:
    $ discover . -type f ( -iname “*.c” -or -iname “*.asm” )
    On this instance, discover all *.conf and (.txt) textual content recordsdata within the /and so forth/ listing:
    $ discover . -type f ( -name “*.conf” -or -name “*.txt” ) -print
    Fig.01: Linux find command exclude files command Fig.01: Linux discover command exclude recordsdata command
    The parentheses should be escaped with a backslash, “(” and “)“, to forestall them from being interpreted as particular shell characters. The -type f possibility drive discover to solely search recordsdata and never directories. The -or operator both discover ‘.c’ or ‘.asm’ file.

    Understanding discover command operators

    Operators construct a posh expression from exams and actions. The operators are, so as of lowering priority:

    ( expr ) Drive priority. True if expr is true
    expr -not expr
    ! expr
    True if expr is fake. In some shells, it’s crucial to guard the ‘!’ from shell interpretation by quoting it.
    expr1 -and expr2 expr2 is just not evaluated if expr1 is fake.
    expr1 -or expr2 expr2 is just not evaluated if expr1 is true.
    WARNING! The ‘-or’, ‘-and’, and ‘-not’ operator should not obtainable on all variations of discover. Normally GNU discover helps all choices. Refer your native discover command man web page for extra data.

    How do I ignore hidden .dot recordsdata whereas looking for recordsdata?

    Discover *.txt file however ignore hidden .txt file reminiscent of .vimrc or .information.txt file:
    $ discover . -type f ( -iname “*.txt” ! -iname “.*” )
    Discover all .dot recordsdata however ignore .htaccess file:
    $ discover . -type f ( -iname “.*” ! -iname “.htaccess” )

    Say hi there to -path possibility

    This selection return true if the pathname being examined matches sample. For instance, discover all *.txt recordsdata within the present listing however exclude ./Motion pictures/, ./Downloads/, and ./Music/ folders:

    cd $HOME
    discover . -type f -name “*.txt” ! -path “./Motion pictures/*” ! -path “./Downloads/*” ! -path “./Music/*”## add -ls choice to get ls -l form of output ##
    discover . -type f -name “*.txt” ! -path “./Motion pictures/*” ! -path “./Downloads/*” ! -path “./Music/*” -ls

    Pattern outputs:

    ./.config/gcloud/legacy_credentials/[email protected]/gaejava.txt
    ./adsl-ip-info.txt
    ./Desktop/Payments-PDF/codex.txt
    ./Desktop/Payments-PDF/2015.txt
    ./Desktop/Payments-PDF/receipt-05-OCT-14 10-08 AM.txt
    ./Desktop/Payments-PDF/untitled.txt
    ./Desktop/Payments-PDF/wufoo/Give Us Suggestions for nixCraft.txt
    ./Desktop/tutorials.txt
    ./Desktop/untitled 4.txt
    ./Paperwork/centos-7-selinux.txt
    ./Paperwork/hhmv-domain.txt
    ./Paperwork/ip.txt
    ./Paperwork/pfsec-ipsec.txt
    ./Paperwork/smem-rhel-centos.txt
    ./Paperwork/3m.txt

    Conclusion

    You realized ignore specific filenames whereas utilizing discover command on Linux or Unix-like techniques.

    Posted by: Vivek Gite

    The writer is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a coach for the Linux working system/Unix shell scripting. Get the newest tutorials on SysAdmin, Linux/Unix and open supply matters by way of RSS/XML feed or weekly electronic mail publication.

    ADVERTISEMENTS

    find exclude hidden files,find command ignore hidden directories,find command exclude directory,linux find exclude multiple directories,find exclude files from list,linux find exclude directory wildcard,find exclude all directories,find command ignore node_modules

    Recent Articles

    Unravel the XDR Noise and Recognize a Proactive Approach

      Cybersecurity professionals know this drill nicely all too nicely. Making sense of heaps of info and noise to entry what actually issues. XDR (Prolonged Detection & Response) has been a technical acronym thrown round within the cybersecurity business with many notations and...

    PLATYPUS: Hackers Can Obtain Crypto Keys by Monitoring CPU Power Consumption

      Researchers have disclosed the small print of a brand new side-channel assault technique that can be utilized to acquire delicate data from a system...

    The Container configurations in Amazon ECS

      Revealed: November 7, 2020 | Modified: November 7, 2020 | Zero views A fast put up on superior container configurations in Amazon ECS. ECS container superior...

    Antivirus Testing – VIPRE for your Home and Business

      Individuals typically marvel, “What’s one of the best antivirus?” A number of distributors will declare that their product is one of the best within...

    Antivirus Testing – VIPRE for your Home and Business

      Individuals typically marvel, “What’s one of the best antivirus?” A number of distributors will declare that their product is one of the best within...

    Related Stories