Find files according to size and archive them

Here is a bash script for finding all files whose size is higher than the given size in the parameter and archiving it. Below line of code you can put into your script file. Following the find command in the script will search files, not directories that are larger than one character.

Let me explain below shell script. The first line of the shell script runs the find command in the current path because we use ./, you can use your searching path instead of ./, where you have to search the file. size option we are using for searching for more than one character. and files variable stores all searching output. techtrname stores all files, which fetch from the find command. after that tar command archives the fetch file and create the file.

More options of find the command you can use. Click the Here to Read More option in the Find command.

files=$(find ./ -type f -size +1c)
#fix names in case there are spaces. Insert \ to escape spaces
techtrname="${files// /\\ }"
tar -czf techtransit.tar.gz $techtrname

About Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks!

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *