Single line archive log files command if exceed certain limit in Linux

Hello Guys,

Is there a single line archive command to zip or tar log files which is larger than certain size limit ?

Do let me know if there is any.

Thanks

Hello UnknownGuy,

On UNIX.com we encourage users to add their efforts which they have put in order to solve their own problems.
So please do let us know what you have tried to solve this.

Thanks,
R. Singh

I can run a find /home/ -type f -size 6579c -exec ls {} \; command to check file size & then run zip command to archive them but I don't want to run multiple commands, need something which does the job in single line, is there anything like that ?

Just replace your ls by what you want to do, in your one liner above...

1 Like

this solves the purpose.

--- Post updated at 04:28 PM ---

Thanks vbe,

this solves the purpose

1 Like
find /  -xdev -size +10M -exec du -sh {} \; | sort -nr

where 10M is size you can change.

You might discover that sizes considered by find are based on blocks and might not exactly match what you want.

If this is the case and you need it to be perfect, consider running find to get all the possible files then reading each with stat -c '%s' "${filename}" to get the size of the file in bytes.

Robin

Guys found the answer : I wanted to check file size & if its bigger than 100kb need to zip it, all in one line.
Below is the answer, thanks for help.

find $LogFile -type f -size +100k -exec zip -r $LogFile.zip {} \;