Basically, the install will be used in the makefile, and the CP command will be used elsewhere.
They accomplish the same task-copying files, the differences between them are mainly as follows:
1, the most important point, if the target file exists, CP will first empty the file to write a new file, and install will delete the original file and then write a new file. This is because writing to a file that is in use can cause problems, such as writing to an executing file that might fail, such as writing a new file to a file handle that has been continuously written to produce the wrong file. The installation can be avoided by using install to delete and then write (generate a new file handle).
2. The install command will properly handle the issue of file permissions. For example, INSTALL-C will set the permissions of the target file to Rwxr-xr-x;
3, the Install command can print more appropriate debug information, but also automatically handle the SELinux context problem.
------------------------------------Split Line------------------------------------
At that time, when compiling LFS 6, I couldn't understand the difference between the command of install and CP and chmod, CHGRP.
After work to understand a running process can not casually carry out CP, often will prompt "text busy", Operations and maintenance Department of the predecessors to the recommendation is to use MV to replace CP, today looks like the predecessor did not know install this command AH.
Let's take a brief look at the install command.
The install Copy file list and the ability to set the properties of the file (including owner, group), usually used in makefiles to copy the program to the specified directory.
The
Common usage is in the following 3 forms:
1: install -D [option] Directory [directory ...] support multiple. Similar to mkdir-p supports recursion.
For example: install-d a/b/c e/f results and mkdir-p a/b/c F. &n Bsp
2:install [option] SOURCE dest
Copy source file (test cannot be a directory) to DEST file.
& nbsp;install a/e c results similar to cp a/e c # Note C must be a file.
Useful options-D
install-d x a/b/c # effects similar to mkdir-p a/b && cp x a/b/c
3:install [OPTION]&N Bsp Source [Source ...] Directory
Copy multiple source files to the destination directory.
install a/* d where D is the directory.
Useful options
-B: Automatic backup.
-M: Set permissions for installation files
-P: Retains the timestamps of the file. This means that the file's timestaamps is the same as the source file. When we want to use the mtime of the installation file to track the build time of the file instead of the installation time.
-s:strip the symbol tables from installed binary executables.
-S: The suffix of the backup file.
Install-s. bak new old #old file is automatically old.bak by MV.
-v:verbose, print the details of the install file.
'-C '
ignored; For compatibility with the old Unix versions of ' Install '. #用来兼容旧版的unix.
-C: (uppercase)
Install the file, but if the destination file is the same as the source file (judging the method needs to look at the code confirmation), the advantage is that you can keep the mtime of the same file.
The difference between the install command and the CP command