LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-25-2010, 07:55 PM   #1
lothario
Member
 
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
copying 1 file to many directories


The current directory contains:
  • A file called "original.txt"
  • Many directories called "source_001", "source_002", "source_003" ...
From the command line how do you copy "original.txt" to
"source_001"
and
"source_002"
and
"source_003" ...

The total number of these source directories is unknown, it changes every week.
 
Old 07-25-2010, 08:57 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
for i in source_???
do
  cp original.txt "$i"
done
 
Old 07-26-2010, 04:30 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,374

Rep: Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198
Could it be done with links instead?
 
Old 07-26-2010, 08:56 PM   #4
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-17.1 with Cinnamon & KDE
Posts: 1,478
Blog Entries: 3

Rep: Reputation: 95
Quote:
Originally Posted by jefro View Post
Could it be done with links instead?
Those in the know understand what you mean by "links". Someone new to *nix, won't know that "links" implies the ln command. Use man ln for details of the command itself.

Here is a short description of "links". Every file system uses some variation of the following. A file exists as a series of bytes on the disk, often called an "extent". A structure called an "inode" keeps track of where the data lives on disk. A folder or directory is just another data file that happens to contain "filenames", some other details, and details about the data extent.

In most cases, there is a one-to-one relationship between what appears in the directory and the data file. Like an entry in a library card index, a "link" makes an entry in some directory for data that lives on the disk somewhere else just like one library book might have dozens of index cards. A given set of data might have a large number of these index-card-like duplicate entries. There is no reason for these links to have identical names, but you need to keep track of them.

A major advantage is that you have one copy of the data regardless of how many directories are used to name it and which users own those directories and link entries.

A major disadvantage of links is that you must remember to clean-up all of them when you delete the associated data file. (I vaguely remember that the fsck family of commands will notice and report and help deal with this issue. I welcome comments from someone who knows.)

One example of link use is the System-V style system initialization.
The system startup scripts get stored in /etc/init.d -- for example, apm, named, networking, samba, gdm, and so on. Then each of the runlevel folders holds a link, for example /etc/rc5.d/S15networking, that then points to the actual script.

One copy of the script content. Edit one -- edit them all. Link to that content each place that you want to use it.

~~~ 0;-Dan

Last edited by SaintDanBert; 07-26-2010 at 09:02 PM.
 
Old 07-31-2010, 08:37 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Moved to Linux--Newbie
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying files and sub-directories of a directory except the directories named ".abc" sri1025 Linux - General 2 08-24-2010 09:53 AM
[SOLVED] automate copying files to multiple directories with log file for admin simransab Linux - Newbie 6 10-01-2009 08:09 PM
Copying a single file to multiple directories quest49 Linux - Software 6 12-04-2006 09:07 AM
copying multiple different files in different directories with identical file names nickleus Linux - Software 4 03-09-2006 02:25 PM
Copying a single file to multiple directories tgolly Linux - Newbie 3 04-26-2004 04:47 PM


All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration