DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2009-02-16 22:15:23

Marijom
Member
From: Sweden
Registered: 2007-07-06
Posts: 54

md5Sum: Is it possible to get a md5 for each file in directory?

I'm wondering if there is an easy way making a md5 file for each on the directory or do i have to run md5sum for each file?

md5sum film1.iso > film1.md5
md5sum film2.iso > film2.md5
md5sum film3.iso > film3.md5

Offline

 

#2 2009-02-16 22:33:55

bzhou
Member
Registered: 2008-02-15
Posts: 171

Re: md5Sum: Is it possible to get a md5 for each file in directory?

for f in `find . -type f`; do (md5sum ${f} > ${f}.md5); done

Offline

 

#3 2009-02-16 22:42:21

Marijom
Member
From: Sweden
Registered: 2007-07-06
Posts: 54

Re: md5Sum: Is it possible to get a md5 for each file in directory?

Thanks

Offline

 

#4 2009-02-17 03:43:20

devotee
Member
From: Valencia, Spain
Registered: 2008-12-12
Posts: 43

Re: md5Sum: Is it possible to get a md5 for each file in directory?

In a single command:

find -type f -exec md5sum {} \; >CHECKSUMS.md5

You can combine it with any other find options (man find for more info):

find -iname *.iso -type f -exec md5sum {} \; >CHECKSUMS.md5
(md5 of all filenames that match *.iso case insensitive from the actual folder)

find Music -iname *.mp3 -mtime -1 -type f -exec md5sum {} \; >CHECKSUMS.md5
(md5 of all filenames that match *.mp3 case insensitive in "Music" folder that have been modified in the last 24 hours)

I love Unix wink


CH3SNAS • 2x Seagate Barracuda ES 7200.11 ST31000340AS 1TB SATAII (3.0Gb/s) 7200RPM 32MB (Rev: SD1A) • Individual volumes • FW1.05 (Firmware Date: 12/31/2008) • ext2

Offline

 

#5 2009-02-17 09:11:01

Marijom
Member
From: Sweden
Registered: 2007-07-06
Posts: 54

Re: md5Sum: Is it possible to get a md5 for each file in directory?

Thanks

Any problem with spaces in the filename as it was in the first one?

Last edited by Marijom (2009-02-17 09:11:22)

Offline

 

#6 2009-02-20 18:15:49

Marijom
Member
From: Sweden
Registered: 2007-07-06
Posts: 54

Re: md5Sum: Is it possible to get a md5 for each file in directory?

And if I want to do more then a single command e.g. check if there already exist a md5 for the file




devotee wrote:

In a single command:

find -type f -exec md5sum {} \; >CHECKSUMS.md5

You can combine it with any other find options (man find for more info):

find -iname *.iso -type f -exec md5sum {} \; >CHECKSUMS.md5
(md5 of all filenames that match *.iso case insensitive from the actual folder)

find Music -iname *.mp3 -mtime -1 -type f -exec md5sum {} \; >CHECKSUMS.md5
(md5 of all filenames that match *.mp3 case insensitive in "Music" folder that have been modified in the last 24 hours)

I love Unix wink

Offline

 

#7 2009-02-22 21:21:31

Marijom
Member
From: Sweden
Registered: 2007-07-06
Posts: 54

Re: md5Sum: Is it possible to get a md5 for each file in directory?

I don't know if there is any interest in the end result but here it is

#!/ffp/bin/sh
#-vx

if [ "$1" == "" ]
then
    find -type f -exec $0 "{}" \;
    exit
fi

if [ -d "$1" ]
then
    find "$1" -type f -exec $0 "{}" \;
    exit
fi

if [ -f "$1" ]
then
    ffile=$1
    Ext=${ffile##*.}
   
    if [ "$Ext" != "md5" ]
    then
        Path=${ffile%/*}
        file="./${ffile##*/}"
        md5file="./checksum.md5"
        cd "$Path"
   
        if [ -f $md5file ]
        then
            grep -F -i "$file" $md5file > /dev/null
            if [ $? -ne 0 ]
            then
                echo "md5sum $ffile"
                #sleep 10
                md5sum "$file" >> $md5file
            else
                echo "Done $ffile"
            fi
        else
            echo "md5sum $ffile"
            md5sum "$file">$md5file
        fi 
    fi
fi

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB