LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-15-2008, 03:29 PM   #1
Linux Fan
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Rep: Reputation: 15
Unhappy get linux file size


how can I get the file'size in a variable, is it linux shell command
cheers

Last edited by Linux Fan; 07-15-2008 at 03:31 PM.
 
Old 07-15-2008, 03:38 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You can try the stat command. To assign the output of a command to a variable, you can do "command substitution". In Bash the syntax is var=$(command) but often you will see back ticks - as in var=`command`.

In brief, to assign file size to a variable you can do something like
Code:
size=$(stat -c %s filename)
see man stat for details.
 
Old 07-15-2008, 03:47 PM   #3
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
this should work in most cases

ls -l <filename> | cut -f 5 -d " "

if it doesn't, try changing f or d in cut.
the default format of ls -l might be different in your distro
it might use tabs and not spaces and might put the size not in the 5th place
 
Old 07-16-2008, 02:57 AM   #4
Linux Fan
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Original Poster
Rep: Reputation: 15
thanks a lot
your help makes me always LINUX FAN
 
  


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
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM
maximum linux file size? alec77 Linux - Newbie 8 12-03-2004 09:31 AM
Is there a file size limitation in Linux? lazyboy0001 Linux - Software 12 08-12-2004 08:28 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM


All times are GMT -5. The time now is 11:18 PM.

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