Alone as an Island What’s the pride in being a Programmer?
Mar 02

The find command in Unix always goes recursive. In order to avoid recursion into subfolders, you have the find -maxdepth in certain flavours of Unix. But find -prune is 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”

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Tags:

Leave a Reply

Give your best to the world.