How is to update in cp -u to really work in saving file save/copy work

just copied to /tmp/onram/cpp and only moddded gainRun.sh

$ ls -l
drwxrwxrwx 2 root root 80 Oct  7 07:02 /tmp/onram/cpp
total 8
-rwxrwxrwx 1 root root 116 Oct  7 07:02 gainRun.sh
-rwxrwxrwx 1 root root 175 Oct  7 07:01 m.c

peek the source before copy back by -u opt.

$ ls -l ~/Downloads/c
drwxrwxrwx 2 root root 4096 Oct  6 09:28 /home/bot/Downloads/c
total 8
-rwxrwxrwx 1 root root 108 Oct  6 09:11 gainRun.sh
-rwxrwxrwx 1 root root 175 Oct  6 09:11 m.c

so time to test go copy it

$ cp -ru /tmp/onram/cpp/*  ~/Downloads/c

'/tmp/opera-beta/cpp/gainRun.sh' -> '/home/bot/Downloads/c/gainRun.sh'
'/tmp/onram/cpp/m.c' -> '/home/bot/Downloads/c/m.c'

just copy indiscriminately all, not only just modded gainRun.sh

please help complete correct steps to saving file save/copy work if it wasn't done so

  • 1
    You may want to get out of the habit of doing such experimentation as the root user.
    – DopeGhoti
    Oct 7, 2022 at 2:32

1 Answer 1


cp -u - copies files based on last modification time of the origin file/s.

cp -ur - Does the same as above but includes content found in subdirectories.

Image showing before:

Image showing timestamps before modifying files

And this next image shows the result afterwards (note the time difference for the two files I modified before copying)

Image showing result of cp -u

Notice that only the modified files' timestamp changes indicating the command works just file.

I hope that helps.

You must log in to answer this question.