LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 05-25-2006, 03:08 PM   #1
mark_wexler
LQ Newbie
 
Registered: May 2006
Posts: 2

Rep: Reputation: 0
Commit file size to a variable


hey folks - I'm new to Linux and LinuxQuestions.org - 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,

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

Rep: Reputation: 108Reputation: 108
Code:
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
mark_wexler
LQ Newbie
 
Registered: May 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Perfect! thanks Hko
 
  


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
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


All times are GMT -5. The time now is 10:17 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration