Reputation: 21
I'm trying to automate an archive process and I'm unsure how to go about a particular aspect.
Currently I manually check whether any files exist over a certain size with find . -size +4194304k -print and if it comes back without any files I'll use cpio if does I'll use tar. How would I test fot that condition?
Thanks
Bryan
Upvotes: 1
Views: 1797
Reputation: 5062
#!/bin/bash
# For a list of files
#large_files=`find . -size +4194304k -print`
# For a test of files
large_files=`find . -size +4194304k -print | cut -c1`
if [[ -z $large_files ]]
then
# No large files
else
# Large files present
fi
Just to clarify about return codes and exit codes:
# Exit codes
$ find . -name foo && s=$?
$ echo $s
0
$ find . -name f1 && s=$?
./f1
$ echo $s
0
# Return codes
$ s=$(find . -name foo)
$ [[ ! $s ]] && echo "N"
N
$ s=$(find . -name f1)
$ [[ $s ]] && echo "Y"
Y
Upvotes: 2