File: copy-if-change

package info (click to toggle)
r-base 3.1.1-1%2Bdeb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 85,436 kB
  • ctags: 35,389
  • sloc: ansic: 306,779; fortran: 91,908; sh: 11,216; makefile: 5,311; yacc: 4,994; tcl: 4,562; objc: 746; perl: 655; asm: 553; java: 31; sed: 6
file content (12 lines) | stat: -rw-r--r-- 247 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
# Like cp $1 $2, but if the files are the same, do NOTHING.
# Status is 0 if $2 is changed, 1 otherwise.

if test -r "$2"; then
  if cmp "$1" "$2" > /dev/null; then
    echo "$2" is unchanged
  else
    cp -f "$1" "$2"
  fi
else
  cp "$1" "$2"
fi