![]() |
Remove sub-directories, yet preserve others
Hi,
I'm trying to write a bash script in which I want it to remove all sub-directories except two ('core' and 'java') within a particular directory. Here's what I got: Code:
for dir in ${DIRS[@]}; doIf I remove the "-name . -o" from the find-statement above, then I get errors such as: Code:
xargs: WARNING: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option? |
Hi, how about
Code:
for dir in "${DIRS[@]}"; do |
Well, if you put . among the directories to exclude, nothing is printed out by the find command. Actually the rm command doesn't work on . and .. since they are a sort of aliases and not the real name of a directory. Anyway, if you want to be sure use -mindepth to exclude the current working directory:
Code:
find . -mindepth 1 -maxdepth 1 -type dCode:
find . -mindepth 1 -maxdepth 1 -type d \( -wholename ./core -o -wholename ./java \) -prune -o -print0 | xargs -0 rm -rfCode:
find . -mindepth 1 -maxdepth 1 -type d \( -wholename ./core -o -wholename ./java \) -prune -o -exec rm -rf {} \; |
Quote:
|
| All times are GMT -5. The time now is 01:46 AM. |