Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cp the same file

Posted on 2000-03-14
3
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

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 21

Accepted Solution

by:
tfewster earned 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:
Suggested Courses

670 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