3

I have a project with many directories named proj

$ find . -iname proj
./include/proj
./src/proj
./lib/proj
./share/proj
./doc/proj

I want to rename all these directories to test with -exec mv. I came up with find . -iname proj -exec mv {} test but it doesn't work

Brady Dean
  • 245
  • 1
  • 3
  • 8
  • `find . -iname proj -print0 | xargs -0 rename.ul proj test` – Costas Jul 20 '16 at 17:38
  • 2
    one way: `find . -depth -type d -name proj -execdir mv proj test \;` - you need `depth` and `execdir` - for details see _Gilles_' answer [here](http://unix.stackexchange.com/q/46344)... there's plenty of examples on this site, I just picked the first result in google – don_crissti Jul 20 '16 at 17:45
  • @don_crissti Suppose for that case (with exact name) will be enough `find . -name proj -execdir mv {} test \;` – Costas Jul 20 '16 at 17:51
  • @Costas - that would work in this particular case but `find` will still complain (_No such file or directory_), just use `depth` – don_crissti Jul 20 '16 at 18:01

1 Answers1

6
find . -depth -iname proj -type d -execdir mv {} test \;

You need a find implementation with support for the non-standard -execdir predicate, but find implementations that support -iname generally also support -execdir in my experience.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501