[PLUG] Moving Files

Karl M. Hegbloom karlheg at hegbloom.net
Thu Aug 22 08:00:19 UTC 2002


Richard Steffens <rsteff at attbi.com> writes:

> I understand that using mv to move a file from one directory to
> another doesn't actually move the contents of the file, but just
> changes the information about where that file is stored.

Sure, it does not move the file's data or change it's inode (look that
up), it only changes or moves that directory entry for that inode.

> If mv doesn't actually move files from one place to another, what
> tool do I use to put the files I accidentally stored on the 8 GB
> drive onto the 40 GB drive? Would I use cp to move them to the 40 GB
> drive and then delete them from the 8 GB drive? Or is there a better
> way?

One way of answering this question for your self would be to RTFS
"mv", which is in the "fileutils" package.  (If you are running a
Debian GNU system you can use "apt-get source mv" to grab it really
quick.)  You might also check the man page to rename(2) (say "man 2
rename" to read it, provide you've got the devel man pages installed),
the system call that actually renames a file.

What you will discover is that "mv" will check and see if the two
files are on the same device or not.  If so, it will use "rename(2)",
and if not, it will copy the file then remove it from the old
location.  Most people use "cp" or "tar" for this sort of task though,
since it's a little safer.  You'll know it's copied for sure before
you remove the old copy of the file from the other disc.  Every now
and then cross device "mv" will lose a file for one reason or another.

Though "cp -a" will work fine, preserving hard links, ownership and
permissions, it is generally much faster to use "tar" to copy large
numbers of files from one spindle to another.  The general formula
is... ("#" means root prompt, "%" means user prompt)

# (cd /source && tar cpf - .) | (cd /dest && tar xpf -)

Please RTFM "tar" (say "info tar") to find out what those switches do.
The reason this is faster, especially when you are copying files from
one device to another, is that now there are two processes running, a
reader and a writer, each on a separate spindle.  With "cp -a",
there's only one process doing both the reading and the writing, so
there is less parallelism.

You can speed up the copy a little more, especially when the two
devices do not operate with the same sustained data throughput speed,
by using a program like "buffer" (apt-get install buffer) in the
pipeline, like:

# (cd /source && tar cpf - .) | buffer | (cd /dest && tar xpf -)

You can also copy files from one machine to another by piping the tar
(tape archive) through a secure shell pipe, like this:

% ssh -e none root at datahost 'cd /source && tar cpf - .' | (cd /dest && tar xpf -)

 Question!  Does anyone who has studied queueing theory (isn't that
            what I need to learn to know this answer?) know where the
            "buffer" belongs in that pipeline for optimal throughput?
            Please discuss.

To copy an entire host to a tarfile, I use this (and got PAID to
develop it):

"make-tarball"
8<------------------------------------------------------------>8
#!/bin/bash
find / -print0 |
 grep --invert-match --extended-regexp --null-data --file=/root/make-tarball.exclude-patterns |
 tar --null --files-from=/dev/stdin --no-recursion -cpf -
8<------------------------------------------------------------>8

"make-tarball.exclude-patterns"
8<------------------------------------------------------------>8
^/proc/.*
^/dev/.*
^/tmp/.*
^/mnt/target/.*
^/target/.*
^/lost+found
^/boot/lost+found
^/var/cache/apache/.*
^/var/cache/apt/.*\.deb
^/var/log/.*\.log
^/var/log/\(amanda\|apache\|gdm\|ksymoops\|mailman\|news\|named\|bind\|sendfile\|wu-ftpd\)/.*
^/var/log/\(syslog\|smb\|nmb\|messages\|mail\|lpr\|debug\|dmesg\).*
^/var/lock/\.LCK.*
^/var/run/.*\.pid
^/var/run/\(ndc\|utmp\)
^/var/samba/.*
\.bash_history
\.gnome-errors
.*~
/\.saves-.*
/\.#.*
/\.netscape/cache/.*
8<------------------------------------------------------------>8

-- 
As any limb well and duly exercised, grows stronger,
the nerves of the body are corroborated thereby. --I. Watts.  .''`.
 Debian -- The blue collar Linux distribution.               : :' :
 <URL:http://www.debian.org/social_contract>		     `. `'




More information about the PLUG mailing list