1

I am reading a book "Linux Command Line",
there's -u update option for command mv and `cp'

-u, --update When moving files from one directory to another, only move files that either don't exist, or are newer than the existing corresponding files in the destination directory.

The option is not included in BSD 'mv' command.

What's the alternative options for --update?

2

You can use rsync instead of mv combining these two options:

-u, --update                skip files that are newer on the receiver
--remove-source-files       sender removes synchronized files (non-dir)
  • What' does r stand for? I didn't find an answer in wikipedia and quora. – JawSaw Mar 28 '18 at 9:59
  • In man page: -r, --recursive recurse into directories – Yurij Goncharuk Mar 28 '18 at 10:18
  • I got it, r in 'rsync' is for 'remote'. ty. – JawSaw Mar 28 '18 at 10:19
  • 1
    Right. I hurried and not think about r whithout -. Sorry. – Yurij Goncharuk Mar 28 '18 at 10:24
2

The BSD alternative would be

[ "$target" -nt "$source" ] || mv "$source" "$target"

This performs the mv if $target does not exist, or if it's not newer than $source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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