LinuxQuestions.org
Help answer threads with 0 replies.
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-14-2004, 07:32 AM   #1
yrraja
Member
 
Registered: Sep 2002
Distribution: RH, FC, Ubuntu, Solaris, AIX
Posts: 114

Rep: Reputation: 15
Getting size of a file


Hi

I want to write a script that finds the size of some of the files in a specific directory. Is there any command that returns the size of a file??

thanx
rYr
 
Old 12-14-2004, 07:36 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
Code:
stat -c %s filename

Last edited by acid_kewpie; 12-14-2004 at 07:37 AM.
 
Old 12-14-2004, 09:31 AM   #3
yrraja
Member
 
Registered: Sep 2002
Distribution: RH, FC, Ubuntu, Solaris, AIX
Posts: 114

Original Poster
Rep: Reputation: 15
thanx ..

On Redhat Linux WS 2.1 there is no -c option. In the remaining options i didnt find anything that gives the size of a file.

On AIX machine there is no stat command available.

Is there some other command available that i can use in my shell script??
 
Old 12-14-2004, 11:19 AM   #4
greeneagle
Member
 
Registered: Dec 2004
Location: Dublin Ireland via Cobh, Limerick.
Distribution: RedHat, Suse, Ubuntu.
Posts: 33

Rep: Reputation: 16
I think you need to quote "%s" like that.

I think you need to quote "%s"
stat -c "%s" awake.mp3
5158034

read stat --help

this is stat on redhat 9.1

also du (Disk Usage) command

du -b awake.mp3
5173248 awake.mp3

once you know what the commands are called you can read the manpages/
infopages on them
info -n "Top" "coreutils.info" "Disk usage"
covers du and stat and sf and sync for me.

If you're writing scripts then you might be reading the info/man pages lots!

which stat
/usr/bin/stat

stat --version
stat (coreutils) 4.5.3
Written by Michael Meskes.

stat awake.mp3
File: `awake.mp3'
Size: 5158034 Blocks: 10104 IO Block: 4096 Regular File
Device: 302h/770d Inode: 1771899 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ jamesc) Gid: ( 500/ jamesc)
Access: 2004-12-14 13:05:17.000000000 +0000
Modify: 2004-12-14 13:02:21.000000000 +0000
Change: 2004-12-14 13:02:21.000000000 +0000
 
Old 12-15-2004, 07:18 AM   #5
yrraja
Member
 
Registered: Sep 2002
Distribution: RH, FC, Ubuntu, Solaris, AIX
Posts: 114

Original Poster
Rep: Reputation: 15
thanx this info was helpful..

I did have a problem though that "du -b" option was not available in AIX so it works fine on Linux but fails on AIX. Now i am using a combination of "ls -l" and "awk" to get the size.

ls -l myfile.txt |awk '// {print $5}'

it works fine both in linux and AIX
 
  


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 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 11:49 AM
when creating a *.iso file, how to make the file size smaller? minm Linux - Newbie 8 12-26-2004 10:58 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 05:18 PM
How to get size of file in C Scrag Programming 5 05-20-2004 04:39 PM
get file size in C++ danxl Programming 3 11-18-2003 10:24 PM

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

All times are GMT -5. The time now is 07:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration