Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Help. noob needs help with file copy!
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 4 Weeks Ago   #21 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
Ok. i figured out the different options. I had to change the -c to -f for format and then I had to change -y to -a for last time modified.

Now when I run I am getting the error with the spaces in the folder names. i tried putting double quotes in like this:

Code:
#!/bin/bash
(cd "/FolderA"
	find "." | xargs stat -f "%a|%n") > astats.txt
(cd "/FolderB" 
	find "." | xargs stat -f "%a|%n") > bstats.txt
sort astats.txt bstats.txt | uniq -d | sed -e 's/^.*|/cp \/FolderA\//' -e 's/$/ \/FolderB/' > copysametime.sh
but to no avail. I am getting this as ouput:
Code:
stat: ./AnimalToysIcons/License: stat: No such file or directory
stat: -: stat: No such file or directory
stat: Read: stat: No such file or directory
stat: Me.url: stat: No such file or directory
stat: ./new: stat: No such file or directory
stat: folder: stat: No such file or directory
stat: ./new: stat: No such file or directory
stat: folder/CODES.txt: stat: No such file or directory
stat: ./AnimalToysIcons/License: stat: No such file or directory
stat: -: stat: No such file or directory
stat: Read: stat: No such file or directory
stat: Me.url: stat: No such file or directory
stat: ./new: stat: No such file or directory
stat: folder: stat: No such file or directory
stat: ./new: stat: No such file or directory
stat: folder/CODES.txt: stat: No such file or directory
arggggg......
wildside is offline   Reply With Quote
Old 4 Weeks Ago   #22 (permalink)
wje_lf
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 969
Ooo. Spaces in filenames. Naughty user!

I got this to work:
Code:
(cd /FolderA; find . -print0 | xargs --null stat -c "%y|\"%n\"") > astats.txt
and so forth. Of course, you'll have to use -f instead of -c and change -y to -a.

What's happening is that the -print0 switch tells the find command to use a NUL character to terminate each file name, and the --null option tells the xargs command to use a NUL character to look for a NUL terminator, rather than that evil whitespace.

The other modification wraps double quotes around the filenames so that the cp command will do right by you.

There's much of this that I haven't tested, so check the script which this script outputs.

(Are you sure that -a means time last modified? I don't have access to your Mac man pages, but you'd think that -a would mean time last accessed (time last read), and maybe something like -m would mean time last modified. Maybe you can re-check. )
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 4 Weeks Ago   #23 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
We are both on the same page here my friend. I researched all the commands in their respective man pages and found (right before you posted) that this is what I should be doing:

Code:
find . -print0 | xargs -0 stat -f "%a|%n"
same as you said. exepct xargs -0 must be the same as --null

the only thing that worries me now is that when i run the command alone all i get is this:

Code:
1216411396|
1216397273|
1216411396|
1216397273|
1216397273|
1216411396|
1216397273|
1216397273|
1216397273|
1216397273|
1216397273|
1216397273|
1216397273|
1216411396|
1216397273|
1216397273|
1216411396|
1216397273|
is this right?
I will be checking again on the %a in the mean time
wildside is offline   Reply With Quote
Old 4 Weeks Ago   #24 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
ok i got it. I used this:

Code:
find . -print0 | xargs -0 stat -f "%m|%N"
and got this:
Code:
1216309964|.
1216309969|./.DS_Store
1213138317|./AnimalToysIcons
1213138366|./AnimalToysIcons/.DS_Store
1094571886|./AnimalToysIcons/Fasticon.com.url
1213138317|./AnimalToysIcons/Icons
1187593089|./AnimalToysIcons/Icons/.DS_Store
1188906563|./AnimalToysIcons/Icons/Elephant
1188906571|./AnimalToysIcons/Icons/Giraffe
1188906546|./AnimalToysIcons/Icons/Gorilla
1188906554|./AnimalToysIcons/Icons/Lion
1188906534|./AnimalToysIcons/Icons/Zebra
1173656658|./AnimalToysIcons/License - Read Me.url
1215932134|./C_PROJECTS
1215931838|./C_PROJECTS/conversion.cpp
1114280757|./CODES.txt
1216267609|./new folder
1114280757|./new folder/CODES.txt
whew... on to the next step.
sorting!
wildside is offline   Reply With Quote
Old 4 Weeks Ago   #25 (permalink)
wje_lf
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 969
Make sure that the find command delivers only regular files and not, um, directories also:
Code:
find . -type f -print0
(Check your man page to be sure.)
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 4 Weeks Ago   #26 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
OK. look s like everything is working out except one minor thing:
Code:
cp -p /FolderA/"./AnimalToysIcons/Fasticon.com.url" /FolderB
cp -p /FolderA/"./CODES.txt" /FolderB
cp -p /FolderA/"./AnimalToysIcons/License - Read Me.url" /FolderB
cp -p /FolderA/"./AnimalToysIcons/Icons/.DS_Store" /FolderB
cp -p /FolderA/"./AnimalToysIcons/Icons/Zebra" /FolderB
cp -p /FolderA/"./AnimalToysIcons/Icons/Gorilla" /FolderB
cp -p /FolderA/"./AnimalToysIcons/Icons/Lion" /FolderB
cp -p /FolderA/"./AnimalToysIcons/Icons/Elephant" /FolderB
cp -p /FolderA/"./AnimalToysIcons/Icons/Giraffe" /FolderB
cp -p /FolderA/"./AnimalToysIcons/.DS_Store" /FolderB
cp -p /FolderA/"./C_PROJECTS/conversion.cpp" /FolderB
So it is putting all the files in the root of FolderB
wildside is offline   Reply With Quote
Old 4 Weeks Ago   #27 (permalink)
wje_lf
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 969
Replace the final line of my suggested script with:
Code:
sort astats.txt bstats.txt | uniq -d | sed -e 's/^\(.*\)$/cp \/FolderA\/\1 \/FolderB\/\1/' > copysametime.sh
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 4 Weeks Ago   #28 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
I think i will need to hash out this last sed command when I get time to read up on sed. That one give me this as the output:

Code:
cp -p /FolderA/1094571886|"./AnimalToysIcons/Fasticon.com.url" /FolderB/1094571886|"./AnimalToysIcons/Fasticon.com.url"
cp -p /FolderA/1114280757|"./CODES.txt" /FolderB/1114280757|"./CODES.txt"
cp -p /FolderA/1173656658|"./AnimalToysIcons/License - Read Me.url" /FolderB/1173656658|"./AnimalToysIcons/License - Read Me.url"
cp -p /FolderA/1187593089|"./AnimalToysIcons/Icons/.DS_Store" /FolderB/1187593089|"./AnimalToysIcons/Icons/.DS_Store"
cp -p /FolderA/1188906534|"./AnimalToysIcons/Icons/Zebra" /FolderB/1188906534|"./AnimalToysIcons/Icons/Zebra"
cp -p /FolderA/1188906546|"./AnimalToysIcons/Icons/Gorilla" /FolderB/1188906546|"./AnimalToysIcons/Icons/Gorilla"
cp -p /FolderA/1188906554|"./AnimalToysIcons/Icons/Lion" /FolderB/1188906554|"./AnimalToysIcons/Icons/Lion"
cp -p /FolderA/1188906563|"./AnimalToysIcons/Icons/Elephant" /FolderB/1188906563|"./AnimalToysIcons/Icons/Elephant"
cp -p /FolderA/1188906571|"./AnimalToysIcons/Icons/Giraffe" /FolderB/1188906571|"./AnimalToysIcons/Icons/Giraffe"
cp -p /FolderA/1213138366|"./AnimalToysIcons/.DS_Store" /FolderB/1213138366|"./AnimalToysIcons/.DS_Store"
cp -p /FolderA/1215931838|"./C_PROJECTS/conversion.cpp" /FolderB/1215931838|"./C_PROJECTS/conversion.cpp"
wildside is offline   Reply With Quote
Old 4 Weeks Ago   #29 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
So i read up on sed. what a fantastic utility!

so Im getting caught up on the sed line you wrote. I tried to re-organize it using the : instead of the / and it looks like this now:

Code:
sort astats.txt bstats.txt | uniq -d | sed -e 's:^\(.*\)$:cp\ -p\ \/FolderA\/\1 :/FolderB\/\1' > copysametime.sh
So where im getting messed up is where the delimiter should be going. if you can help me with that I think I can figure oout the rest of the substitues.

thanks
wildside is offline   Reply With Quote
Old 4 Weeks Ago   #30 (permalink)
wildside
Just Joined!
 
Join Date: Jul 2008
Posts: 20
Ok... This code is half of what i need:

Code:
sort astats.txt bstats.txt | uniq -d | sed -e 's:[0-9]*|".:cp -p "/FolderA:'
when i run it, I get half of the command that i need.
Code:
cp -p "/FolderA/AnimalToysIcons/Fasticon.com.url"
cp -p "/FolderA/CODES.txt"
cp -p "/FolderA/AnimalToysIcons/License - Read Me.url"
cp -p "/FolderA/AnimalToysIcons/Icons/.DS_Store"
cp -p "/FolderA/AnimalToysIcons/Icons/Zebra"
cp -p "/FolderA/AnimalToysIcons/Icons/Gorilla"
cp -p "/FolderA/AnimalToysIcons/Icons/Lion"
cp -p "/FolderA/AnimalToysIcons/Icons/Elephant"
cp -p "/FolderA/AnimalToysIcons/Icons/Giraffe"
cp -p "/FolderA/AnimalToysIcons/.DS_Store"
cp -p "/FolderA/C_PROJECTS/conversion.cpp"
so my question is:
Can I just re-run 's again ont he same stream and change the whole string to say FolderB and add that to the end?
wildside is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 10:49 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0