Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

find . -regex ....

regexe:

'.*^((?!xml).)*$'

but without expected results...

or is there another way to achieve this, i.e. without a regexp matching?

like image 593
paweloque Avatar asked Sep 26 '12 13:09

paweloque


4 Answers

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

like image 61
Laser Avatar answered Nov 13 '22 07:11

Laser


find . -not -name '*.xml'

Should do the trick.

like image 26
verdesmarald Avatar answered Nov 13 '22 05:11

verdesmarald


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
like image 3
Andy Lester Avatar answered Nov 13 '22 06:11

Andy Lester


with bash:

shopt -s extglob globstar nullglob
for f in **/*!(.xml); do 
    [[ -d $f ]] && continue
    # do stuff with $f
done
like image 2
glenn jackman Avatar answered Nov 13 '22 07:11

glenn jackman