Home > Software engineering >  Copy all *.txt to *.new.txt but ignore existing *.new.txt files
Copy all *.txt to *.new.txt but ignore existing *.new.txt files

Time:07-29

I need script for this:

  1. Copy all *.txt to *.new.txt
  2. 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}"' {} {} \;
  •  Tags:  
  • bash
  • Related