Re: Size of a directory



David Bolt wrote:
On Sat, 26 May 2007, John Bowling wrote:-

Henk Oegema wrote:
Is there a command to find the size of all files (together) in a directory ?

The responses so far have all been using command line methods.

That's probably because that was what was asked for. Or did Henk really
mean what mouse clicks do I need to use when he asked "Is there a
command..." ?

In Kde, using Konqueror, right click on the directory and it will show
the total size in both MB and bytes.

Well, if you select "Properties" from the pop-up menu it will.

For a lot of things manipulating directories I use Kde. There are
problems moving directories with command lines (probably because I never
looked up the options to do it right)

Most likely. It's not that hard to use "man mv" or "mv --help" .

- mv will not create new
directories at the new location by default.

It won't? It will here.

<snippet>
davjam@playing:~> ls -lR mnt
mnt:
total 11876
-rw-r--r-- 1 davjam users 382981 2003-10-16 06:47 fron_msa.zip
-rw-r--r-- 1 davjam users 384960 2003-10-16 06:47 fron_st.zip
-rw-r--r-- 1 davjam users 380328 2003-10-16 06:47 frontier.zip
-rw-r----- 1 davjam users 24973 2003-10-16 06:47 list.txt
drwxr-xr-x 2 davjam users 4096 2003-10-16 06:47 samba
drwxr-xr-x 2 davjam users 4096 2007-05-26 21:32 tags4-1.0.0
-rw-r----- 1 davjam users 3585775 2003-10-16 06:48 tar-1.tar.gz
-rw-r----- 1 davjam users 513287 2003-10-16 06:48 tar-2.tar.gz
-rw-r----- 1 davjam users 1683989 2003-10-16 06:48 tar-3.tar.gz
-rw-r----- 1 davjam users 5140322 2003-10-16 06:48 tar-4.tar.gz
drwxr-xr-x 2 davjam users 4096 2007-05-26 21:33 text

mnt/samba:
total 0

mnt/tags4-1.0.0:
total 88
-rwxr--r-- 1 davjam users 888 2007-05-26 21:32 each_file.c
-rw-r--r-- 1 davjam users 3176 2007-05-26 21:32 each_file.o
-rwxr--r-- 1 davjam users 714 2007-05-26 21:32 lame_it.c
-rw-r--r-- 1 davjam users 3688 2007-05-26 21:32 lame_it.o
-rwxr--r-- 1 davjam users 311 2007-05-26 21:32 Makefile
-rwxr--r-- 1 davjam users 1525 2007-05-26 21:32 read_tag.c
-rw-r--r-- 1 davjam users 4448 2007-05-26 21:32 read_tag.o
-rwxr--r-- 1 davjam users 312 2007-05-26 21:32 shrink.c
-rw-r--r-- 1 davjam users 1384 2007-05-26 21:32 shrink.o
-rwxr-xr-x 1 davjam users 17899 2007-05-26 21:32 tags4
-rwxr--r-- 1 davjam users 1555 2007-05-26 21:32 tags4.c
-rwxr--r-- 1 davjam users 1939 2007-05-26 21:32 tags4.h
-rw-r--r-- 1 davjam users 5896 2007-05-26 21:32 tags4.o
-rwxr--r-- 1 davjam users 1414 2007-05-26 21:32 upper_case.c
-rw-r--r-- 1 davjam users 6712 2007-05-26 21:32 upper_case.o

mnt/text:
total 0
davjam@playing:~> mv -v mnt/tags4-1.0.0 mnt/text/new_dir
`mnt/tags4-1.0.0' -> `mnt/text/new_dir'
davjam@playing:~> ls -lR mnt
mnt:
total 11872
-rw-r--r-- 1 davjam users 382981 2003-10-16 06:47 fron_msa.zip
-rw-r--r-- 1 davjam users 384960 2003-10-16 06:47 fron_st.zip
-rw-r--r-- 1 davjam users 380328 2003-10-16 06:47 frontier.zip
-rw-r----- 1 davjam users 24973 2003-10-16 06:47 list.txt
drwxr-xr-x 2 davjam users 4096 2003-10-16 06:47 samba
-rw-r----- 1 davjam users 3585775 2003-10-16 06:48 tar-1.tar.gz
-rw-r----- 1 davjam users 513287 2003-10-16 06:48 tar-2.tar.gz
-rw-r----- 1 davjam users 1683989 2003-10-16 06:48 tar-3.tar.gz
-rw-r----- 1 davjam users 5140322 2003-10-16 06:48 tar-4.tar.gz
drwxr-xr-x 3 davjam users 4096 2007-05-26 21:34 text

mnt/samba:
total 0

mnt/text:
total 4
drwxr-xr-x 2 davjam users 4096 2007-05-26 21:32 new_dir

mnt/text/new_dir:
total 88
-rwxr--r-- 1 davjam users 888 2007-05-26 21:32 each_file.c
-rw-r--r-- 1 davjam users 3176 2007-05-26 21:32 each_file.o
-rwxr--r-- 1 davjam users 714 2007-05-26 21:32 lame_it.c
-rw-r--r-- 1 davjam users 3688 2007-05-26 21:32 lame_it.o
-rwxr--r-- 1 davjam users 311 2007-05-26 21:32 Makefile
-rwxr--r-- 1 davjam users 1525 2007-05-26 21:32 read_tag.c
-rw-r--r-- 1 davjam users 4448 2007-05-26 21:32 read_tag.o
-rwxr--r-- 1 davjam users 312 2007-05-26 21:32 shrink.c
-rw-r--r-- 1 davjam users 1384 2007-05-26 21:32 shrink.o
-rwxr-xr-x 1 davjam users 17899 2007-05-26 21:32 tags4
-rwxr--r-- 1 davjam users 1555 2007-05-26 21:32 tags4.c
-rwxr--r-- 1 davjam users 1939 2007-05-26 21:32 tags4.h
-rw-r--r-- 1 davjam users 5896 2007-05-26 21:32 tags4.o
-rwxr--r-- 1 davjam users 1414 2007-05-26 21:32 upper_case.c
-rw-r--r-- 1 davjam users 6712 2007-05-26 21:32 upper_case.o

</snippet>

That's on the same file-system. Here the source directory was simply
renamed. It's slightly different when the source and destination are
different file-systems:

<snippet>
davjam@playing:~> mv -v mnt/tags4-1.0.0 /local1
`mnt/tags4-1.0.0' -> `/local1/tags4-1.0.0'
`mnt/tags4-1.0.0/each_file.c' -> `/local1/tags4-1.0.0/each_file.c'
`mnt/tags4-1.0.0/Makefile' -> `/local1/tags4-1.0.0/Makefile'
`mnt/tags4-1.0.0/tags4.o' -> `/local1/tags4-1.0.0/tags4.o'
`mnt/tags4-1.0.0/each_file.o' -> `/local1/tags4-1.0.0/each_file.o'
`mnt/tags4-1.0.0/lame_it.c' -> `/local1/tags4-1.0.0/lame_it.c'
`mnt/tags4-1.0.0/shrink.o' -> `/local1/tags4-1.0.0/shrink.o'
`mnt/tags4-1.0.0/read_tag.c' -> `/local1/tags4-1.0.0/read_tag.c'
`mnt/tags4-1.0.0/upper_case.o' -> `/local1/tags4-1.0.0/upper_case.o'
`mnt/tags4-1.0.0/shrink.c' -> `/local1/tags4-1.0.0/shrink.c'
`mnt/tags4-1.0.0/read_tag.o' -> `/local1/tags4-1.0.0/read_tag.o'
`mnt/tags4-1.0.0/tags4.c' -> `/local1/tags4-1.0.0/tags4.c'
`mnt/tags4-1.0.0/tags4.h' -> `/local1/tags4-1.0.0/tags4.h'
`mnt/tags4-1.0.0/tags4' -> `/local1/tags4-1.0.0/tags4'
`mnt/tags4-1.0.0/upper_case.c' -> `/local1/tags4-1.0.0/upper_case.c'
`mnt/tags4-1.0.0/lame_it.o' -> `/local1/tags4-1.0.0/lame_it.o'
removed `mnt/tags4-1.0.0/each_file.c'
removed `mnt/tags4-1.0.0/Makefile'
removed `mnt/tags4-1.0.0/tags4.o'
removed `mnt/tags4-1.0.0/each_file.o'
removed `mnt/tags4-1.0.0/lame_it.c'
removed `mnt/tags4-1.0.0/shrink.o'
removed `mnt/tags4-1.0.0/read_tag.c'
removed `mnt/tags4-1.0.0/upper_case.o'
removed `mnt/tags4-1.0.0/shrink.c'
removed `mnt/tags4-1.0.0/read_tag.o'
removed `mnt/tags4-1.0.0/tags4.c'
removed `mnt/tags4-1.0.0/tags4.h'
removed `mnt/tags4-1.0.0/tags4'
removed `mnt/tags4-1.0.0/upper_case.c'
removed `mnt/tags4-1.0.0/lame_it.o'
removed directory: `mnt/tags4-1.0.0'
</snippet>

As you can see, in this situation, mv creates the destination directory,
copies the contents from the source to the destination, then deletes the
files/directories from the source.

rm and rmdir have problems
when there are hundreds of files to delete.

I don't know about rmdir, since I've never used it. I have used rm and,
unless you pass a wildcard ('*' is a good one) in a directory with lots
of files/directories, it manages quite well:

<snippet>
davjam@playing:~> mkdir -p /local1/tags
davjam@playing:~> mv -f /local1/tags4-1.0.0/ /local1/tags/
davjam@playing:~> for i in $(seq 1 1000) ; do cp -r ~/tags4-1.0.0 $(printf "/local1/tags/tags4-1.0.0-%04u" $i) ; done
davjam@playing:~> find /local1/tags | wc -l
16017
davjam@playing:~> rm -rf /local1/tags
davjam@playing:~>
</snippet>

Nope. Handled that easily. How about with a wildcard?

<snippet>
davjam@playing:~> cp -r tags4-1.0.0 /local1/tags
davjam@playing:~> for i in $(seq 1 1000) ; do cp -r ~/tags4-1.0.0 $(printf "/local1/tags/tags4-1.0.0-%04u" $i) ; done
davjam@playing:~> find /local1/tags | wc -l 16016
davjam@playing:~> rm -rf /local1/tags/* davjam@playing:~>
</snippet>

Well that went okay, but then there was only 1014 filenames passed. How
about several thousand more?

<snippet>
davjam@playing:~> cp -r tags4-1.0.0 /local1/tags davjam@playing:~> for i in $(seq 1 5000) ; do cp -r
davjam@playing:~> for i in $(seq 1 5000) ; do cp -r ~/tags4-1.0.0 $(printf "/local1/tags/tags4-1.0.0-%04u" $i) ; done
davjam@playing:~> find /local1/tags | wc -l 80017
davjam@playing:~> rm -rf /local1/tags/* -bash: /bin/rm: Argument list too long
-bash: /bin/rm: Argument list too long
davjam@playing:~>
</snippet>

Ah, now it's failed with 5014 filenames. Okay, lets reduce that a touch
and see what happens:

<snippet>
davjam@playing:~> rm -rf /local1/tags/*[54]???
davjam@playing:~> rm -rf /local1/tags/*
davjam@playing:~>
</snippet>

Well, dropping it down to 3013 filenames got rid of them all without
another error.

And Konqueror does all of
these without blinking.

In the case of mv, I'll disagree with you, but in the case of rm I will
sort of agree. KDE handles the rm a lot easier, but I don't agree that
it "does all of these without blinking."

mv will create the destination directory if what you're moving is a
directory. It won't create any missing directories, so you couldn't use:


Perhaps I wasn't clear enough.
mv Mydir /media/flash/
tells me it cannot create the sub directories existing under Mydir/ at
/media/flash/ and since I don't want to route out a multilayer tree and
manually recreate it somewhere else, I don't bother doing that. And
clicking on the Home icon and going to the top level directory, then
another with the flash drive, I can drag the Mydir to the flash and it
all gets copied, directories duplicated as in the origional.

mv /home/<USER>/source /home/<USER>/missing_dir1/missing_dir2/dest

You can't do that sort of move in KDE either. While, using the
command-line you could use:

mkdir -p /home/<USER>/missing_dir1/missing_dir2

to create the missing directories, then use the mv command, to do the
same in KDE would require opening a window for the destination, creating
the directory missing_dir1, changing into that directory, then create
missing_dir2, then you could drag the source file to destination. And if
you want source to be renamed as dest, you've got to either right-click
and select rename, or highlight it and then press F2.

So, which do you think is going to be the quicker? As a "two-fingered"
typist, I know which one is quicker for me, and it'd not the one that
requires mouse clicks.

Drag and drop is quicker! And I do touch typing at about 40 words a
minute. It's the looking up what's there that takes the time.



Regards,
David Bolt

.



Relevant Pages

  • Re: Size of a directory
    ... The responses so far have all been using command line methods. ... davjam@playing:~> ls -lR mnt ... As you can see, in this situation, mv creates the destination directory, ...
    (alt.os.linux.suse)
  • Re: windows server 2003 COPY command
    ... >Do you know the SYNTAX of the 2003 COPY command? ... >>> files into a single file using the windows server 2003 COPY command. ... Allows the encrypted files being copied to be saved as decrypted files at the destination. ... If you do not specify a destination file, a copy is created with the same name, creation date, and creation time as the original file, placing the new copy in the current directory on the current drive. ...
    (microsoft.public.windows.server.scripting)
  • Re: Copying only changed or new files??
    ... there was a COPY command. ... destination Specifies the location and/or name of new files. ... Specifies a list of files containing strings. ... include empty directories or subdirectories. ...
    (microsoft.public.windowsxp.general)
  • To find wether given entry is a file or directory
    ... In this script i have to check whether the dest_dir is a file or ... I used -d and -f command to check wether it is a directory or file. ... The entry is located on a remote computer. ...
    (comp.unix.shell)
  • ViewMate: Help needed in street identification
    ... I've posted to Viewmate a snippet from a ship's manifest: the destination ...
    (soc.genealogy.jewish)