I have files named test.txt
in different directories like this
./222/test.txt
./111/test.txt
I want to rename all test.txt
to info.txt
I've tried using this
find . -type f -iname 'test.txt' -exec mv {} {}info \;
I get test.txtinfo
Your idea is right, but you need to use -execdir
instead of just -exec
to simplify this.
find . -type f -iname 'test.txt' -execdir mv {} info.txt ';'
This works like -exec
with the difference that the given shell command is executed with the directory of the found pathname as its current working directory and that {}
will contain the basename of the found pathname without its path. Also note that the option is a non-standard one (non POSIX compliant).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.