- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: File Size
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 10:43 AM
тАО08-21-2006 10:43 AM
OS -> 11i
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 10:51 AM
тАО08-21-2006 10:51 AM
SolutionThe stat(2) system call is probably the most common means of getting this information programmatically.
Look at the stat(2) man page:
off_t st_size; /* File size (bytes) */
The st_size field contains the size of the file in bytes.
Regards,
Dave
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
- Tags:
- stat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 11:16 AM
тАО08-21-2006 11:16 AM
Re: File Size
Perl has access to the 'stat(2)' function. To list the names of files and their size in bytes, you can do:
# perl -le 'die unless @ARGV;print join " = ", $_, (stat($_))[7] for @ARGV' filename
For example:
# perl -le 'die unless @ARGV;print join " = ", $_, (stat($_))[7] for @ARGV' /etc/hosts /etc/services /etc/rc.config.d/netconf
...might return:
/etc/hosts/ = 606
/etc/services = 9946
/etc/rc.config.d/netconf = 3987
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 11:34 AM
тАО08-21-2006 11:34 AM
Re: File Size
If you want to limit the output only to regular files, amend my original post to:
# perl -le 'die unless @ARGV;for (@ARGV) {print join " = ", $_,(stat(_))[7] if (-f $_)}' /etc/hosts/ /etc/services /etc/rc.config.d
...returns (only):
/etc/hosts/ = 606
/etc/services = 9946
...since '/etc/rc.config.d' is a *directory*. My first variation treats files and directories equally and reports their byte-sizes.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 12:39 PM
тАО08-21-2006 12:39 PM
Re: File Size
- Tags:
- fstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 09:28 PM
тАО08-21-2006 09:28 PM
Re: File Size
there's even an easier way than to stat().
I wonder why people always forget about
the simple -s test.
E.g. this should print a size sorted list of all files in /tmp
(n.b. usually one would further refine by excluding the single dot references as well as directories etc.)
$ perl -e 'opendir TMP,"/tmp";print map{sprintf"%30s:%10u\n",$_->[0],$_->[1]}sort{$a->[1]<=>$b->[1]}map[$_,-s "/tmp/$_"],readdir TMP;closedir TMP'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 02:28 AM
тАО08-22-2006 02:28 AM
Re: File Size
"wc -c filename" will "Report the number of bytes in each input file".
is this fine?
[ofcourse, u need to cut the result of wc]
- Tags:
- wc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 02:43 AM
тАО08-22-2006 02:43 AM
Re: File Size
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 02:46 AM
тАО08-22-2006 02:46 AM
Re: File Size
Change:
wc -c filename
filename=
SIZE=$(wc -l $filename)
echo $SIZE
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 02:51 AM
тАО08-22-2006 02:51 AM
Re: File Size
filename=
SIZE=$(wc -l $filename)
echo $SIZE
should be
filename=
SIZE=$(wc -c $filename)
echo $SIZE
isnt?
[-l gives the number of lines
-c gives the number of bytes]