Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
COmparing file size
Name: panther9_99 Date: January 30, 2005 at 20:29:43 Pacific OS: redhat 9 CPU/Ram: amd-64bit
Comment:
Hi there, can anybody tell me how to compare the size of the given files( 2 or more) and then display the one with bigger size. ( all this is in command line, I don't have GUI)
Name: David Perry Date: January 31, 2005 at 05:28:41 Pacific
Reply:
Create the following script. Make it executable ( chmod ugo+x scriptname ). Execute it with the names of the two files you want to compare.
#!/bin/sh if [ $# -ne 2 ] ; then echo "USAGE: $0 file1 file2" exit 4 fi file1=$1 file2=$2 file1size=`ls -l $file1 | awk '{ print $5 }'` file2size=`ls -l $file2 | awk '{ print $5 }'` if [ $file1size -eq $file2size ] ; then echo "$file1 and $file2 are the same size" elif [ $file1size -gt $file2size ] ; then echo "$file1 is larger with $file1size bytes" else echo "$file2 is larger with $file2size bytes" fi
0
Response Number 2
Name: panther9_99 Date: January 31, 2005 at 09:39:21 Pacific
Reply:
thanks for the script. ok, this script would work fine with two files. what if in a given directory there are several files and I just want to display the size of the biggest file. I figured out a way to display the file size and the file name, but all i want is the file size and not the file name. here is the command: ls -s | sort -nr | head -1 cannot figure out how can I just display the file size.
0
Response Number 3
Name: David Perry Date: January 31, 2005 at 10:40:51 Pacific
Reply:
ls -s | sort -nr | head -1 | awk '{ print $1 }'
Bear in mind that the -s flag shows a block count not a byte count.
0
Response Number 4
Name: panther9_99 Date: January 31, 2005 at 10:59:15 Pacific
Reply:
thanx david. so how do I show a byte count?
0
Response Number 5
Name: xan Date: January 31, 2005 at 13:24:56 Pacific
Summary: Hi, I have downloaded limewire and I have a question. Before I downloaded LimeWire I checked how much space I have free on my harddrive, which was 1.7gig. So I downloaded LimeWire and installed it. ...
Summary: Hello, im using Mandrake Linux 8.2, Kernel: 2.4.18. Im trying to move a file, and keep getting an error. The file is 650mbs, its on my windows partition, I want to move it from their to my ReiserFS pa...