Solved

cp the same file

Posted on 2000-03-14
3
395 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

789 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