i want to put if condition for particular statement. The statement should only execute if particular file size is < 4 kb.
Please let me know the correct way.
i want to put if condition for particular statement. The statement should only execute if particular file size is < 4 kb.
Please let me know the correct way.
fsize=$(ls -l filename | nawk '{print $5}'); [ "$fsize" -gt "4" ] && echo "high" || echo "Less"
if [ `du -b filename | awk '{print $1}'` -le 4096 ]
Another utility that's really useful is stat, packaged with GNU's "coreutils".
fsize=$( stat -L -c %s )
if [ "$fsize" -lt 4096 ]; then
echo "Smaller than 4k"
fi
file_size=ls -lart | awk -F " " '{print $5}'
if [[ $file_size < 4 ]]
then ...
fi
Or with find.
toobig=$(find filename -size +4095c -print)
if [ -z "${toobig}" ]
then
# Process
fi
fs=$(ls -l file_name | awk '{print $5/1024}')
if [ $fs -lt 4 ]
echo "executed"
fi
Scanning the above posts is interesting. Some posters must have a version of "ls" which outputs in kilobytes not bytes.