LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   show how much diskspace do certain files use (https://www.linuxquestions.org/questions/linux-newbie-8/show-how-much-diskspace-do-certain-files-use-777566/)

thewebshark 12-22-2009 06:56 PM

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....

/path/to/dir1/file1
/path/to/dir1/file2
/path/to/dir2/file3
/path/to/dir3/file4

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

Thanks.

raju.mopidevi 12-22-2009 07:10 PM

use du command to know each file size ...

for example you want to know size of a folder and its subfolders
Code:

$du foldername
see my example
Code:

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
Code:

$du filename
see my example
Code:

raju@Raju:~/Documents> du His*
24      HistoryManager2.1.oxt


Skaperen 12-22-2009 07:27 PM

If you are just going to replicate the file tree in whole and need only the total size in bytes:
Code:

(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:
Code:

(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?

~sHyLoCk~ 12-22-2009 07:42 PM

You may want to search for a tool called "ncdu"

thewebshark 12-22-2009 11:41 PM

I was going to use this script to copy the files listed in the SRC file.

Code:

#/bin/bash

for file in `more SRC`
do

echo $file

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

done

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.

thanks.


All times are GMT -5. The time now is 02:13 PM.