1

I have atleast 2-3 *.txt files inside several hundred directories. What I need is: 1. copy the *.txt from every directory to the same directory but by renaming the filename to *_name.txt (* should be the original name of the .txt and the string "name" is same for all newly copied files. Can I use pax for this? If yes, how?

1 Answers1

2

This doesn't use pax, but is a pretty straightforward way to get what you need done, done:

IFS="\n"
for file in *.txt; do
    cp -- "$file" "${file%.txt}_name.txt"
done

The construct ${var%suffix} will strip suffix from the end of the value of $var; this is used to remove the file extension.

DopeGhoti
  • 76,081