LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Finding a file size (https://www.linuxquestions.org/questions/linux-newbie-8/finding-a-file-size-774030/)

LneWlf 12-07-2009 01:47 PM

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

lugoteehalt 12-07-2009 02:06 PM

Not obvious why not just something like:
Code:

$ ls -lh filename.html > summaryFile.txt

colucix 12-07-2009 02:12 PM

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.

Web31337 12-07-2009 02:18 PM

not obvious why use ls (o_0) instead of stat:
Code:

stat -c %s file.html > size.txt
uh?

lugoteehalt 12-07-2009 02:30 PM

Oh dear.:)

ghostdog74 12-07-2009 05:52 PM

Quote:

Originally Posted by LneWlf (Post 3783033)
(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}'

colucix 12-07-2009 06:06 PM

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"


All times are GMT -5. The time now is 05:07 PM.