|
|
First attempt in Unix
|
|
|
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Hi all,
I ran into troubles on my backup files. Basically I need to organize 10,000+ photos in many nested folders/partitions.
http://forums.macnn.com/showthread.p...hreadid=237965
- Many Same Files under the Same Name in different folder/partition.
(ie. iPhoto)
- Many Different Files also under the Same Name, but different Size in different folder/partition.
(ie. the counter on digicam roll back)
- Many Different Files under the Same Name, but also Same Size in different folder/partition.
(ie. the webcam capture)
Since I never touch *nix before, only very few C in school, and never like programing too much. I hope I am on the right path.
Things I need to do:
Search all jpeg in one location,
List them by date,
Copy the file each at the beginning and save as "jpeg0001" and so on,
New folder for every 100 files. (or even better 650mb each)
Repeat for .tiff .bmp .crw etc
How much lines of code I am looking at?
I need to organize these photo, burn them all on DVD, edit and print ~500-1000 of them for a Huge X'mas family gathering. I better do the job right in front of 100+ family members...
John
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
This is a pretty large thing to do if you've never done any programming in UNIX before... Anyway, I'll give you some pointers. Use the man command on any of these:
The default shell in OS X is bash, but if you're used to C you may want to use tcsh instead. It's not really good for scripting, but it has the nifty foreach command. If not, then get a quick Perl introduction from eg. www.perl.org.
What you need to do is basically to get a list of all the files in question, sort it according to date and start copying them with a new name (generated from a counter) into various folders. Getting filenames is easy, use the "find" command. That command can also execute a command on each of the file it finds, with the "-exec" switch. To get a modification date, use "ls -l" on the path you just got. To grab the relevant field, use "awk" - something like this:
ls -l $filename | awk '{print $6,$7, $8}'
The |, pipe, means that you send the output of one command on to the next. You can also use > to rediret out put to a file. My first idea is to use to find to get a list of the file, use the exec switch to run the above ls -l command and make a file formatted like path/to/file;date.
That done, you can use the "sort" command to sort the list in the right order and the "cut" command (use the -f and -d switches) to remove the date again. Finally use this tempfile as input to a script that uses the "foreach" command (a lot like C for) to rename the files using a counter to generate the name. The folder thing you can hack up with a command that runs whenever the counter is a multiple of 100.
Not trivial, no. It's up to you to see if you can do it. Other interesting commands you may want to use is sed and xargs, they're useful in cases like this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|