Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

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......
0
boofulls
Asked:
boofulls
  • 2
1 Solution
 
tfewsterCommented:
for dir in 2 3 4 5 6 7 8 9 10
do
  cp  1/text.txt $dir
done
0
 
tfewsterCommented:
That was for Korn shell - for Csh, it would be:

foreach dir ( 2 3 4 5 6 7 8 9 10 )
  cp 1/text.txt $dir
end

If the directories are not really called 2-10, it's
easy enough to construct an expression that
expands to the list of directories.

Regards, Tim
0
 
PC_User321Commented:
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.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now