Aqui está a resposta no caso de alguém precisar:
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Usage: $0 <izvor> <destinacija>"
exit
fi
if [ ! -d "$1" ]
then
echo "Izvorniot folder ne postoi"
exit
fi
if [ -d "$2" ]
then
rm -r "$2"
mkdir "$2"
else
mkdir "$2"
fi
extension='ls -l "$1" | grep -v "^d" | awk '{ print $10; }' | sed 's/^.*\.//g''
for f in $extension
do
if [ ! -d "$1/$f" ]
then
mkdir "$2/$f"
fi
done
rec_copy(){
folder='ls "$1"'
for f in $folder
do
dest='echo "$f" | sed 's/.*\.//g''
to='cp "$1/$f" "$2/$dest"'
if [ -f "$1/$f" ]
then
echo "$to"
elif [ -d "$1/$f" ]
then
rec_copy "$1/$f" "$2"
fi
done
}
rec_copy "./$1" "./$2"