Install
cp vs install
- software installation - How is install different from cp? - Unix & Linux Stack Exchange
- software installation - Why use install rather than cp and mkdir? - Unix & Linux Stack Exchange
cp 명령 대신 install 명령을 사용하는 이유는 다음과 같다:
- Install copies files with the default mode 755.
- Install can be configured to set the owner or group of a file and/or the mode of a file.
- Install can be configured to backup the original file before it is replaced.
- dd is a low level copy tool that is mostly used to copy exactly sized blocks of the source which could be for example a file or a device.
- cp is the common command to copy files and directories also recursively with the option -r and by preserving the permissions with the option -p.
- install is mostly similar to cp but provides additionally the option to set the destination file properties directly without having to use chmod separately.
- The install command is normally used in installation scripts that come with packages and source code for installing a binary to your system. It can also be used to install any other file or directory. In addition to the -d and -c options you have -m for specifying the new permissions of the file to be installed, so you don't have to do a cp and a chmod to get the same result. For instance:
install -m644 "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname"
- You also have options -g and -o for setting the target group and owner, respectively. This avoids separate calls to chown. In general, using install shortens your script and makes it more concise by doing file creation, copying, mode setting and related stuff in one command instead of many.