LinuxQuestions.org
Register a domain and help support LQ
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 01-11-2012, 04:05 PM   #1
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
copying file/folder into subdirectories


I have over 50 folder in home (using Debian 6 LAMP).

/home/xcz1/xzcx2/name1/name2
/home/zsd1/zd2/name1/name2
/home/.../.../name1/name2
...


/home/update/name2/

how can i copy the name2 from update folder and paste him into the name1 folder of each folder in the home folder?

i have tried:
cd /home/update
cp -R name2 /home/*/*/name1
and
cp -r name2 /home/../../name1
but it did not work.

Thank's
 
Old 01-11-2012, 09:04 PM   #2
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
Your request (or at least the way you are explaining it) is somwhat odd, and a bit vague or ambiguous. Can you perhaps give us some more background on what you are trying to accomplish?
 
Old 01-11-2012, 09:20 PM   #3
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydraMax View Post
Your request (or at least the way you are explaining it) is somwhat odd, and a bit vague or ambiguous. Can you perhaps give us some more background on what you are trying to accomplish?
I'm trying to input few files in subfolders with name 'name1'.
These files are not there, so overwrite is not needed.

or as simple as possible:
It's game hosting machine, these 50 folders contain the files and folders of the game, so i want to input some files, which block exploits and etc.
how i gonna do it?

Sorry for my bad English.
 
Old 01-11-2012, 09:30 PM   #4
john_erlandsson
Member
 
Registered: Jul 2009
Location: Sweden
Distribution: Fedora
Posts: 70

Rep: Reputation: 1
If i understand you correctly, you want to copy ~/src/dir/file to ~/dst/dir/file

Could the problem be that the ~/dst/dir/ folder doesent exist?

In that case you could either just mkdir ~/dst/dir/ or do some fancy find thing.
 
Old 01-11-2012, 09:42 PM   #5
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by john_erlandsson View Post
If i understand you correctly, you want to copy ~/src/dir/file to ~/dst/dir/file

Could the problem be that the ~/dst/dir/ folder doesent exist?

In that case you could either just mkdir ~/dst/dir/ or do some fancy find thing.

All directories has been already created, but i need files on the right position, so i want input them to one directory named as 'dir' and input them (whole 'dir' folder) in an subdirectory where is the directory with name 'dir'.
But i don't want input it in just one directory, i want input it in all directory in the 'home' dir. (all those directories have created 'dir' directory).

for example:
/home/michael/today/dir
/home/carey/evening/dir
/home/jay/birthday/dir

and i want input 'dir' folder from
/home/update/dir
to those above.
(Please do not tell me, i have to do it one by one, it must be some trick with 'cp' command or something like that.
 
Old 01-12-2012, 12:37 AM   #6
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
I don't know if there is a single command that can do that, but I think something like this shell script should work:

Code:
XYZ=`ls /home/*/*/dir -d`
for i in $XYZ
do
    cp -R /home/update/dir/* $i
done
I tested it in a directory on my system (leaving off the leading forward slashes, for obvious reasons). I started with this directory:

Code:
.
|-- home
|   |-- carey
|   |   `-- evening
|   |       `-- dir
|   |-- jay
|   |   `-- birthday
|   |       `-- dir
|   |-- michael
|   |   `-- today
|   |       `-- dir
|   `-- update
|       `-- dir
|           `-- update-file.txt
`-- mcopy.sh
(mcopy.sh is the shell script) I ran the shell script with "bash mcopy.sh". And the result was:

Code:
|-- home
|   |-- carey
|   |   `-- evening
|   |       `-- dir
|   |           `-- update-file.txt
|   |-- jay
|   |   `-- birthday
|   |       `-- dir
|   |           `-- update-file.txt
|   |-- michael
|   |   `-- today
|   |       `-- dir
|   |           `-- update-file.txt
|   `-- update
|       `-- dir
|           `-- update-file.txt
`-- mcopy.sh
 
1 members found this post helpful.
Old 01-12-2012, 12:58 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You will need to use a loop.

Code:
for dir in /home/*/*/dir1; do
cp name2 "$dir"/
done
 
Old 01-12-2012, 07:33 AM   #8
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydraMax View Post
I don't know if there is a single command that can do that, but I think something like this shell script should work:

Code:
XYZ=`ls /home/*/*/dir -d`
for i in $XYZ
do
    cp -R /home/update/dir/* $i
done
I tested it in a directory on my system (leaving off the leading forward slashes, for obvious reasons). I started with this directory:

Code:
.
|-- home
|   |-- carey
|   |   `-- evening
|   |       `-- dir
|   |-- jay
|   |   `-- birthday
|   |       `-- dir
|   |-- michael
|   |   `-- today
|   |       `-- dir
|   `-- update
|       `-- dir
|           `-- update-file.txt
`-- mcopy.sh
(mcopy.sh is the shell script) I ran the shell script with "bash mcopy.sh". And the result was:

Code:
|-- home
|   |-- carey
|   |   `-- evening
|   |       `-- dir
|   |           `-- update-file.txt
|   |-- jay
|   |   `-- birthday
|   |       `-- dir
|   |           `-- update-file.txt
|   |-- michael
|   |   `-- today
|   |       `-- dir
|   |           `-- update-file.txt
|   `-- update
|       `-- dir
|           `-- update-file.txt
`-- mcopy.sh
i make script and run her on this way:

./mcopy.sh

it's work, but when finish show this error:
p: missing destination file operand after `/home/update/dir/subdirectory'
Try `cp --help' for more information.

It's not so mather, beacause it's work
Thank you.


Quote:
Originally Posted by jschiwal View Post
You will need to use a loop.

Code:
for dir in /home/*/*/dir1; do
cp name2 "$dir"/
done
i try your script, but it's say direcyory 'name2' doesnt exist, i put 'dir' instead of 'name2'. No errors and nothing happend.
Thank's anyway.
 
Old 01-13-2012, 02:32 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
name2 is from your original post. I didn't enter a script to run but an example of the commands to run in the terminal.

Since you are copying into several users' home directories, you will need to run the cp command as root.

1) The first argument of cp is the file to copy. If you are copying a directory, then use the -r flag. It is to recurse through the source, not the destination. Be in the same directory as the source file, or include the path to it in the filename.

2) Wildcards are expanded before the command is run. /home/*/*/dir1 will expand to a list of directories named "dir1" two levels deep from each users home directory. Such as /home/mike/www/dir1/ for example. I think it would be better to explicitly give which directory it is, and use a variable for the user name:

Code:
for user in sam mike sally ted; do
sudo cp file /home/$user/www/dir1/
done
Or if more than a few users:
Code:
for homedir in /home/*; do
sudo cp file $homedir/http/dir1/
done
Use the particular subdirectories you

need, and watch what you do.
 
1 members found this post helpful.
  


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
[SOLVED] Copying the files inside a folder, without copying the folder (hopefully easy) tibberous Linux - Software 3 12-23-2010 02:50 AM
FC13: There was an error copying file into smb://path/folder BryanChong Linux - Server 3 10-28-2010 05:55 AM
There was an error copying the file into smb:// PcName/Folder/Folder morbid_bean Linux - Networking 2 06-14-2009 05:49 PM
copy a file to all subdirectories in a folder raj000 Linux - General 6 03-24-2006 04:55 AM
Error Copying File or Folder nysethe Linux - Networking 3 08-17-2004 02:06 PM


All times are GMT -5. The time now is 06:19 AM.

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