LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2009, 01:47 PM   #1
LneWlf
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
Finding a file size


Hello, newbie here;

Scenario:

Need to find the size of a file (html), and display it in a summary file.

Any suggestions? (Have tried du, ls, size, but none of these work)

Thanks,

LneWlf
 
Old 12-07-2009, 02:06 PM   #2
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Not obvious why not just something like:
Code:
$ ls -lh filename.html > summaryFile.txt
 
Old 12-07-2009, 02:12 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi and welcome to LinuxQuestions!

Have you tried stat? By the way, what do you mean by "none of these work"? All the cited command can be used to retrieve different information from file objects, ls being the most suitable to retrieve the size of a file (unless you have to deal with sparse files). In any case, I believe stat is exactly what you're looking for.
 
Old 12-07-2009, 02:18 PM   #4
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
not obvious why use ls (o_0) instead of stat:
Code:
stat -c %s file.html > size.txt
uh?
 
Old 12-07-2009, 02:30 PM   #5
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Oh dear.
 
Old 12-07-2009, 05:52 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by LneWlf View Post
(Have tried du, ls, size, but none of these work)
you should then post what you did when none of these work. i can assure you du, ls will work, among others like stat, GNU find etc.
Code:
ls -l|awk 'NR>1{print $5}'
 
Old 12-07-2009, 06:06 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
As ghostdog mentioned, even find should work and you can take advantages of the searching criteria, e.g.
Code:
find . -name \*.html -printf "%f size is %s bytes\n"
 
  


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
Finding Buffer cache size Manjunath1847 Linux - Software 8 03-21-2009 09:15 AM
Finding the file size harrylmh Programming 8 04-29-2006 03:59 PM
Finding File Size cmfarley19 Linux - General 1 01-24-2005 08:36 AM
Finding files via their size ivanatora Linux - General 1 09-08-2004 08:23 AM
Finding size of a directory chrisk5527 Linux - General 2 12-30-2003 08:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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