Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-22-2009, 07:56 PM   #1
LQ Newbie
Registered: Dec 2009
Posts: 2

Rep: Reputation: 0
Question show how much diskspace do certain files use

I have a single file we'll call "SRC"

this "SRC" file contains a long list of files on "server A" that I need to copy to "server B".

I don't have much space left on "server B".

SO, I need to know how much disk space these files are using.

the format of the "SRC" file is....


Please advise on how this can be done either through a simple cmd or script.

Old 12-22-2009, 08:10 PM   #2
Senior Member
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
use du command to know each file size ...

for example you want to know size of a folder and its subfolders
$du foldername
see my example
raju@Raju:~> du Documents
304     Documents/Alea2-1-distribution/src/xklusac/environment
108     Documents/Alea2-1-distribution/src/xklusac/extensions
416     Documents/Alea2-1-distribution/src/xklusac
420     Documents/Alea2-1-distribution/src
4       Documents/Alea2-1-distribution/graphs
12      Documents/Alea2-1-distribution/nbproject/private/profiler
24      Documents/Alea2-1-distribution/nbproject/private
84      Documents/Alea2-1-distribution/nbproject
2452    Documents/Alea2-1-distribution/data-set
3576    Documents/Alea2-1-distribution
1592    Documents/Printouts
264     Documents/Themes/revolution_kdm_theme
176     Documents/Themes/SweetDarkness/logos
652     Documents/Themes/SweetDarkness
8456    Documents/Themes
26800   Documents
You can see that .. output is giving size of every folder.

If you want to know size of a single file
$du filename
see my example
raju@Raju:~/Documents> du His*
24      HistoryManager2.1.oxt
Old 12-22-2009, 08:27 PM   #3
Senior Member
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,672
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
If you are just going to replicate the file tree in whole and need only the total size in bytes:
(cat SRC|while read f;do du -B1 "$f";done|awk '{t+=$1;}END{print t;}')
If you need the size in K (1024) bytes:
(cat SRC|while read f;do du -B1024 "$f";done|awk '{t+=$1;}END{print t;}')
These commands will run a bit slow. Give them time. And they will have a slight under-estimate because they do NOT count the space needed for directories. And don't try to do megabytes this way, since it will round up small files way more than their actual block allocation.

Note that these sizes will reflect allocated sizes. If any files are "sparse" (that means any blocks of all bits being zero is just not allocated), the actual allocated size will be small, and a copy operation without a sparse option enabled would make the new files larger. If you are doing the copy with the "cp" command then you should use the "--sparse=always" option.

How are you planning to do the file copying?
Old 12-22-2009, 08:42 PM   #4
Senior Member
Registered: Jul 2008
Location: /dev/null
Posts: 1,173
Blog Entries: 12

Rep: Reputation: 129Reputation: 129
You may want to search for a tool called "ncdu"
Old 12-23-2009, 12:41 AM   #5
LQ Newbie
Registered: Dec 2009
Posts: 2

Original Poster
Rep: Reputation: 0
I was going to use this script to copy the files listed in the SRC file.


for file in `more SRC`

echo $file

cp -Rp /src/dir/$file /dest/dir/

I'm open to better ways of copying.

one other thing, you said it will take a while. this SRC file has just over 43,000 files listed. it will be reading from the nfs, so that shouldn't be too bad.....right?

i jsut want to make sure I have enough room before I start copying all these files in the SRC list over.



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
ntfs hard drive mounted. but doesnt show all files , tar files ataomega Linux - Software 1 08-28-2009 01:47 PM
Missing Diskspace? Casper36410 Linux - General 2 11-14-2007 07:21 PM
OMFG, where is that diskspace going to .. Manu-M *BSD 4 09-03-2004 05:47 PM
diskspace.... yenonn Slackware 5 03-19-2004 08:39 PM
how to check diskspace nbtaher Linux - General 1 05-16-2002 07:42 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration