View previous topic :: View next topic |
Author |
Message |
Hoshimaru Apprentice
Joined: 09 Nov 2003 Posts: 225 Location: Belgium
|
Posted: Sun Nov 07, 2004 10:43 am Post subject: Complicated file copy issue... |
|
|
Hi,
This is kind of complicated. I received a patch "patch" for a dedicated server. However, that patch contains all updates and not only the last one.
I managed to find out what the new file were, doing
Code: | find Files/ -mtime 2 > new.txt |
That new.txt looks like this:
Code: | Files/bin/dedicated.dll
Files/bin/dedicated_amd.so
Files/bin/dedicated_i486.so
Files/bin/dedicated_i686.so
Files/bin/engine_amd.so
Files/bin/engine_i486.so
Files/bin/engine_i686.so
Files/bin/tier0_i486.so
... |
How can I copy all the files mentionned in that file to another location, like ~/patch5/ and regenerate the directory tree as well ? |
|
Back to top |
|
|
Hoshimaru Apprentice
Joined: 09 Nov 2003 Posts: 225 Location: Belgium
|
Posted: Mon Nov 08, 2004 5:21 pm Post subject: |
|
|
I tried this...
Code: | # cp -Rv `cat new.txt` target/ |
it copies the right files, but it doesn't regenerate the directories on target.
Files/bin/file1.bin become target/file1.bin
That's not what I'm looking for :'( |
|
Back to top |
|
|
abcdefg Apprentice
Joined: 29 Feb 2004 Posts: 216 Location: The Netherlands
|
Posted: Mon Nov 08, 2004 9:19 pm Post subject: |
|
|
There probably a faster way, but his was some good bash practise for me
Code: | from=/home/user/location
to=/home/user/another_location
files=$(find $from/ -mtime 2)
for X in $files
do
Y=$(dirname $(echo "$X" | sed "s:$from::g"))
mkdir -p $to/$Y
cp $X $to/$Y
done |
I think this should work, place this text in a file and make it executable (chmod +x file) of course modify the from and to locations. |
|
Back to top |
|
|
Hoshimaru Apprentice
Joined: 09 Nov 2003 Posts: 225 Location: Belgium
|
Posted: Thu Nov 11, 2004 10:01 am Post subject: |
|
|
Hi, thanks for your script
I almost works. It's having trouble with directories containing blanks. It forgets the part after the blank.
I'm looking how I can add
to your script.
It's a long time ago since I did shell scripts and almost forget everything :s
Last edited by Hoshimaru on Fri Nov 12, 2004 7:40 am; edited 1 time in total |
|
Back to top |
|
|
abcdefg Apprentice
Joined: 29 Feb 2004 Posts: 216 Location: The Netherlands
|
Posted: Thu Nov 11, 2004 9:42 pm Post subject: |
|
|
I have no idee how to solve that problem. Currently it puts all the files that must be copied in a variable seperated by spaces, like: "/home/user/file1 /home/user/file with spaces /home/ etcetc" The problem is that is sees a file with spaces like two (or more) different files. Which of course isn't correct...
Does somebody else know how to solve this problem? |
|
Back to top |
|
|
karatefish n00b
Joined: 27 Oct 2004 Posts: 34 Location: Singapore
|
Posted: Fri Nov 12, 2004 3:33 am Post subject: |
|
|
what about using the tar method from here? tar preserves directory structures in usual use, I can't see why it wouldn't work in this case....
edit: I just did a quick test and it seems to work fine. The command I guess would be something like:
Code: | tar -cf - `cat new.txt` | tar -C ~/patch5/ -xvf - |
assuming you've already created the ~/patch5 directory of course... |
|
Back to top |
|
|
|