Go Back   MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 9, 2012, 08:21 PM   #1
JonBerry
macrumors newbie
 
Join Date: Nov 2012
Create an individual MD5 file for each folder in a main directory

The specs for a file delivery I'm making require an individual MD5 file per folder, with the contents of that folder being inside the MD5 file. Such as:

DAY_01 (MAIN FOLDER)
A01
-(files 1-1000)
-md5 for files 1-1000
A02
-files 1001-2000
-md5 for files 1001-2000

And so on. Is there a script or program that can make those MD5 files automatically or do I hace to go and do each one individually? Thanks
JonBerry is offline   0 Reply With Quote
Old Nov 11, 2012, 09:53 PM   #2
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: San Diego, CA USA
You didn't specify what kind of interface you are looking for. Are you comfortable with the shell in Terminal?

Create the following text file in your home directory.

Code:
#!/bin/bash

function do_sum
{
	local $ans;

	for f in $@ ;
	do
		if [ -f $f ];
		then
			ans=`openssl md5 < $f`
			echo "$ans $f" >> md5sums.out
		fi
	done
}

s=$(pwd)

cd $1
if [ -f md5sums.out ]; then 
	rm -f md5sums.out
fi
do_sum *
cd $s
If you call this file "do_sums.sh". Then:

Code:
chmod +x do_sums.sh
find MAIN_DIR -type d -exec ~/do_sums.sh {} \;
... where MAIN_DIR is the top level directory in question. This script will create a file "md5sums.out" in each directory.

Last edited by mfram; Nov 11, 2012 at 10:04 PM.
mfram is offline   0 Reply With Quote
Old Nov 12, 2012, 01:34 PM   #3
JonBerry
Thread Starter
macrumors newbie
 
Join Date: Nov 2012
Maybe I'm doing it wrong

I tried that, created the do_sums.sh and put it in the home folder as requested. Ran the terminal command though and got and error like this:

/Tusers/jberry/do_sums.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf360: command not found
/Tusers/jberry/do_sums.sh: line 2: syntax error near unexpected token `}'
/Tusers/jberry/do_sums.sh: line 2: `{\fonttbl\f0\fswiss\fcharset0 Helvetica;}'

I'm a complete novice when deciphering terminal codes so any help would appreciated. Thanks!
JonBerry is offline   0 Reply With Quote
Old Nov 12, 2012, 01:35 PM   #4
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: San Diego, CA USA
That's RTF, not a text file. And the script takes a parameter, the name of the directory where you want to generate the file.
mfram is offline   0 Reply With Quote
Old Nov 12, 2012, 07:55 PM   #5
JonBerry
Thread Starter
macrumors newbie
 
Join Date: Nov 2012
Fixed, but still issues

Fixed the rtf issue. Here's what I've been doing, and let me know how completely far off I am:

-copy do_sums.sh (renamed from a text file) into the home directory (under my user)
-open terminal and cd into the main directory above the folder I want to make MD5's of. So:

FOLDER_1
-MAIN FOLDER <---CD into this via terminal)
-Shot1
-Shot2
-etc.

type in the commands you listed with /VOLUMES/V1/MAIN_FOLDER in place of MAIN_DIR

Still get an issues of No such file or directory with regards to the do_sums.sh:

find: /Tusers/jberry/do_sums.sh: No such file or directory.

Any thoughts? Am I in the right place?
JonBerry is offline   0 Reply With Quote
Old Nov 13, 2012, 01:02 AM   #6
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: San Diego, CA USA
Maybe you have spaces in the filenames? My initial script wouldn't have handled that well. Also, be careful of case. Although the filesystem may not be case-sensitive, the shell is often case sensitive. Finally, be sure to double-check the name of your script. Here's another try:

File ~/do_sums.sh
Code:
#!/bin/bash

s=$(pwd)

cd "$@"
for i in *; do
	if [ -f "$i" ]; then
		ans=$(openssl md5 < "$i")
		echo "$ans $i" >> md5sums.out
	fi
done
cd "$s"
Make sure to "chmod +x do_sums.sh" the script after it is created.

The lines starting with "$" are the commands entered. The rest are the output. "ls" means list files
"cat" means print the contents of a file.
"find" means to find files and do some operation on them.

Code:
$ ls -l ~/do_sums.sh
-rwxr-xr-x  1 user  staff  145 Nov 12 22:39 do_sums.sh*
Make sure the "x" shows up as above.

Here's an example. I'm using an external Flash drive with a FAT filesystem.

Code:
$ ls -l -R "/Volumes/NO NAME/test"
total 16
drwxrwxrwx  1 user  staff  4096 Nov 12 22:45 Dir 1/
drwxrwxrwx  1 user  staff  4096 Nov 12 22:45 Dir 2/

/Volumes/NO NAME/test/Dir 1:
total 24
-rwxrwxrwx  1 user  staff  12 Nov 12 22:21 1 - File.txt*
-rwxrwxrwx  1 user  staff  11 Nov 12 22:21 2 - File.txt*
-rwxrwxrwx  1 user  staff  15 Nov 12 22:21 3 - File.txt*

/Volumes/NO NAME/test/Dir 2:
total 16
-rwxrwxrwx  1 user  staff  16 Nov 12 22:22 01 - FF.txt*
-rwxrwxrwx  1 user  staff  14 Nov 12 22:22 02 - FF.txt*

$ find "/Volumes/NO NAME/test" -type d -exec ~/do_sums.sh {} \;

$ ls -l -R "/Volumes/NO NAME/test"
total 16
drwxrwxrwx  1 user  staff  4096 Nov 12 22:46 Dir 1/
drwxrwxrwx  1 user  staff  4096 Nov 12 22:46 Dir 2/

/Volumes/NO NAME/test/Dir 1:
total 32
-rwxrwxrwx  1 user  staff   12 Nov 12 22:21 1 - File.txt*
-rwxrwxrwx  1 user  staff   11 Nov 12 22:21 2 - File.txt*
-rwxrwxrwx  1 user  staff   15 Nov 12 22:21 3 - File.txt*
-rwxrwxrwx  1 user  staff  138 Nov 12 22:46 md5sums.out*

/Volumes/NO NAME/test/Dir 2:
total 24
-rwxrwxrwx  1 user  staff  16 Nov 12 22:22 01 - FF.txt*
-rwxrwxrwx  1 user  staff  14 Nov 12 22:22 02 - FF.txt*
-rwxrwxrwx  1 user  staff  90 Nov 12 22:46 md5sums.out*

$ find "/Volumes/NO NAME/test" -name 'md5*' -print -exec cat {} \;
/Volumes/NO NAME/test/Dir 1/md5sums.out
c6ad45b534cb0b5d94915f70d06805fb 1 - File.txt
ae73b736bf34cbd74f9b1926b16d9815 2 - File.txt
6a48187d882925248e6dd0fe8c907d8e 3 - File.txt
/Volumes/NO NAME/test/Dir 2/md5sums.out
3ad65dd4430b55270c2829d1380c3794 01 - FF.txt
d6e6e2ae2539151395860a3943298806 02 - FF.txt
mfram is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Almost 42000 of exe and pif files on my main folder/directory and on macintosh hd aaronmagahis MacBook Pro 1 May 8, 2014 04:58 AM
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory xpmrz Mac Basics and Help 0 Dec 31, 2013 02:59 PM
Help verifying MD5 of rcd system file max6166 OS X Mavericks (10.9) 5 Oct 24, 2013 05:09 PM
iPhone: How to change individual folder icons? x-evil-x Jailbreaks and iOS Hacks 7 Mar 4, 2013 07:18 PM
Help to create txt file of tons of images in a folder zenmster Mac Applications and Mac App Store 3 Jun 26, 2012 10:56 AM

Forum Jump

All times are GMT -5. The time now is 11:47 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC