Advertisement
Guest User

P1 SHELL

a guest
Jan 23rd, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #Shell:Realizati un program shellscript ce primeste ca argument un nume de director S.
  2. #Scriptul va parcurge recursiv directorul S si va calcula spatiul total ce se poate obtine daca se vor sterge fisierele #duplicate.
  3. #Se considera ca doua fisiere sunt duplicate daca au aceeasi dimensiune si nume.
  4.  
  5. cale_temp=nimic
  6. fisier_temp=nimic
  7. prezent=0
  8. limita=1
  9. total=0
  10.  
  11. recursiv() {
  12. for i in `ls $1`
  13. do
  14.   if test -f $1/$i
  15.     then
  16.     if [ `wc -c $cale_temp | awk '{print $1}'` -eq `wc -c $1/$i | awk '{print $1}'` -a `echo $fisier_temp` = `echo $i` -a `echo $cale_temp` != `echo $1/$i` ]
  17.       then
  18.            prezent=$((prezent + 1))
  19.     fi
  20.   elif test -d $1/$i
  21.     then recursiv $1/$i
  22.   fi
  23. done
  24. }
  25.  
  26. recursiv_principal(){
  27. for j in `ls $1`
  28. do
  29.   if test -f $1/$j
  30.     then
  31.     cale_temp=$1/$j
  32.     fisier_temp=$j
  33.     recursiv $1
  34.     if [ $prezent -ge $limita ]
  35.       then
  36.            total=$((total + prezent * `wc -c $1/$j | awk '{print $1}'`))
  37.         prezent=0
  38.     fi
  39.   elif test -d $1/$j
  40.     then recursiv_principal $1/$j
  41.   fi
  42. done
  43. }
  44. recursiv_principal $1
  45. echo "Numarul de bytes care ar putea fi eliberati = "$total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement