Skip to main content
NetBSD had `-regex` (1999, inspired from GNU's) before FreeBSD. (2001), though -E was added there later (2007). In any case, all BSDs should have it now.
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

With GNU find (i.e. under non-embedded Linux or Cygwin), you can use -regex to combine all these -path wildcards into a single regex.

find . -regextype posix-extended \
     -type d -regex '\./(\..*|Music|Documents)' -prune -o \
     -type f -regex '.*(\.(bck|bak|backup)|~)' -print0 |
xargs -0 --no-run-if-empty trash-put

With FreeBSDOn BSDs or OSXmacOS, use -E instead of -regextype posix-extended.

You may also want to replace that -print0 | xargs -0 --no-run-if-empty trash-put (where --no-run-if-empty is GNU-specific1¹) with its standard shorter equivalent: -exec trash-put {} +.


¹ its shorter -r form is however supported by some other implementations, even the default on some BSDs

With GNU find (i.e. under non-embedded Linux or Cygwin), you can use -regex to combine all these -path wildcards into a single regex.

find . -regextype posix-extended \
     -type d -regex '\./(\..*|Music|Documents)' -prune -o \
     -type f -regex '.*(\.(bck|bak|backup)|~)' -print0 |
xargs -0 --no-run-if-empty trash-put

With FreeBSD or OSX, use -E instead of -regextype posix-extended.

With GNU find (i.e. under non-embedded Linux or Cygwin), you can use -regex to combine all these -path wildcards into a single regex.

find . -regextype posix-extended \
     -type d -regex '\./(\..*|Music|Documents)' -prune -o \
     -type f -regex '.*(\.(bck|bak|backup)|~)' -print0 |
xargs -0 --no-run-if-empty trash-put

On BSDs or macOS, use -E instead of -regextype posix-extended.

You may also want to replace that -print0 | xargs -0 --no-run-if-empty trash-put (where --no-run-if-empty is GNU-specific1¹) with its standard shorter equivalent: -exec trash-put {} +.


¹ its shorter -r form is however supported by some other implementations, even the default on some BSDs

Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

With GNU find (i.e. under non-embedded Linux or Cygwin), you can use -regex to combine all these -path wildcards into a single regex.

find . -regextype posix-extended \
     -type d -regex '\./(\..*|Music|Documents)' -prune -o \
     -type f -regex '.*(\.(bck|bak|backup)|~)' -print0 |
xargs -0 --no-run-if-empty trash-put

With FreeBSD or OSX, use -E instead of -regextype posix-extended.