LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-26-2011, 07:32 PM   #1
Chupakabra
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Rep: Reputation: Disabled
comparing a file size to a given number


I'm trying to write a script that takes two arguments, the first argument is a number, and the second argument is a filename. The shell script should indicate if the file's size is BIGGER or SMALLER the number provided.


this is what i have sofar, am i on the write track, i'm hoping its just a problem with my if command

if [ $1 -h $2 ]
then
echo "$1 is bigger than $2"
else
echo "$1 is smaller than $2"
fi
 
Old 07-26-2011, 07:38 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by Chupakabra View Post
I'm trying to write a script that takes two arguments, the first argument is a number, and the second argument is a filename. The shell script should indicate if the file's size is BIGGER or SMALLER the number provided.


this is what i have sofar, am i on the write track, i'm hoping its just a problem with my if command

if [ $1 -h $2 ]
then
echo "$1 is bigger than $2"
else
echo "$1 is smaller than $2"
fi
Your condition $1 -h $2 is nothing that's valid in bash.
Plus there's a semicolon missing after ]

Cheers,
Tink
 
Old 07-26-2011, 07:39 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,357

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
According to this http://tldp.org/LDP/abs/html/fto.html '-h' = 'file is a symbolic link' so I think you're looking at it wrong.
What you need to do is use ls -l and grab the size field (eg via awk) or try the stat cmd http://linux.die.net/man/1/stat
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
file comparing abhijeetdutta Linux - Server 5 09-10-2009 09:51 PM
lvm: PE size, number of stripes and stripe size considerations tramni1980 Slackware 1 08-07-2009 10:19 AM
file comparing and printing viveksnv Programming 11 02-28-2008 03:55 AM
comparing file xlordt Programming 5 11-19-2007 03:32 AM
comparing music file pantera Programming 2 07-01-2004 02:57 AM


All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration