LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-24-2010, 06:24 PM   #1
tara
Member
 
Registered: Aug 2005
Location: Australia
Distribution: Centos 7
Posts: 58

Rep: Reputation: 15
Determine the size of file in a script


Hi,

I have the following which works but think there must be a easier one-liner way of doing this which involves not writing to a file but have failed to find something that works

This is what I have:

Code:
du -m $i > filesize.txt
FILESIZE=$`cat "filesize.txt" | cut -f1
rm filesize.txt
I then use the FILESIZE to compare to a number.

cheers,
Tara
 
Old 06-24-2010, 06:35 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
stat -c%s $i
 
1 members found this post helpful.
Old 06-24-2010, 06:48 PM   #3
stevexyz
LQ Newbie
 
Registered: Apr 2008
Location: Hampshire, UK
Distribution: None
Posts: 27

Rep: Reputation: 16
Perhaps you could try something like FILESIZE=$(du -m $i) Steve
 
Old 06-24-2010, 07:34 PM   #4
tara
Member
 
Registered: Aug 2005
Location: Australia
Distribution: Centos 7
Posts: 58

Original Poster
Rep: Reputation: 15
got it with

Code:
FILESIZE="$((`stat -c%s $i` / 1000000))"
The 1000000 is 1000 * 10000 to get to M. Probably more correct as 1024 but not that important.

Thanks
 
  


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
shell script to determine if file size equals zero jonfa Programming 5 12-11-2007 04:48 PM
s there a way to determine the owner of a file by using a script? DHoody Programming 4 01-27-2006 10:01 AM
k3b only works as root: can't determine size of resulting image file c-- Linux - Software 5 03-07-2005 07:28 PM
How to determine file system block size? provo1234 Linux - Newbie 2 02-14-2005 09:30 AM
K3B error could not determine size of resulting image file mdm_green Fedora 1 12-11-2004 04:34 PM

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

All times are GMT -5. The time now is 12:56 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
Open Source Consulting | Domain Registration