3

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

#!/bin/bash

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

But I think this isn't the right solution.

1 Answer 1

2

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
2
  • This will break if any of the filenames contain spaces.
    – evilsoup
    Aug 26, 2013 at 16:14
  • Good catch. Edited to avoid that problem
    – Dan
    Aug 26, 2013 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .