Sponsored Content
Full Discussion: size of a directory
Top Forums Programming size of a directory Post 57020 by AbEnd on Friday 15th of October 2004 03:18:47 PM
Old 10-15-2004
Quote:
Originally posted by Driver
> This definitively is I/O bound.

Irrelevant. Invoking an external program adds the time needed to create a process, execute the du program, communicate back the results and destroy the process. Whether this is going to be a problem or not depends on the application; And a portable directory traverser, once written, will compile even using only, say, DOS/Windows libraries - with minimal changes (many libraries provide the exact same functions prefixed with a ``_'' character, and/or declared in a header called direct.h instead of dirent.h)
If you mean that there is a portability issue with du, I agree with that. But spawning the sub-process will take almost no time compared to reading the directories. The overhead will never be noticeable.

Quote:
> And now that I think about it... du/fts will probably be optimized to
> run much faster than whatever could be coded trivially... Heh, what
> overhead? Not to mention du/fts will probably get right the
> traversing of the hierarchy while it is being modified. Modularity.

In think that you are dreaming this up in order to support your assertion that ``du'' is a superior solution Smilie If you can explain how a program can ``get right the traversing of the hierarchy while it is being modified'' (and what you actually mean by that), I'm all ears. As to whether it will be ``optimized to run much faster'', well, there's not a lot of room for any relevant differences. In part because it is ``I/O bound'', as you said earlier.
1) AFAIK, it keeps opened FDs to the parent directories as it does the traversal. If some directories are moved, it will always use the right parent dir. There might be other stuff they did in fts as IIRC, there were security issues related with that as rm -r, chmod -R, find, etc, are often using fts and could be used as root on user files (ex, what happens if root does rm -rf ~user/stuff and user moves ~/stuff/a/b/c to /tmp while rm is traversing it? if using chdir ".." without checking if the parent dir is the same, it could end up traversing files starting at /. If not using "..", it will not traverse all the files in ~user/stuff because the path have changed. Keeping the open'd FD requires keeping them in dynamic data structures and this is a waste of time to code again).

2) ... Dude... It Is BECAUSE this is I/O bound that adding some CPU overhead to reduce the I/O will give a faster results. You see for yourself; they have a lot of code in that library and this is prolly not to make things slower (although a lot of it could be for security): http://www.freebsd.org/cgi/cvsweb.cg...libc/gen/fts.c
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Size of a directory

Hi, It would be of great help if anyone can tell me what is the command for getting the size of a directory. Thx a lot in advance Minaz (9 Replies)
Discussion started by: minazk
9 Replies

2. UNIX for Dummies Questions & Answers

size of a directory?

hi, say i have the following directory structure a/b/c/d... can i do df -kt /a/b/c/d and the output will gives me the total space of the directory space in d? or the output will just be the total space of the parent directory a. hope its clear.. (2 Replies)
Discussion started by: yls177
2 Replies

3. AIX

size of directory with ls -l

hello When i do a "ls -l" in a directory (Aix 5.3), i have the result : >ls -l total 65635864 -rw-r--r-- 1 lobi system 2559909888 Feb 20 15:06 cible5.7bdat -rw-r--r-- 1 lobi system 1020098870 Feb 20 13:06 cible6.7bdat -rw-r--r-- 1 lobi system 1544789511 Feb 20 11:06 cible9.7bdat -rw-r--r--... (2 Replies)
Discussion started by: pascalbout
2 Replies

4. UNIX for Dummies Questions & Answers

directory size with ls -l

am I right in assuming that in unix a directory size is just information about that directory stored somewhere on the file system, and not a sum of its contents? This is because ls -l gives 1024 as my directory size, when the directory contains many gigs worth of stuff. also, is du -sk dir ... (2 Replies)
Discussion started by: JamesByars
2 Replies

5. Shell Programming and Scripting

size of directory

Hello again; I have a directories and subdirectories in my current directory and i wanna to find the directories( and subdirectories ) which are larger than what user enters as first parameter. find . -type d -size +"$1"c -print > directories.dat I used this command and i am not sure it is... (19 Replies)
Discussion started by: redbeard_06
19 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. UNIX for Dummies Questions & Answers

directory tree with directory size

find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' Can someone explain how this works..?? How can i add directory size to be listed in the above command's output..?? (1 Reply)
Discussion started by: vikram3.r
1 Replies

8. Solaris

get directory size

Hi, How to get size of particular directory? Thanks (5 Replies)
Discussion started by: cutefriend
5 Replies

9. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

10. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies
DPNS_GETCWD(3)						      DPNS Library Functions						    DPNS_GETCWD(3)

NAME
dpns_getcwd - get DPNS current directory used by the name server SYNOPSIS
#include <sys/types.h> #include "dpns_api.h" char *dpns_getcwd (char *buf, int size) DESCRIPTION
dpns_getcwd gets the DPNS current directory used by the name server. This current working directory is stored in a thread-safe variable in the client. If buf is not NULL, the current directory name will be stored there. If buf is NULL, dpns_getcwd allocates a buffer of size bytes using malloc. size must be at least the length of the directory name to be returned plus one byte. RETURN VALUE
This routine returns buf if the operation was successful or NULL if the operation failed. In the latter case, serrno is set appropriately. ERRORS
ENOENT The current directory has not been set yet or does not exist anymore. ENOMEM buf is a NULL pointer and memory could not be allocated. EINVAL size is less than or equal to zero. ERANGE size is greater than 0 and less than size of current directory name plus 1. SENOSHOST Host unknown. SENOSSERV Service unknown. SECOMERR Communication error. ENSNACT Name server is not running or is being shutdown. SEE ALSO
dpns_chdir(3) AUTHOR
LCG Grid Deployment Team DPNS
$Date: 2001/10/04 12:12:44 $ DPNS_GETCWD(3)
All times are GMT -4. The time now is 12:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy