Link to home
Start Free TrialLog in
Avatar of boofulls
boofulls

asked on

cp the same file

if i have 10 dirs in a dir
number 1 to 10
how can i copy 1/text.txt into all the other dirs
so that i then have
1/text.txt
2/text.txt
3/text.txt etc......
Avatar of tfewster
tfewster
Flag of United Kingdom of Great Britain and Northern Ireland image

for dir in 2 3 4 5 6 7 8 9 10
do
  cp  1/text.txt $dir
done
ASKER CERTIFIED SOLUTION
Avatar of tfewster
tfewster
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PC_User321
PC_User321

ls -p1 | fgrep / | xargs -n1 -i cp 1/text.txt {}
 
 The 'ls -p1 | fgrep /' part gets a list of all directories.
 The ' xargs -n1 -i cp 1/text.txt {}' part copies the specified file to all those directories.
 You should ignore the error reported when this command tries to copy 1/text.txt to itself.