Skript mis otsib kõik pildi,video,muusika,dokumendi failid ja jagab need kaustadesse - BASH: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<source lang=" | <source lang="bash"> | ||
GNU nano 2.2.2 File: Testscript.sh | GNU nano 2.2.2 File: Testscript.sh | ||
Revision as of 12:19, 28 January 2011
GNU nano 2.2.2 File: Testscript.sh
#!/bin/bash
array=( .mp3 .wav .doc .pdf )
array2=( /home/Muusika /home/Muusika /home/Dokumendid /home/Dokumendid )
for x in `seq 0 2`;
do
find /home -name *"${array[x]}" > /home/Log.txt
if [ -d "${array2[x]}" ];then
find "${array2[x]}" -name *"${array[x]}" | awk -F/ '{ print $NF }' > /home/Kaust.txt
fi
if [ -s /home/Kaust.txt ];then
while read line2
do
sed -i "/$line2/ d" /home/Log.txt
done < /home/Kaust.txt
rm /home/Kaust.txt
fi
if [ ! -d "${array2[x]}" ];then
mkdir "${array2[x]}"
fi
awk -F/ '{ print $NF }' Log.txt|sort| uniq > /home/FNimi.txt
while read line1
do
grep -m 1 "$line1" Log.txt | sort | uniq -u >> /home/Log.txt.new
done < /home/FNimi.txt
rm /home/FNimi.txt
if [ -f Log.txt.new ];then
while read line
do
echo "Paigutan faili:" "$line" "Uude asukohta:" "${array2[x]}"
mv -i "$line" "${array2[x]}" -n
done < /home/Log.txt.new
rm /home/Log.txt.new
fi
done
rm /home/Log.txt