Posted: Thu May 15, 2008 8:10 am Post subject: find directories and rename the directories
Hello,
I would like to find some directories and rename then.
I use
find . -type d -name 'tau_*'
to find directories starting with "tau_". I would like to change
the underscore to a hyphen in the directory names use -exec, but can
not figure out the syntax.
Posted: Thu May 15, 2008 8:10 am Post subject: Re: find directories and rename the directories
On May 14, 1:53 pm, zhengquan <zhang.zhengq...@gmail.com> wrote:
Quote:
Hello,
I would like to find some directories and rename then.
I use
find . -type d -name 'tau_*'
to find directories starting with "tau_". I would like to change
the underscore to a hyphen in the directory names use -exec, but can
not figure out the syntax.
Thank you!
Regards,
Zhengquan
And it seems to complicate the problem that there are tau_*
directories under some other tau_* directories...
Posted: Thu May 15, 2008 1:10 pm Post subject: Re: find directories and rename the directories
zhengquan wrote:
Quote:
On May 14, 1:53 pm, zhengquan <zhang.zhengq...@gmail.com> wrote:
Hello,
I would like to find some directories and rename then.
I use
find . -type d -name 'tau_*'
to find directories starting with "tau_". I would like to change
the underscore to a hyphen in the directory names use -exec, but can
not figure out the syntax.
Thank you!
Regards,
Zhengquan
And it seems to complicate the problem that there are tau_*
directories under some other tau_* directories...
Zhengquan
You can see previously the output with the "echo", so:
find . -type d -name 'tau_*'|while read D;do echo mv -i $D ${D/
_/-};done
Posted: Thu May 15, 2008 11:10 pm Post subject: Re: find directories and rename the directories
On Wednesday 14 May 2008 22:19, zhengquan wrote:
Quote:
find . -type d -name 'tau_*'
to find directories starting with "tau_". I would like to change
the underscore to a hyphen in the directory names use -exec, but can
not figure out the syntax.
Thank you!
Regards,
Zhengquan
And it seems to complicate the problem that there are tau_*
directories under some other tau_* directories...
If you can, consider using the "rename" program (available on most systems).
Otherwise, you can try this (with bash):
find . -depth -type d -name 'tau_*' -exec
sh -c 'b=$(basename "$1");d=$(dirname "$1");
nn=${b//_/-}; mv -- "$d/$b" "$d/$nn"' sh '{}' \;
But I suggest you run this before:
find . -depth -type d -name 'tau_*' -exec
sh -c 'b=$(basename "$1");d=$(dirname "$1");
nn=${b//_/-}; echo "would perform mv -- $d/$b $d/$nn"' sh '{}' \;
To see what the program would do. The run the real one above.
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum