In another forum I saw this command:
ls -1 | xargs -n 1 cp ../y/info.txt
It copies info.txt into sub folders (e.g. folder a, folder b, folder c) in the current working directory.
Now I want to copy the file info.txt to sub folders replacing existing info.txt files, but do nothing when the sub folder doesn't contain info.txt.
So I need the opposite of -n.
How can I accomplish this?
Best Answer
I would not parse the output of
ls
, use thefind
command instead:Note that the
-v
option withcp
isn't necessary, I just like to see what's being copied where.To address a comment, the
find
command shown above searches the entirePWD
. If you want to limit the the search to just first level subdirectories of thePWD
then add-maxdepth 2
to thefind
command, e.g.:In this scenario:
Only
./a/info.txt
and./b/info.txt
are replaced,./a/1/info.txt
is not.