Skip to main content
2 of 2
formatting; tags; grammar
chaos
  • 49.3k
  • 11
  • 127
  • 147

Detecting file size and do operation conditionally

In my main_dir, I have a lot of sub-folders say DFT1 to DFT150, and in each directory, there is a file named OSZICAR. However, some of this would have file size 0.

So I would like to have a script, that goes into each folder and checks the size of OSZICAR, if it is below size of 10 bytes, then delete its DFT folder.

The pseudo-code (which doesn't work), I have is:

for f in *; do
 cd $f
 status=(check whether OZICAR has size below 10bytes)
 cd ..
 if (status); do
  rm -r $f
 fi 
done
user40780
  • 2k
  • 4
  • 16
  • 16