0

I have one file, let's call it image.png. I also have a folder of files like so:

picture.png
file.png
screenshot.png
art.png
painting.png

And so on.

What I want to do is replace each file inside the folder with image.png, but I want to keep the name of the original (so picture.png is still called picture.png, but when viewed contains image.png.

image.png does not have to be located inside the folder.

I've tried this so far, but it doesn't seem to work:

for file in 'folder' 
do
    cp -f 'image.png'  $file
done
3

cp should do what you want. The problem is that you are not iterating through a folder. You are only doing one iteration with the "folder" being the contents of the $file variable. Try iterating over the file globbing, like this:

for file in folder/* 
do
    cp -vf 'image.png'  "$file"
done

I added a -v so you can get more verbose output to see any error, but you could leave that off once you get the correct results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.