LinuxQuestions.org
Register a domain and help support LQ
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 01-07-2005, 12:58 AM   #1
blackzone
Member
 
Registered: Jul 2004
Posts: 256

Rep: Reputation: 30
finding size of total files in a directory


how do I find the total file size in a directory.

while using "du" it don't do the actual file size.

for example any file over 1 byte will use 4096 bytes of space(becuase of node)?
 
Old 01-07-2005, 01:04 AM   #2
Linux~Powered
Member
 
Registered: Jan 2004
Location: /lost+found
Distribution: Slack`er-current
Posts: 845

Rep: Reputation: 33
Code:
du -ab
Will show the size of the files in bytes and the total size of the directory at the end.
 
Old 01-07-2005, 02:08 AM   #3
blackzone
Member
 
Registered: Jul 2004
Posts: 256

Original Poster
Rep: Reputation: 30
it won't really show file size though

on my system any file less than 4k will use 4k of space. du shows disk usage not file size.

It woult be approximately the same anyway. but is there a way to show total file size in a directory?
 
Old 01-07-2005, 04:01 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
But 4k is how many bytes the file consumes. If the file contains the letter 'A' followed by an EOF, it still consumes 4k on the disk even though the file can be contained in two bytes. I just don't understand why you need to make the distinction aside from an academic perspective. That said, you can use the ls -l command wrapped in a shell script.

Something along the lines of (this is off the top of my head; I make no promises of its quality or that it will even work):
Code:
#!/bin/bash

total_size=0

for file in * ; do
  file_size=$( ls -ld ${file} | awk '{print $5 }' )
  echo "${file_size} ${file}"
  ((total_size=total_size+file_size))
done

echo "------------"
echo "Total size: ${total_size}"
Bear in mind, the script does not:
1. recognize directories as anything other than a regular file (in other words, no recursion)
2. count any hidden files (such as .bash_profile)

You'd need to flesh it out some more to do that, or search for a different tool.
 
  


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
BASH : Total directory size xgreen Programming 7 03-04-2013 06:33 AM
finding total used space by a user in a directory vince_2x Linux - General 1 09-21-2004 07:49 AM
Finding files via their size ivanatora Linux - General 1 09-08-2004 09:23 AM
Finding size of a directory chrisk5527 Linux - General 2 12-30-2003 09:49 AM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 04:47 PM


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