File size comparison in bash?
I am looking for a code to compare 2 different file size. Is there any reference? Any of you know?
Appreciate if you can help..... Thank You..... |
Check here http://www.linuxquestions.org/questi...28#post2386428 for instance.
|
Hi,
Something like this could do that: Code:
#!/bin/bash Hope this gets you going again. |
SIZE_01=`ls -l <file01> | awk '{ print $5 }'`
Using ls|awk is overkill if "stat -c %s" suffices. Just like I said in the post I mentioned. |
I had tried the below but it didnt works well. Actually the file1 is smaller size than file2
#ls -l /home/abc/logs/file1 | awk '{ print $5 }' 8933 #ls -l /home/abc/logs/file2 | awk '{ print $5 }' 2851050 Code:
#!/bin/bash Whats going on? I dont really understand the section [HTML]Check here http://www.linuxquestions.org/questi...28#post2386428 for instance.[/HTML] Anyone can help? |
Not sure that ">" as an operator works. "-gt" is the correct syntax for sure.
Usually you would put the variables in quotes: Code:
if [ "$SIZE_01" -gt "$SIZE_02" ] You also can use Code:
SIZE=`wc -c < myfile` jlinkels |
jlinkels is correct.
Where you expect a numeric comparison, Code:
-gt Code:
-ne Code:
> End |
Thanks man, you all are the best
|
All times are GMT -5. The time now is 09:09 AM. |