Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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
share|improve this answer
    
this seems logic. Thanks –  Adrian George Aug 26 '13 at 15:57
    
This will break if any of the filenames contain spaces. –  evilsoup Aug 26 '13 at 16:14
    
Good catch. Edited to avoid that problem –  dan08 Aug 26 '13 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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