-1

I want to use rm -rf to remove files/folders inside a folder, but skip or ignore a specific folder.

It has been suggested as duplicated to another quesiton, but that is not the case. The other quesiton ask about skipping files. I want to skip a folder with all the content of that folder.

3 Answers3

1

This:

find . -mindepth 1 -maxdepth 1 -not -name '.svn' -print0 | xargs -0 -r rm -rf

does what you want it to do, I believe. It skips the .svn directory and its contents but deletes everything else, files and directories, including those starting with a '.' in the current directory and any subdirectories.

Vojtech
  • 1,272
  • 9
  • 6
0

It is kind of a duplicate of link in comments... In any case, for a dir:

find . ! \( -type d -and -iname "test" \)

To see whether test dir is skipped or not.

Then:

find . ! \( -type d -and -iname "test" \) -delete

Simply find . ! -iname "test" for both file and dir.

SΛLVΘ
  • 1,465
0

find . -not -path ./.svn/* ! -name .svn

Essentially, the first part excludes all files within that directory, and the second part excludes the directory itself.

Alex
  • 250