Shell snippets

From Flavio's wiki
Revision as of 12:55, 18 February 2007 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Moving all files to another directory structure

$ find -type f | while read f; do mv -f --backup=t "$f" "../otherdir/$f"; done

Removing empty directories

$ find -depth -type d | xargs rmdir

The trick here is that rmdir will not remove non-empty directories. We use find -depth to act on deeper directories first.