robust total size of a list of files
Hi,
There are different methods but what is the most robust method to make the total size of the files and/or directories from a list of files (`ls -1 `)? Code:
ls -1 | while read -r each ; do thanks |
du also shows total count of file sizes
check "-c" parameters in du man pages. |
Quote:
requirement of this exercise? |
For a list of files, I'd use
Code:
stat -c '%s' FILE(s).. | awk '{ s=s+$1 } END { printf("%.0f\n", s) }' Code:
find DIR(S).. -type f -printf '%s\n' | awk '{ s=s+$1 } END { printf("%.0f\n", s) Remember that du lists disk usage, not file sizes. |
@Nominal
du lists disk usage, but by whom?? ofcourse a file.. everything is file in linux. than what is the difference between size listed by du for a file and file size showing using stat command ? |
Quote:
Code:
dd if=/dev/zero of=example-file bs=1 count=1 seek=1048574 So, even though ls -l example-file outputs Code:
-rw-rw-r-- 1 nominal animal 1048575 May 10 14:43 example-file Code:
1048575 Code:
4.0K example-file Directories also consume disk space. The amount depends on the number of entries, the length of the file and directory names in it, and the number of POSIX and extended attributes used. If the du command you run includes the directories, the result will reflect the actual disk space used, and will be significantly different to the total size of the relevant files. You cannot even say which one (disk usage or total file size) is greater, unless you check! |
Quote:
will not be reported outside the loop. |
Quote:
|
What about?
cat * | wc -c well typically to compare directories I do Code:
cat A/* | cksum a) lazy b) a guru c) lateral thinking not sure which |
Quote:
Code:
du -b --apparent-size ... DIRECTORY ... |
Quote:
Quote:
|
Quote:
Directory size is almost always an integral number of disk allocation blocks, making it useless for detecting e.g. additions or removals. (Note: Symlink size is almost always the length of the symlink target path.) Directories cannot be hardlinked, only files can. (You can, however, bind-mount directories and files over other directories and files, so only the "top one" is accessible.) Execute right to a directory allows you to stat() the directory and any file you know the name of in that directory. (Without read rights, you cannot scan the directory, so I guess read and write rights are analogous between files and directories.) For mount points, /path/to/directory and /path/to/directory/. have different device and inode numbers. |
thank you so so so much !!!!!
I like the --apparent-size way and too the find frmo unspawn |
All times are GMT -5. The time now is 01:56 PM. |