All three options are used to take a backup of the destination file/directory before overwriting it with the source file/directory but the difference is on the name cp command given to the backup file. With -b option the backup file is suffixed with a tilde (~) sign, with –backup[=CONTROL] suffix the backup file as per [CONTROL] value and –suffix=SUFFIX or -s option lets you decide which suffix to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
mkdir mydir1 ## create some files and directory echo "one" > mydir1/myfile1 echo "two" > myfile1 cp --suffix=.bak myfile1 mydir1 ## creates a backup (myfile1.bak) of myfile1 overwriting cp -b myfile1 mydir1 ## creates a backup (myfile1~) of myfile1 overwriting cp --backup=t myfile1 mydir1 ## creates a backup (myfile1.~1~) of myfile1 overwriting tree ## . ## |-- mydir1 ## | |-- myfile1 ## | |-- myfile1.bak => created by cp --suffix ## | |-- myfile1.~1~ => created by cp --backup ## | `-- myfile1~ => created by cp -b ## `-- myfile1 rm -r my* |