Skip to main content
edited body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102

This is a really simplysimple one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems that do include non-standard -empty and -delete include BSD and OSX but apparently not AIX.

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems that do include non-standard -empty and -delete include BSD and OSX but apparently not AIX.

This is a really simple one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems that do include non-standard -empty and -delete include BSD and OSX but apparently not AIX.

added 6 characters in body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems includingthat do include non-standard --empty and -delete include BSD and OSX but apparently not AIX.

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems including non-standard -empty and -delete include BSD and OSX but apparently not AIX.

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems that do include non-standard -empty and -delete include BSD and OSX but apparently not AIX.

deleted 27 characters in body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution many "Linux" distributions. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems including non-standard -empty and -delete include BSD and OSX but apparently not AIX.

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution many "Linux" distributions. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems including non-standard -empty and -delete include BSD and OSX but apparently not AIX.

This is a really simply one liner:

find Parent -empty -delete

It's fairly self explanatory. Although when I checked I was surprised that it successfully deletes Parent/Child1. Usually you would expect it to process the parent before the child unless you specify -depth.

This works because -delete implies -depth. See the GNU find manual:

-delete Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.


Note these features are not part of the Posix Standard, but most likely will be there under many Linux Distribution. You may have a specific problem with smaller ones such as Alpine Linux as they are based on Busybox which doesn't support -empty.

Other systems including non-standard -empty and -delete include BSD and OSX but apparently not AIX.

added 430 characters in body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102
Loading
added 430 characters in body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102
Loading
portability notes. Official link for GNU find manual.
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k
Loading
added 367 characters in body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102
Loading
added 97 characters in body
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102
Loading
Source Link
Philip Couling
  • 21.1k
  • 5
  • 65
  • 102
Loading