Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I took a backup of a directory which has a number directories and files inside them. Recently some files have gone missing. I would like to just move over the missing files.

I prefer moving files instead of just copying as space is a premium on this particular box and the files are quite large.

How can i achieve this without a GUI and on the command line?

share|improve this question
How was the backup made and where is it relative to where the files need to be? – Dennis Williamson May 5 '10 at 5:47
@Dennis Just in another folder on the same drive. I took a straight copy of the directory for safe keeping. – JavaRocky May 5 '10 at 8:00
up vote 1 down vote accepted

The quick and dirty way is to us the mv (move) command with the -n or --no-clobber option.

From the mv man page:

   -n, --no-clobber
          do not overwrite an existing file


You two directories:



if /files is the original directory that is missing the files and the /backup directory is your most current backup, the command would be:

mv -n /backup/* /files

If your version of Linux/Unix does not support the -n option you can do the same thing with the -i option, except it will ask if you want to overwrite the existing file. You will need to answer no each file. It will not ask you if the file does not exist in the destination directory.

From the mv man page:

   -i, --interactive
          prompt before overwrite

i.e. mv -i /backup/* /files

Be careful.


share|improve this answer
This would not be recursive. – Dennis Williamson May 5 '10 at 8:38

Personally, I find myself using rsync quite often for this kind of thing. Read the man page. There are a lot of options and it can be a lot to learn, but in the long run, I think that it will be worth it. The best part is that it is free and found already installed on most Linux systems.

Amongst rsync's options include updating only the files that have changed since the last update, ability to filter certain files and directories, you can do a dry-run first, and many many other features. Notably, rsync can copy not only between files on the host system, but even over a network. So, however you have backed up your files, it should work. A quick look at the man page seems that the --remove-source-files option would be similar to moving the files. You may even find that you like it enough to use it to do your backup next time.

share|improve this answer

Do a folder comparison using the trial version of Beyond Compare, then move the files right in there. Easy.

share|improve this answer

Similar to the answer from JimT:

cd /backupdir
for file in `find . -type f`
  yes no | mv -i $file /origdir/`dirname $file`

where "/backupdir" is your backup directory and "/origdir" your original source dir.

The "yes" command is very useful for handling interactive commands. In this case it automatically answers "no" to the prompt when asked to overwrite existing files, so only the files that are missing will be moved.

share|improve this answer
for...find fails if there are spaces in filenames. Use find ... | while read instead. Also, for large numbers of files in the source, this is likely to be quite slow. – Dennis Williamson May 5 '10 at 8:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.