LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-05-2005, 06:20 AM   #1
loopoo
Member
 
Registered: Aug 2005
Posts: 40

Rep: Reputation: 15
Get the size of a file


Hi!

Can anyone tell me how can I get the size of a file?


Thanks in advance,
Chris
 
Old 12-05-2005, 06:25 AM   #2
T.Hsu
Member
 
Registered: Jan 2005
Posts: 178

Rep: Reputation: 31
du -h file

man du
 
Old 12-05-2005, 06:25 AM   #3
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
Code:
ls -l file
 
Old 12-05-2005, 06:51 AM   #4
loopoo
Member
 
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
Hi again!

Thanks for your replies.

Unfortunately, "du -h file" doesn't seem to work on my system. I'm on AIX 4.3
In the man file, "-h" option is present, but the error is:

du: Not a recognized flag: h
Usage: du [-a | -s] [-rlkx] [Name ...]


Also, ls -l , or ls -s is not portable....I need to take this info into a variable...not just to see it....

Thanks,
Chris
 
Old 12-05-2005, 07:14 AM   #5
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Rep: Reputation: 30
Hi Loopoo,

I see that du -s is present ..that sh dwork just fine except that you get the output in bytes if Im not mistaken.Ive not done too much shell scripting..bit of a noob there...but logically u shd be able to redirect o/p to a file ..so wat Im saying is:

#touch abc

#vi abc
blah bkadaksfpsa

#cat abc > test

Then use ur scripting skills to read from the file or sed/awk to parse the file.
U shd be okay...bit of a crude explanation but its the best I can give...sorry..

Arvind
 
Old 12-05-2005, 07:47 AM   #6
loopoo
Member
 
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
Hi live_dont_exist

I tried with du -s.....but I can't split the fields with "cut"..don't know why...
What I need is a command that will take the file as parameter and return its size...doesn't matter if in bytes, kbytes....I just want to check if the file is empty or not...

Thanks a lot,
Chris
 
Old 12-05-2005, 08:13 AM   #7
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Rep: Reputation: 30
Hi Chris,

Heres what u can du...

#vi abcd
4 5 6 7 8 9

#cut -d' ' -f1 abcd > output

The stuff after d is for the space delimiter....you should get only 4 in the output file.

So if you get 0 as the character in the output file you know that the file is empty

keep posting
Arvind

Last edited by live_dont_exist; 12-05-2005 at 08:14 AM.
 
Old 12-05-2005, 08:15 AM   #8
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Try this:
Code:
$ du -s /tmp/kde-peter | gawk '{print $1};'
44
where,of course, you use your own file name.

And, I, too, got no output from split. Strange.

Oh, if you just want to test for an empty file in a shell (bash) script, try test -s file. See info test for details.

Last edited by PTrenholme; 12-05-2005 at 08:24 AM.
 
Old 12-05-2005, 08:21 AM   #9
loopoo
Member
 
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
Tanks, PTrenholme .
Thas is just what I asked for.

Thank you all for your help,
Chris
 
Old 12-05-2005, 08:28 AM   #10
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Have you tried stat?
stat -c %s file.txt
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I know the size of a file using C skie_knite007 Programming 3 04-04-2005 10:49 AM
when creating a *.iso file, how to make the file size smaller? minm Linux - Newbie 8 12-26-2004 09:58 PM
Getting size of a file yrraja Linux - General 4 12-15-2004 06:18 AM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
get file size in C++ danxl Programming 3 11-18-2003 09:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:07 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