How can I move files up a directory where there might be hundreds or thousands of files in the directory, and you might not be sure about whether there are dupes in ... What method would you use?

How to handle dupes will vary, sometimes we'll overwrite, sometimes we need to be safer. IO can be important because these are production servers. But given quantity a prompt for non duplicate files isn't an option. Preservation of permissions, and timestamps, etc, is important. We usually won't know what the data is.

Oh and it using mv isn't required, rsync, cp solutions welcome.

note: we're running CentOS 5.5 so let me know if it won't work there due to it being a more recent... feature

@Iain depends on the situation? I work at a webhost... it really depends on the mv and whether we care about preservation in the case of... and whether we've already made a backup. This question is fairly open. I'm just looking for good options, and maybe a comment about whether or not it can bite you and how.
–
xenoterracide♦Dec 17 '10 at 15:54

@Tok is it possible to do the copy's as hardlinks? so as not to waste IO. (like -l for cp)
–
xenoterracide♦Dec 18 '10 at 12:13

@xenoterracide - You can use the -H or --hard-links flags for rsync to preserve hard links.
–
TokDec 20 '10 at 14:14

1

@xenoterracide - You can use the --link-dest=DIR flag to achieve this behavior as: rsync -avP --link-dest=/path/to/src /path/to/src/* /path/to/dest/ which will hard link into dst/ any unchanged files between src and src, in this case all files. Ordinarily you see this flag used when you wish to re-link backup files without copying their data such as --link-dest=/most/recent/backup.
–
TokDec 20 '10 at 14:46

@xenoterracide - Habit and portability (it's a GNU extension). On top of that I've just tried it and can't figure out how to pass the second parameter .. to the mv '{}' + command as the + just adds to the end.
–
IainDec 17 '10 at 16:31

yes n | mv -i … moves all files that don't exist in the destination directory. On FreeBSD and OSX, you can shorten this to mv -n ….

Note that neither of these will merge a directory argument with an existing directory in the same name in the destination directory.

A separate issue is how to act on all the files in the current directory. There are two problems: grabbing all files (* omits dot files) and not running into a command line . On Linux (or more generally with GNU find and GNU coreutils):

As usual zsh makes things easier. It doesn't have a command line length limitation internally, so if you use its mv builtin you don't need to worry about that. And you can tell it not to ignore dot files with the D glob qualifier. Limitation: this doesn't work across filesystems (as of zsh 4.3.10).