0

I have a requirement of finding the directory size which is more than a particular value and I made a script for the same. But find command is not accepting -size section. Can anyone help me on this

echo -e "This script will generate report for directories which consumes more size than the given value"
read -p " Enter the file system or directory full path: " path
read -p " This script will check the directories which is greater than the given size Please Enter the directory size in GB: " size
find $path  -type d -size +$sizeG -exec ls -ld {} \;

error

find: invalid -size type `+'
9
  • Your command looks for a variable named sizeG; you want ${size}G, or "$size"G, or "${size}G". Commented Aug 26, 2020 at 17:13
  • 1
    -size on directories probably doesn't work as you expect. It doesn't count the size of the files inside the directory. You probably need to use du $path instead and filter out the directories you want. Commented Aug 26, 2020 at 17:15
  • I reopened as "not a duplicate" because fixing the variable name error doesn't result in what you want, as per @TedLyngmo's comment. Commented Aug 26, 2020 at 17:16
  • 2
    Does this answer your question? Check folder size in Bash Commented Aug 26, 2020 at 17:19
  • 1
    Use df instead of du if you want the size of an entire volume. Commented Aug 26, 2020 at 17:57

1 Answer 1

0

In order to eliminate bad substitution error in bash script. Wrap the variable size with a double quota.

    echo -e "This script will generate report for directories which consumes more size than the given value"

read -p " Enter the file system or directory full path: " path
read -p " This script will check the directories which is greater than the given size Please Enter the directory size in GB: " size

echo "+${size}G";

find $path  -type d -size "+${size}G" -exec ls -ld {} \;
Sign up to request clarification or add additional context in comments.

4 Comments

I tried it but not working. To narrow down the issue, I tried to execute find command alone and found it is not giving result if we use -type d. find /root -size +10M -type d -exec ls -ld {} \;
if you are getting permission denied error. Try with Sudo privilege.
Sample from ubuntu: fatihsennik@fatihsennik:~$ find / -type d -size +10G -exec ls -ld {} \; find: ‘/etc/polkit-1/localauthority’: Permission denied
No. It is not permission denied error. output will not get id we use type but we will get the result if we use type f

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.