Bash: How to move files and directories from one directory to another?

I'm trying to write a script that moves files and (sub)directories from within one directory to another. That move operation should include not only regular files and directories but also any dot-files. So far I've come up with this:

mv -f "$SOURCE_DIR"/.?? "$TARGET_DIR"
mv -f "$SOURCE_DIR"/.??* "$TARGET_DIR"
mv -f "$SOURCE_DIR"/* "$TARGET_DIR"

But these commands fail if there are no files matching the patterns.

I need this move operation to succeed in any case ..

  • regardless of the file name
  • regardless if there are no files at all
  • regardless of the type: file, link, directory, etc.

But I need the operation to fail if something goes wrong completely (e.g. insufficient privileges at the target directory, etc.) so just ignoring any errors is not a good option.

How to I solve this problem? I guess there is a very simple solution to that which I overlooked.

Thank you for your help!


Solution 1:

You are probably making this harder than you need to.

mv $srcdir $destdir