On Mon, 15 Jan 2001, Tony Mueller wrote:

> Hello,
>
> I would like to rename a large directory without a copy taking place.
> (i dont have disk space for both directories to exist at the same time)
> the command:
> mv olddir newdir
> makes newdir first and copies all the files from olddir into it.
>

Hmm... that should not be. :/ Assuming we're talking about a single
filesystem (otherwise a copy is unavoidable) a mv should be litterally a
call to rename().

bash$ cd /tmp
bash$ mkdir tick
bash$ for i in 1 2 3 4; do touch tick/$i; done
bash$ strace mv tick tock
execve("/bin/mv", ["mv", "tick", "tock"], [/* 39 vars */]) = 0
brk(0)                                  = 0x80531f0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x40014000
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
[... open a bunch of shared lib and locale stuff ...]
geteuid()                               = 500
umask(0)                                = 02
stat("tock", 0xbffff7f0)                = -1 ENOENT (No such file or
directory)
lstat("tick", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("tock", 0xbffff5bc)               = -1 ENOENT (No such file or
directory)
rename("tick", "tock")                  = 0
_exit(0)                                = ?
bash$

... so the entry for "tick" in "/tmp" was renamed to "tock" and the files
"1", "2", "3", "4" never came into play.  So - possibly something else
screwy is going on in your case, worth checking out anyway.

However, it is possible to do a copy and delete that doens't take up any
more disk space. Well, discounting some directory inodes anyway.  If you do
a "cp -l" then instead of actual copies of a file being made you get a hard
link made; that is, two files that point to the same peice the disk.  Once
your link is made you can delete the old one.

First lets make some files to play with that take up some space:

bash$ cd /tmp
bash$ mkdir cp-l
bash$ cd cp-l
bash$ mkdir tick
bash$ for i in 1 2 3 4; do
> dd if=/dev/zero of=tick/$i bs=1k count=$RANDOM
> done
23226+0 records in
23226+0 records out
20622+0 records in
20622+0 records out
9316+0 records in
9316+0 records out
29805+0 records in
29805+0 records out
bash$ ls -l tick
total 83084
-rw-rw-r--    1 matthewm matthewm 23783424 Jan 16 07:45 1
-rw-rw-r--    1 matthewm matthewm 21116928 Jan 16 07:45 2
-rw-rw-r--    1 matthewm matthewm  9539584 Jan 16 07:45 3
-rw-rw-r--    1 matthewm matthewm 30520320 Jan 16 07:45 4
bash$ du -k .
83088   ./tick
83092   .

... okay so /tmp/cp-l takes up about 81M.  Now lets cp tick to be tock...

bash$ $ cp -la tick tock
bash$ ls -l tock
total 83084
-rw-rw-r--    2 matthewm matthewm 23783424 Jan 16 07:45 1
-rw-rw-r--    2 matthewm matthewm 21116928 Jan 16 07:45 2
-rw-rw-r--    2 matthewm matthewm  9539584 Jan 16 07:45 3
-rw-rw-r--    2 matthewm matthewm 30520320 Jan 16 07:45 4
bash$ du -k .
83088   ./tick
4       ./tock
83096   .

Okay.  So now I've got two directories, tick and tock, that contain the same
stuff but don't take up any additional room becuase they refere to the same
on disk data.  Now I can delete the original.

bash$ rm -rf tick
bash$ ls -l tock
total 83084
-rw-rw-r--    1 matthewm matthewm 23783424 Jan 16 07:45 1
-rw-rw-r--    1 matthewm matthewm 21116928 Jan 16 07:45 2
-rw-rw-r--    1 matthewm matthewm  9539584 Jan 16 07:45 3
-rw-rw-r--    1 matthewm matthewm 30520320 Jan 16 07:45 4
bash$ du -k .
83088   ./tock
83092   .
bash$

... and now all I've got is tock, and it takes up the same 81M as tick did
originally.

... as mud? ;)

M.

-- 
WebCentral Pty Ltd           Australia's #1 Internet Web Hosting Company
Level 1, 96 Lytton Road.           Network Operations - Systems Engineer
PO Box 4169, East Brisbane.                       phone: +61 7 3249 2583
Queensland, Australia.                            pgp key id: 0x900E515F



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to