Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  1. #!/bin/csh
  2. echo "This script searches in the preset directory for a subdirectory which contains maximal count of files. Than it calculates total size of files in this subdirectory."
  3. echo "Script call should look like this: csh [path to script] [folder to search in]"
  4. if ($1 == "") then
  5.   echo "You must pass a path to the folder."
  6.   exit
  7. endif
  8.  
  9. set folder = $1
  10. set subfolders = `find $folder -type d`
  11. set maxFilesCount = 0
  12.  
  13. foreach subfolder ( $subfolders )
  14.   if ($subfolder == $1) continue
  15.     set files = `find $subfolder -maxdepth 1 -type f`
  16.     set filesCount = 0
  17.     foreach file ( $files )
  18.       @ filesCount ++
  19.     end
  20.     echo "Subfolder $subfolder contains $filesCount files"
  21.     if ($filesCount > $maxFilesCount) then
  22.       set maxFilesCount = $filesCount
  23.       set subfolderWithMaxFilesCount = $subfolder
  24.     endif
  25. end
  26.  
  27. if ($maxFilesCount == 0) then
  28.   echo "All the subfolders are empty."
  29.   exit
  30. endif
  31.  
  32. #echo $subfolderWithMaxFilesCount $maxFilesCount
  33.  
  34. set filesFromBigFolder = `find $subfolderWithMaxFilesCount -type f`
  35. set totalFilesSize = 0
  36. foreach file ( $filesFromBigFolder )
  37.   set filesize = `stat -c %s $file`
  38.  # echo $file $filesize
  39.   @ totalFilesSize += $filesize
  40. end
  41.  
  42. echo
  43. echo "The subfolder with max files count ($maxFilesCount) is $subfolderWithMaxFilesCount. Total size of files in this subfolder is $totalFilesSize bytes."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement