0

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?

2
  • How was the backup made and where is it relative to where the files need to be? May 5, 2010 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, 2010 at 8:00

4 Answers 4

1

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

Example:

You two directories:

/files/

/backup/

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.

JimT

1
2

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.

0

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

0

Similar to the answer from JimT:

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

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.

1
  • 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. May 5, 2010 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .