Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Can I copy files – but with certain restrictions?

I have just finished a large project, the archives of which involves about 5000 "base" files, stored on about 80 CDs and 50 DVDs, involving about 50,000 files in total. Each of the "base" files may have had up to 30 incremental versions. i.e. a certain text file may have undergone revision 23 times, and each revision was saved and archived to (probably) a different disk, with a different suffix – a, b, c and so on. But sometimes the suffix didn't change even though the file was edited. I might have done a bit more dust removal on an image and just overwrote the old file (already archived), and so the new one was archived on a different disk.

I now have 130 disks from which I would like to extract all the files and collapse them to one large archive that will probably span about 20 disks by the time I delete some files not needed. That way I can easily search for all versions of, say, GB097, by going to the particular DVD that has the "G" files on it. Up would come:

GB097
GB097a
GB097b
GB097b-1
GB097b-2
GB097c
... and so on.

This is what I would like to do:

1. Grab the first archive disk, open every folder, and copy all the files to the one folder on a hard drive.

2. Open the second disk and repeat step (1), but with these two provisos.

(a) If a file is identical to a previously copied file (maybe I archived it twice), the file isn't copied. However...

(b) If a file has the same name as a previously copied file, but the data within that file is different (i.e. I removed some dust from an image file, but left the name unchanged), I'd like that file to be copied with a numbered suffix, the same way that Trash treats identically named files.

Any suggestions how I could do this?

G5 iSight, Mac OS X (10.4.11)

Posted on May 18, 2010 3:27 AM

Reply
92 replies

May 27, 2010 10:27 PM in response to Guy Burns

How are you running Terminal? What exactly are you double-clicking or clicking from the Dock (and from which side of the vertical bar?)

This line that you posted:
/Volumes/C-Data/Consolidate\ Test\ Files/consolidate14.command; exit

Is what you should see if you double-clicked the Consolidate14.command file... if you double click the Terminal app in /Applications/Utilities, you shouldn't see a reference to that command file.

May 28, 2010 12:02 AM in response to Guy Burns

When I select File> New Shell I now get:

+Last login: Fri May 28 16:46:13 on ttyp4+
+Welcome to Darwin!+
+jenny-pearces-imac-g5:~ Jenny$+

and I am able to type in simple commands. Before I trashed my preference folder, I did not get this simple message. but the one previously posted.

When I double click on consolidate14 I get:

+Last login: Fri May 28 16:46:17 on ttyp5+
+/Volumes/C-Data/Consolidate\ Test\ Files/consolidate14.command; exit+
+Welcome to Darwin!+
+jenny-pearces-imac-g5:~ Jenny$ /Volumes/C-Data/Consolidate\ Test\ Files/consolidate14.command; exit+

+Consolidate14 script revised 2010-05-25 10:00 P.M.+

+Folder not specified. Type the path to the top-level folder or drag+
+it into this Terminal window, then click back in this window and press return:+

And the script stops at the LordB2002.mp3 file. I don't think the script stops at 10,000 lines like I assumed. It seems to stop every time at this file which has two checksums that are both: 037e57b3870f9186739c11c1d8b94c11

I thought consolidate14 might have been corrupted, so I unzipped it again and the same thing happens. That suggest to me there is something sus in OSX or elsewhere that Terminal or the script is accessing.

I'm going to restore my OSX and all software. No big deal, I do that regularly and it only takes about 10 minutes. But first I'll try it on another of my OSXes. I've got three separate OSXes on separate drives, and the others are virgins, shall I say.

May 28, 2010 12:31 PM in response to Guy Burns

Here is an overview of the terminal commands. Lets assume that your account has a short user name of mac.
Macintosh-HD -> Applications -> Utilities -> Terminal
#How to list all of your disks.
# The ls command is for li st
mac $ ls /Volumes/
Audio CD Macintosh-HD Spotless Tiger-ext
mac $


# Let's say your flash drive is named Spotless

# cd is change directory
mac $ cd /Volumes/Spotless
# pwd is print working directory
mac $ pwd
/Volumes/Spotless
mac $




# The ls command is for li st
# l is long
# F is type of file where / is directory
mac $ ls -lF
total 134704
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files/
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards/
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009/
... trimmed ...


What does all this mean?

drwxrwxrwx

d = directory
r = read
w = write
x = executeable program

drwxrwxrwx
| | |
| | all other users not in first two types
| |
| group
|
owner



# l is long
# a is all to show hidden files & folders
mac $ ls -lFa
total 134736
drwxr-xr-x 41 mac staff 1496 Dec 22 17:11 .
drwxrwxrwt 8 root admin 272 Dec 24 13:55 ..
-rwxrwxrwx 1 mac staff 15364 Dec 23 12:52 .DS_Store*
drwx------ 4 mac staff 136 Jan 22 2009 .Spotlight-V100
drwxrwxrwt 5 mac staff 170 Sep 14 16:36 .TemporaryItems
d-wx-wx-wx 4 mac staff 136 Dec 31 1969 .Trashes
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009

... trimmed ...



# mv is move or rename
mv -i the-name the-new-name

# You can just rename the file back to what it was with mv command.
mv -i old-name new-name

Here is what these commands mean:
cd is change directory
pwd is a print working directory
ls is list
sudo is Super user do
mv is move or rename

For cryptic comments, you can always uses the manual command which is man. For example:
man mv

# Type the letter q to quit.

I noticed that you had spaces in your filenames or directories. You need to escape them. See examples:

mac $ ls -l ~/"see it"
-rw-r--r-- 1 mac staff 3171 Oct 26 23:38 /Users/mac/see it
mac $
mac $ cd /Users/mac/Desktop/ttt\ html\ copy/

Do you know about tabing? Type in a few letters of a name then press the tab key. The computer will type out the rest of the name if it is unique.

Press the up arrow(s) to see the previous command(s).

history to see many previous commands.


Robert

May 29, 2010 12:51 AM in response to Guy Burns

I've started testing consolidate14 again. All runs are on a backup 59.3 GB folder with ~11,300 files on an external FW drive. Between runs I restore the folder from the original folder using SilverKeeper, in case anything changed.

In all cases I created a new shell, dragged consolidate14 to the window, dragged the folder to the window, and selected "n" so that no files are moved.

*Run 1* (buffer = 10,000 lines) -- completed in 5741 seconds.

*Run 2* (buffer = unlimited) -- failed at LordB2002.mp3

*Run 3* (Quit Terminal, buffer set to 10,000, clicked on "set as default") -- failed at LordB2002.mp3

*Run 4* (Quit Terminal, buffer came up as "unlimited", reset to 10,000, clicked on "set as default") -- failed at LordB2002.mp3

I've posted about not being able to set 10,000 as the default ( http://discussions.apple.com/thread.jspa?threadID=2444078&tstart=0), because I thought that might be causing the problem.

Any idea how I can reset Terminal to its defaults?

May 29, 2010 8:08 AM in response to Guy Burns

This is a summary of what I have discovered about consolidate14 and Terminal.

1. With a brand new Terminal, set to the default 10,000 line buffer, the first run works.

2. I assume all subsequent runs would also work. Will try and test that on another of my OSXes.

3. If "unlimited scrollback" is selected in Terminal, the script stops somewhere after 3000 lines. The number varies. It does not stop because of a particular file. I removed LordB2002 and the script stopped at another file.

4. Once "unlimited scrollback" is selected, the Script never again completes a long run, and there appears nothing you can do about it -- except reload OSX.

If I can get the script running on another OSX, I'll try several runs to prove point 2. Otherwise I'll try the other Terminal mentioned by Robert.

May 31, 2010 12:24 AM in response to Guy Burns

This is the result of testing consolidate12 using a backup Test folder of 8.0 GB with 2047 files, of which maybe a few hundred are duplicates. Test (not its real name) is a sub folder of my Archive folder.

1. I restored OSX from a diskimage that I have for just this purpose, to a partition on an external FW drive. It's a brand new OSX with nothing else on the partition. I booted into that OSX.

2. I dragged consolidate12 to the Terminal window, followed by Test, and selected "n" so that files were not moved. 435 seconds later the script finished a complete run.

3. I repeated 2. The script completed the run in 388 seconds.

4. I repeated 2 again – completion time 388 seconds.

5. I ran SilverKeeper to restore Test to its full complement of files. I checked that the original Test and the backup Test were identical by running Toast's Compare utility. About 10 minutes later the answer came back: "The folders are identical". I should be back where I started at step 2.

6. I repeated step 2. The run failed.

7. I quit Terminal, deleted the "plist" preference file, and repeated step 2. The run failed.

8. I deleted the "plist" file again and rebooted, then repeated step 2. The run failed.

9. I rebooted into my normal OSX (which had already been through several failed runs), repeated step 2, and the run failed.

It seems to me that the problem is connected with restoring my Test folders with SilverKeeper. If I run the script on a large folder, it will complete the task. If I then restore the folder so that I can test again, the script fails -- even though the folder is reported by Toast (and SK) as being identical to the original. The failure is then permanent. Nothing except a new OSX will make the script run correctly again.

I had an idea that maybe Terminal, plist, or the script were being corrupted. But when I compared them with the same three files on another pristine OSX partition, Toast report all three as being identical.

I'm at a loss to explain how this could happen. Identical software running on an identical folder, but because the folder has undergone a restore, the software fails. The problem only occurs with folders above a certain size. When I ran similar tests to the above on a much smaller folder, including the use of SK, the script always completed its run.

Any ideas as to why the script is failing to complete its run?

I looks to me like the script will be useful when I finally come to use it, but this problem with restoring means I can't test it thoroughly.

May 31, 2010 12:12 PM in response to Guy Burns

SilverKeeper V2.0.2 is a new release of LaCie's free backup application. It has been designed to support Apple's OS X operating system for Intel and PowerPC based Macintosh computers.


Suspect!

Try a different backup utility.

CCC features an interface designed to make the cloning and backup procedure very intuitive.
http://www.bombich.com/

--------

How to duplicate a folder in termainal:
ditto -X -rsrc ~/Pictures/MP\ Navigator /Volumes/Spotless/backup/MP\ Navigator

-----
Is the duplicate folder the same?

Try making your top level folder a bundle. Use silverkeeper to duplicate. Make new folder a bundle. & use tool to compare the two bundles by putting both in a new folder.

See command:
/Developer/Tools/SetFile
/Developer/Tools/GetFileInfo

These two commands are in xcode tools. Install if needed.

------
/Developer/Applications/Utilities/FileMerge may be able to do a folder compare.

Robert

May 31, 2010 6:48 PM in response to rccharles

Thanks for the suggestions, Robert. Unfortunately, CCC is not as flexible as SK. Several years ago I extensively tested CCC, and most other cloning software, and for my purposes SK came out on top. For example, CCC cannot clone sub-folders to sub-folders (which is what I want to do while testing) and anyway, CCC takes about 10 times as long to clone (see the last post, and the third before that (mine) at http://forums.bombich.com/viewtopic.php?t=15540).

The Compare utility within Toast reports that: "The folders are identical" before each test run, so I assume they are. Maybe there is an invisible file within my test folder that SilverKeeper puts there which is causing the problem, but which the Compare utility does not detect.

RE XCode, I don't think I have that, and if I remember correctly from a post of mine years ago, it is not possible to put it back without doing a complete reinstall of OSX. But if you can tell me how to get it back, I'll give it a go.

Jun 1, 2010 12:30 PM in response to Guy Burns

Guy Burns wrote:
Thanks for the suggestions, Robert. Unfortunately, CCC is not as flexible as SK. Several years ago I extensively tested CCC, and most other cloning software, and for my purposes SK came out on top. For example, CCC cannot clone sub-folders to sub-folders (which is what I want to do while testing) and anyway, CCC takes about 10 times as long to clone (see the last post, and the third before that (mine) at http://forums.bombich.com/viewtopic.php?t=15540).


This is a little non-intuitive to me. You say you might have a problem with SK, but you continue testing with SK expecting somehow your results to change.

You are testing here. The objective is to try to find out what is causing the script to fail. The approach is to divide & conquer. You need to try different things to see what the common tread is.

The objective is to try to figure out why a script is stopping. You need to change what you are doing.

1) try iTerm

2) You somehow created a valid copy of the data where the script worked. Why did this copy work with script? This is what you want to know. Duplicate with the data in the finder. Use ditto. You need to rule out things.

I am only talking about testing not replacing your regular us of SK.

3) Try to reduce the size of the date while the error still occurs

4) Run the script in debug mode. Mega data out will result.

mac $ bash -vx consolidate17.command see
#!/bin/bash

# Purpose of this script:
# Find folders within a specified top folder which are not bundles. Find files within each found folder (and not within subfolders because each folder is handled individually.)
....clipped...


Warning lots of data to file outsee have mega gigs of free space

mac $ bash -vx consolidate17.command see 2>outsee

Consolidate17 script revised 2010-05-26 9:49 P.M.

WARNING: allowing the script to move files could cause problems!
Holding down Control-c on the keyboard will stop this script in an emergency.
....clipped...


Robert

Jun 3, 2010 12:56 AM in response to rccharles

I've been following a few trails trying to crack the problem with this script, and now I may have nailed it. Something along the lines of: if an item is already in the trash from a previous run, and the script tries to trash the same item on a subsequent run (because the folder being checked has been restored to its original condition), the script stops. That's my theory (at least for a large number of items in a folder) and it's backed up by:

1. If I run the script and it completes it run, there will be items in the Trash.

2. If I +don't+ restore the folder and run the script again, it completes the run. BUT, if I do restore the folder and run the script again, the script will fail.

3. BUT, if I restore the folder +and+ empty the trash, then run the script, it completes it run.

I'd like to alter the script so that instead of sending items to the Trash, it instantly deletes them. This is the relevant part of the script (+consolidate16+):

# Check each checksum against the sorted list, beginning at the current cell position in the array
# If a matching checksum is found, trash the matching file and wipe out it's values in the array
# If no match is found then break, the list is sorted so once there is no match we're done
for ((j=$((${i}+1));j<${count};j++)) ; do
[ -z "${filePath[${j}]}" ] && continue
if [ "${fileSum[${i}]}" = "${fileSum[${j}]}" ] ; then
mv "${filePath[${j}]}" ~/.Trash 2>/dev/null || mv "${filePath[${j}]}" ~/.Trash/$RANDOM
echo "${filePath[${j}]}" | tee -a "${MainFolder}/Consolidate_Trashed_List_${runDateTime}.txt"
filePath[${j}]='' fileSum[${j}]=''
else
break
fi
done

Does anyone know how to make a simple change to that part of the script, so that instead of trashing, the items are instantly deleted?

Re iTerm (already tested after it was suggested): it gave the same results as Terminal.

Jun 3, 2010 10:13 AM in response to rccharles

Be sure to make a complete backup of your system. Using delete in a loop is living on the edge.


# things are being moved to the trash here:
# mv "${filePath${j}}" ~/.Trash 2>/dev/null || mv "${filePath${j}}" ~/.Trash/$RANDOM
#well considering that rm is delete, You could just replace mv with rm.
rm "${filePath${j}}"


Message was edited by: rccharles

Can I copy files – but with certain restrictions?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.