I am trying to find all files which size is higher than $1 (parameter) and zip them using a shell script.


find . -type f -size +$1c = $files
tar -xf $files

But I think this isn't the right solution.


Assuming your find command works the way you want you just need to change your bash syntax a bit. Also your tar command is extracting -x.

files=$(find ./ -type f -size +$1c)
#fix names in case there are spaces. Insert \ to escape spaces
goodNames="${files// /\\ }"
tar -czf bigfiles.tar.gz $goodNames
  • This will break if any of the filenames contain spaces. – evilsoup Aug 26 '13 at 16:14
  • Good catch. Edited to avoid that problem – Dan Aug 26 '13 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.