Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-25-2010, 06:55 PM   #1
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_003" ...

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

Rep: Reputation: 244Reputation: 244Reputation: 244
for i in source_???
  cp original.txt "$i"
Old 07-26-2010, 03:30 PM   #3
Registered: Mar 2008
Posts: 19,852

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

Rep: Reputation: 105Reputation: 105
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 08:02 PM.
Old 07-31-2010, 07:37 AM   #5
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

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


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 08:53 AM
[SOLVED] automate copying files to multiple directories with log file for admin simransab Linux - Newbie 6 10-01-2009 07:09 PM
Copying a single file to multiple directories quest49 Linux - Software 6 12-04-2006 08:07 AM
copying multiple different files in different directories with identical file names nickleus Linux - Software 4 03-09-2006 01:25 PM
Copying a single file to multiple directories tgolly Linux - Newbie 3 04-26-2004 03:47 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:01 PM.

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