Skip to main content
updated to indicate that find can delete empty dirs itself
Source Link

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -name ".svn" -type d -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories as well as directories that contain only empty directories, a way to hack aroundfind can do that is to useitself with rmdir-delete instead ofand rm -rempty:

find . -name ".svn" -type d -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -name ".svn" -type dempty -exec rmdir "{}" \;  2> /dev/nulldelete

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -name ".svn" -type d -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -name ".svn" -type d -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -name ".svn" -type d -exec rmdir "{}" \;  2> /dev/null

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -name ".svn" -type d -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories as well as directories that contain only empty directories, find can do that itself with -delete and -empty:

find . -name ".svn" -type d -empty -delete
recommended to keep -type calls after -name for efficiency: explanation in comment
Source Link

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -type d -name ".svn" -type d -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -type d -name ".svn" -type d -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -type d -name ".svn" -type d -exec rmdir "{}" \;  2> /dev/null

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -type d -name ".svn" -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -type d -name ".svn" -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -type d -name ".svn" -exec rmdir "{}" \;  2> /dev/null

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -name ".svn" -type d -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -name ".svn" -type d -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -name ".svn" -type d -exec rmdir "{}" \;  2> /dev/null

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r onwith the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -type d -name ".svn" -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all it'sits contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -type d -name ".svn" -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -type d -name ".svn" -exec rmdir "{}" \;  2> /dev/null

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r on the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -type d -name ".svn" -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all it's contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -type d -name ".svn" -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -type d -name ".svn" -exec rmdir "{}" \;  2> /dev/null

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

find . -type d -name ".svn" -exec rm -r "{}" \;

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -type d -name ".svn" -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -type d -name ".svn" -exec rmdir "{}" \;  2> /dev/null
Explain how to delete just empty directories
Source Link
Drav Sloan
  • 14.7k
  • 4
  • 49
  • 45
Loading
Source Link
Drav Sloan
  • 14.7k
  • 4
  • 49
  • 45
Loading