On Fri, Jan 01, 2021 at 06:12:32PM +0700, Budi wrote: > find or bash or anything has made a bit buggy behavior > > for n in dircopy dircopy1 ;{ > > sudo find /usr/bin /usr/local -regextype posix-extended -iregex > '.*|.*' '(' -type d '(' -path '* *' -printf ''\''%p/'\''\n' -o -printf > '%p/\n' ')' -o '(' -path '* *' -printf ''\''%p'\''\n' -o -printf > '%p\n' ')' ')' -exec cp -r '{}' "$n" ';' > > } > > find make up bin dir. inside dircopy and target results are put there > instead of on dircopy
This has nothing to do with the bash shell. It is also not surprising that you get strange results as you are recursively copying every found directory into your two directories dircopy and dircopy1. That is, you copy /usr/local into dircopy recursively, then you copy /usr/local/share into dircopy (even though it's already been copied), then you copy /usr/local/bin etc. In some cases, depending on a file's depth, you would copy the same files many many times. Also note that -regextype posix-extended -iregex .*|.*' just means "every name" since the given pattern would match all possible filenames. Your -printf arguments contain empty strings (the first '' can be removed from both), and they can be simplified into -printf "'%p/'\n" and -print "'%p'\n". Unfortunately, it's unclear what it is you really want to achieve, but this is not the list to discuss it as it has nothing to do with bash. You may want to try https://unix.stackexchange.com/ or some similar place instead. -- Andreas (Kusalananda) Kähäri SciLifeLab, NBIS, ICM Uppsala University, Sweden .