Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy multiple files and give prefix and keep originals

Tags:

bash

shell

how do i copy files in unix. i want to keep the originals and add a prefix to the originals.

i have the following:

file1.csv
file2.csv
file3.csv
file4.csv
...
fileX.csv

what I will end up with after giving the command(with "H_" being the prefix in this example):

file1.csv
file2.csv
file3.csv
file4.csv
...
fileX.csv
H_file1.csv
H_file2.csv
H_file3.csv
H_file4.csv
...
H_fileX.csv

I was looking at the cp or mv command, but have no luck yet

like image 899
HattrickNZ Avatar asked Jan 25 '26 00:01

HattrickNZ


1 Answers

for file in *.csv; do
    cp "$file" "H_$file"
done
like image 194
slezica Avatar answered Jan 27 '26 17:01

slezica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!