1

I am using this 3 line shell script and it works to compare 2 files sizes.

FIRSTV=`stat -c%s crk03-rtr-002-20140504.rsc`
SECONDV=`stat -c%s crk03-rtr-002-20140503.rsc`
echo `expr $FIRSTV - $SECONDV`

If there a way I could do this on 1 line using expr or a better command which can tell me the number of bytes differnce between 2 files?

L

2
  • 1
    Why is having three lines a problem? Commented May 4, 2014 at 7:51
  • 1
    Note that echo `expr $FIRSTV - $SECONDV` produces exactly the same output as expr $FIRSTV - $SECONDV; you don't need the echo or back-quotes. Commented May 4, 2014 at 8:02

1 Answer 1

1

Yes you can do:

expr `stat -c%s crk03-rtr-002-20140504.rsc` - `stat -c%s crk03-rtr-002-20140503.rsc`

In BASH/ksh/dash and few more shells you can make use of (( )) (arithmetic evaluation brackets):

echo $(( $(stat -c%s crk03-rtr-002-20140504.rsc) - $(stat -c%s crk03-rtr-002-20140503.rsc) ))
Sign up to request clarification or add additional context in comments.

1 Comment

Arithmetic expansion is not bash specific but part of the POSIX standard. Your second line would work with ksh, dash and others. pubs.opengroup.org/onlinepubs/9699919799/utilities/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.