|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
|
#1 |
|
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 |
|
|
|
0
|
|
|
#2 |
|
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
Code:
chmod +x do_sums.sh
find MAIN_DIR -type d -exec ~/do_sums.sh {} \;
Last edited by mfram; Nov 11, 2012 at 10:04 PM. |
|
|
|
0
|
|
|
#3 |
|
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! |
|
|
|
0
|
|
|
#4 |
|
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.
|
|
|
|
0
|
|
|
#5 |
|
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? |
|
|
|
0
|
|
|
#6 |
|
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" 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* 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
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 09:47 PM.






Hybrid Mode
