Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.11 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. Check (){
  4.  
  5. # $1 katalogas
  6.  
  7. k=1
  8.  
  9. check=`ls -l | grep index.txt`
  10.  
  11. if [ -z "$check" ]; then
  12.  
  13. k=0
  14.  
  15. fi
  16.  
  17. if [ $k -eq 0 ]; then
  18.  
  19. touch index.txt
  20.  
  21. fi
  22.  
  23. for i in *; do
  24.  
  25. if [ -f $i ] && [ "$i" != "index.txt" ]; then
  26.  
  27. check=`grep $i index.txt`
  28.  
  29. if [ -z "$check" ]; then
  30.  
  31. echo "Katalogas $1, aprasymas $i : "
  32.  
  33. read apr
  34.  
  35. echo $i " / " $apr >> index.txt
  36.  
  37. fi
  38.  
  39. fi
  40.  
  41. done
  42.  
  43. }
  44.  
  45. Delete() {
  46.  
  47. # 1 katalogas
  48.  
  49. for i in *; do
  50.  
  51. touch tarpinis.txt
  52.  
  53. check=`cat index.txt | grep $i`
  54.  
  55. if [ -n "$check" ]; then
  56.  
  57. #echo "==" +$check+
  58.  
  59. echo $check >> tarpinis.txt
  60.  
  61. fi
  62.  
  63. done
  64.  
  65. cat tarpinis.txt > index.txt
  66.  
  67. rm tarpinis.txt
  68.  
  69. }
  70.  
  71. #Surandami katalogai/failai, kurie atitinkamai irasomi i index.txt
  72.  
  73. dir=`pwd`
  74.  
  75. for i in *; do
  76.  
  77. if [ -d $dir/$i ]; then
  78.  
  79. cd $dir/$i
  80.  
  81. Check $i
  82.  
  83. cd $dir
  84.  
  85. elif [ -f $i ]; then
  86.  
  87. name=`basename "$PWD"`
  88.  
  89. Check $name
  90.  
  91. fi
  92.  
  93. done
  94.  
  95. #Pasalinami panaikinti failai
  96.  
  97. k=1
  98.  
  99. for i in *; do
  100.  
  101. if [ -d $dir/$i ]; then
  102.  
  103. cd $dir/$i
  104.  
  105. Delete $i
  106.  
  107. cd $dir
  108.  
  109. elif [ -f $i ] && [ k -eq 1 ]; then
  110.  
  111. k=0
  112.  
  113. name=`basename "$PWD"`
  114.  
  115. Delete $name
  116.  
  117. fi
  118.  
  119. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement