I need script for this:
- Copy all *.txt to *.new.txt
- When run this script, ignore all *.new.txt files.
What I try:
find ~/folder -type f -name "*.txt" ! -name "*.new.txt"
how to send this output to
cp STDIN *.new.txt
CodePudding user response:
Use -exec
to execute a subshell where you copy the file to the modified filename.
find ~/folder -type f -name "*.txt" ! -name "*.new.txt" -exec bash -c 'cp "$1" "${1/.txt/.new.txt}"' {} {} \;