![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to search for text in a file and copy file | imeadows | UNIX for Dummies Questions & Answers | 9 | 11-12-2008 09:12 PM |
| Noob on Unix. | bobtheb | UNIX for Dummies Questions & Answers | 7 | 07-10-2008 07:56 AM |
| how to copy a file to a directory ,where file and dir are sent as args to a function? | wrapster | Shell Programming and Scripting | 0 | 06-08-2008 08:37 AM |
| Script to capture new lines in a file and copy it to new file | fara_aris | Shell Programming and Scripting | 0 | 05-27-2008 11:11 PM |
| complete noob | avdrummerboy | UNIX for Dummies Questions & Answers | 3 | 12-04-2006 12:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Something like this perhaps: Code:
#!/usr/bin/ksh
find /srcdir -type f | while read f
do
destfile=$(echo $f | sed 's#/srcdir#/destdir#')
if find $destfile -newer $f
then
print "$destfile is newer than $f, skipping"
else
print cp -p $f $destfile
fi
done
Obviously take out the second print once you've confirmed that it's going to do what you want. Last edited by Annihilannic; 07-17-2008 at 04:17 AM.. Reason: typo |
|
||||
|
Quote:
THANK YOU! this is where I have been trying to get to. So I tried to convert it to using Bash Shell. (im on OS 10.5) Here is my script: Code:
#!/bin/bash
find /FolderA -type f | while read f
do
destfile=$(echo "$f" | sed 's#/FolderA#/FolderB#')
if find $destfile -newer $f
then
echo "$destfile is newer than $f, skipping"
else
echo cp -p $f $destfile
fi
done
When i run it, it looks like it will do everything correctly. I threw some random files in and changed a couple to test. I am getting an error where I think it is stumbling on a directory name with a space in it. I tried puting quotes on things here and there but to no avail. here is the line form the output. Code:
find: /FolderA/new: No such file or directory cp -p /FolderA/new folder/CODES.txt /FolderB/new folder/CODES.txt so it looks like it stumbles but then copies the file in the directory anyway. Is there a way to help this spaced directory error? |
|
||||
|
hmmm.... So it looked like it was going to work. I put those quotes in. I made an exact copy of the files in FolderA and put them in FolderB. (if the same everything should say it will copy) and I get this: Code:
/FolderB/.DS_Store /FolderB/.DS_Store is newer than /FolderA/.DS_Store, skipping /FolderB/AnimalToysIcons/.DS_Store is newer than /FolderA/AnimalToysIcons/.DS_Store, skipping /FolderB/AnimalToysIcons/Fasticon.com.url is newer than /FolderA/AnimalToysIcons/Fasticon.com.url, skipping /FolderB/AnimalToysIcons/Icons/.DS_Store is newer than /FolderA/AnimalToysIcons/Icons/.DS_Store, skipping /FolderB/AnimalToysIcons/Icons/Elephant is newer than /FolderA/AnimalToysIcons/Icons/Elephant, skipping /FolderB/AnimalToysIcons/Icons/Giraffe is newer than /FolderA/AnimalToysIcons/Icons/Giraffe, skipping /FolderB/AnimalToysIcons/Icons/Gorilla is newer than /FolderA/AnimalToysIcons/Icons/Gorilla, skipping /FolderB/AnimalToysIcons/Icons/Lion is newer than /FolderA/AnimalToysIcons/Icons/Lion, skipping /FolderB/AnimalToysIcons/Icons/Zebra is newer than /FolderA/AnimalToysIcons/Icons/Zebra, skipping /FolderB/AnimalToysIcons/License - Read Me.url is newer than /FolderA/AnimalToysIcons/License - Read Me.url, skipping /FolderB/C_PROJECTS/conversion.cpp is newer than /FolderA/C_PROJECTS/conversion.cpp, skipping /FolderB/CODES.txt is newer than /FolderA/CODES.txt, skipping /FolderB/new folder/CODES.txt is newer than /FolderA/new folder/CODES.txt, skipping |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|