Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress files larger than a certain size in a directory?

The idea behind this code is to find all files within a directory larger than 1KB (or 1000 bytes), compress them, and delete them from the original directory. I was able to figure out both of the separate commands but am unsure how to link the output from the first to the second commands (if that makes sense)? Can anyone point me in the right direction?

# Initialize variables
dir=~/Test 

# Change directory to $DIRECTORY
cd "$dir"

# Find all files in the current directory that are larger than 1000 bytes (1KB).
find . -maxdepth 1 -type f -size +1000c | zip -mT backup
like image 968
IAspireToBeGladOS Avatar asked Sep 05 '25 23:09

IAspireToBeGladOS


1 Answers

Use the -exec option instead of trying to pipe the next command:

find . -maxdepth 1 -type f -size +1000c -exec zip -mT backup {} \;

Would create a zip archive containing the matched files.

like image 170
l'L'l Avatar answered Sep 10 '25 07:09

l'L'l