Generate a directory for files

This commit is contained in:
nemunaire 2014-01-20 18:59:49 +01:00
parent 363ba3325a
commit 9108124ca4

26
gen_hash_link_files.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
FROM=`realpath $1`; shift
TO=`realpath $1`; shift
if [ -z "$FROM" ] || [ -z "$TO" ]
then
echo "Usage: $0 from to"
exit 1
elif ! [ -d "$FROM" ]
then
echo "$FROM not found"
exit 2
fi
mkdir -p "$TO" || exit 3
rm -rf "$TO" || exit 3
for i in `find "$FROM" -mindepth 1 -type f`
do
FILE=`echo $i | sed "s!^$FROM/!!"`
HASH=`echo -n $FILE | sha384sum | cut -d " " -f 1`
mkdir -p "$TO/$HASH/"
ln -s "$i" "$TO/$HASH/"
done