LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2006, 10:25 PM   #1
bricedebrignaisplage
Member
 
Registered: Apr 2006
Location: singapore
Distribution: debian
Posts: 51

Rep: Reputation: 16
how to get the size of a file in a shell variable


how to get the size of a file in shell?
"ls -ls 1.JPG" gives
"104 -rw-r--r-- 1 casa casa 99341 2006-10-18 10:41 1.JPG"
but how to get the first part, 104, in a shell variable? I would to compare with a numerical value.

Is there any other solution?
 
Old 10-17-2006, 10:55 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
filesize=$(stat --format=%s 1.JPG)
 
Old 10-18-2006, 02:34 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
BTW, %s = bytes, you asked for blocks; use %b
 
  


Reply



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 Size Shell Script BlackLabel Programming 7 11-27-2007 07:48 PM
openswan-variable size of key bart0094 Linux - Security 0 09-06-2006 03:19 PM
How to know the size of the variable without using sizeof() ? indian Programming 6 08-02-2006 11:04 PM
how to send shell variable data to a text file ginda Programming 7 06-23-2006 05:49 AM
Commit file size to a variable mark_wexler Programming 2 05-26-2006 06:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:41 AM.

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
Open Source Consulting | Domain Registration