find all files except e.g. *.xml files in shell

前端 未结 6 1744
天命终不由人
天命终不由人 2021-01-04 07:09

Using bash, how to find files in a directory structure except for *.xml files? I\'m just trying to use

find . -regex ....

regexe:

相关标签:
6条回答
  • 2021-01-04 07:21

    You can also do it with or-ring as follows:

    find . -type f -name "*.xml" -o -type f -print

    0 讨论(0)
  • 2021-01-04 07:29

    with bash:

    shopt -s extglob globstar nullglob
    for f in **/*!(.xml); do 
        [[ -d $f ]] && continue
        # do stuff with $f
    done
    
    0 讨论(0)
  • 2021-01-04 07:35

    Sloppier than the find solutions above, and it does more work than it needs to, but you could do

    find . | grep -v '\.xml$'
    

    Also, is this a tree of source code? Maybe you have all your source code and some XML in a tree, but you want to only get the source code? If you were using ack, you could do:

    ack -f --noxml
    
    0 讨论(0)
  • 2021-01-04 07:40

    find . ! -name "*.xml" -type f

    0 讨论(0)
  • 2021-01-04 07:42

    Try something like this for a regex solution:

    find . -regextype posix-extended -not -regex '^.*\.xml$'
    
    0 讨论(0)
  • 2021-01-04 07:44
    find . -not -name '*.xml'
    

    Should do the trick.

    0 讨论(0)
提交回复
热议问题