Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-25-2006, 03:08 PM   #1
LQ Newbie
Registered: May 2006
Posts: 2

Rep: Reputation: 0
Commit file size to a variable

hey folks - I'm new to Linux and - nice to meet you all - and here is my first question

How can I grab the size of a file and commit it to a variable?

I know how to use "stat /file -c %s" to print the file size to the screen and I know how to init a variable "variableName=value" but I can't seem to figure out how put the file size int a variable as an integer.

FYI: I am using this to create an automated backup script that backs up files based on file size. I need to be able to run an if/then statement based on a file size comparison.

Thanks in advance,

Old 05-25-2006, 03:37 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
FSIZE=`stat /file -c %s`  # note: back-quotes ( ` not ')
# or:
FSIZE=$(stat /file -c %s)   # bash only
Old 05-26-2006, 06:48 AM   #3
LQ Newbie
Registered: May 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Perfect! thanks Hko


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
default array size for variable in gcc compiler mlaich Programming 13 01-04-2006 05:40 PM
reading a char string of variable size in C introuble Programming 3 05-08-2005 01:07 PM
mldonkey commit file access problem dropwise Slackware 0 12-31-2004 04:35 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
why i'm getting this when i commit a file glalu Linux - General 1 08-03-2002 06:08 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:05 PM.

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