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?
Asked
Active
Viewed 58 times
1 Answers
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
-
Glad to have helped. – DopeGhoti Jan 04 '17 at 16:02