Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/csh
- 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."
- echo "Script call should look like this: csh [path to script] [folder to search in]"
- if ($1 == "") then
- echo "You must pass a path to the folder."
- exit
- endif
- set folder = $1
- set subfolders = `find $folder -type d`
- set maxFilesCount = 0
- foreach subfolder ( $subfolders )
- if ($subfolder == $1) continue
- set files = `find $subfolder -maxdepth 1 -type f`
- set filesCount = 0
- foreach file ( $files )
- @ filesCount ++
- end
- echo "Subfolder $subfolder contains $filesCount files"
- if ($filesCount > $maxFilesCount) then
- set maxFilesCount = $filesCount
- set subfolderWithMaxFilesCount = $subfolder
- endif
- end
- if ($maxFilesCount == 0) then
- echo "All the subfolders are empty."
- exit
- endif
- #echo $subfolderWithMaxFilesCount $maxFilesCount
- set filesFromBigFolder = `find $subfolderWithMaxFilesCount -type f`
- set totalFilesSize = 0
- foreach file ( $filesFromBigFolder )
- set filesize = `stat -c %s $file`
- # echo $file $filesize
- @ totalFilesSize += $filesize
- end
- echo
- 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