Mind.random()

random ramblings of an eccentric programmer

Non-recursive Find in Unix

The find command in Unix always goes recursive. In order to avoid recursion into subfolders, you have the find -maxdepthin certain flavours of Unix. But find -pruneis the standard way to restrict recursion into certain subfolders.

Consider you have a logs folder /apps/myapp/data/logs and a subfolder /apps/myapp/data/logs/history, you would like to move the files in the logs folder alone and NOT the files in the history folder, then issue

find * \( ! -name history -prune \) -type f - exec cp {} /apps/myapp/archive \;

keeping the pwd as /apps/myapp/data/logs.

If you wish to restrict more than one folder, then use

find * \( ! -name history -prune \) -o \( ! -name history -prune \) -type f - exec cp {} /apps/myapp/archive \;

“-o” just says “OR”

Comments