Solved

cp the same file

Posted on 2000-03-14
3
385 Views
Last Modified: 2010-04-21
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
Comment
Question by:boofulls
  • 2
3 Comments
 
LVL 20

Expert Comment

by:tfewster
ID: 2616434
for dir in 2 3 4 5 6 7 8 9 10
do
  cp  1/text.txt $dir
done
0
 
LVL 20

Accepted Solution

by:
tfewster earned 50 total points
ID: 2616872
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
 
LVL 5

Expert Comment

by:PC_User321
ID: 2618216
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now