File size and dir size

How to use 'df' only to get the 'Available' space for a specific dir, and then compare with a specific file size using stat -c %s file.txt to see if the file actually can be copied into the dir. Is there any quick way to see if a file can fit into a dir?

df /dir/you/want | awk '{print $4}' | grep -v Avail

or

df /dir/you/want | awk '{print $4}' | tail -1

Will return just the Available space for 'df'. You can then you comparisons using tests or if commands

 freespace=`df /dir/you/want | awk '{print $4}' | tail -1`
myfile=`stat -c %s /path/to/file.txt`
[ "$freespace" -gt "$myfile" ] && echo "The file will fit"

DC_Slick, don't forget that df usually returns free size in 512 or 1K byte blocks.

Emilywu, does your df support the -k option to output sizes in 1024 byte blocks?

If so you might be able to do somthing like this:

freespace=$(( $(df -k /dir/you/want | awk '{S=$4} END{print S}') * 1024 ))

Thanks for all your answers. They worked fine.
Chubler XL, Yes, -k is ok for me. do you mean that we can't compare the file size using stat and the freespace suggested by DC since the block size used by stat is also 1024 byte?

DC was using %s in the stat command, which reports size in bytes. This is the best way to go as the blocksize %b uses can vary from filesystem to filesystem, where df will use the same blocksize for all filesystems. So you won't be comparing apples with apples.