When using find
command in linux, one can add a -regex
flag that uses emacs regualr expressions to match.
I want find to look for all files except .jar
files and .ear
files. what would be the regular expression in this case?
Thanks
Sometimes we may find that we want to exclude all files except some specific files from a specific domain: Edit Real Browser Check > Advanced > + Add Excluded File. From the dropdown menu, select 'All Except' and specify the domain or subdomain that you'd like to include.
We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!
This answer is not useful. Show activity on this post. [] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
Enter a file extension. For example, to exclude your music files, enter mp3 or .mp3. Click Add. Create additional exclusions, if desired. Click Save. A regular expression (regex) is a search pattern that locates files and folders containing a specific sequence of characters by comparing that sequence to absolute file paths on your device.
The find command support standard UNIX regex to match, include or exclude files. You can write complex queries easily with regex while find command recursively descends the directory tree for each /file/to/path listed, evaluating an expression. Find command exclude or ignore files syntax. The syntax is as follows:
Click Save. A regular expression (regex) is a search pattern that locates files and folders containing a specific sequence of characters by comparing that sequence to absolute file paths on your device. You can use the power of regular expressions to fine-tune and allow for more complex backup file exclusion rules.
Certain files and file types can be globally excluded from a backup without having to modify the file selection by deselecting individual files and folders. These exclusions can be added either by file type or by using regular expressions ( regex ).
You don't need a regex here. You can use find
with the -name
and -not
options:
find . -not -name "*.jar" -not -name "*.ear"
A more concise (but less readable) version of the above is:
find . ! \( -name "*.jar" -o -name "*.ear" \)
EDIT: New approach:
Since POSIX regexes don't support lookaround, you need to negate the match result:
find . -not -regex ".*\.[je]ar"
The previously posted answer uses lookbehind and thus won't work here, but here it is for completeness' sake:
.*(?<!\.[je]ar)$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With