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

4
  • find . -iname proj -print0 | xargs -0 rename.ul proj test
    – Costas
    Commented Jul 20, 2016 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... there's plenty of examples on this site, I just picked the first result in google Commented Jul 20, 2016 at 17:45
  • @don_crissti Suppose for that case (with exact name) will be enough find . -name proj -execdir mv {} test \;
    – Costas
    Commented Jul 20, 2016 at 17:51
  • @Costas - that would work in this particular case but find will still complain (No such file or directory), just use depth Commented Jul 20, 2016 at 18:01

1 Answer 1

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .