Linux command
install 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Copy file with specific permissions
install -m [755] [source] [dest]
Copy files into a target directory
install -t [/usr/local/bin/] [file1] [file2]
Create directories (including parents)
install -d [/path/to/dir]
Set owner and group
install -o [user] -g [group] [file] [dest]
Copy preserving timestamps
install -p [file] [dest]
Strip binaries during install
install -s [binary] [/usr/local/bin/]
Copy only if source is different (avoids unnecessary writes)
install -C [file] [dest]
Create parent directories then copy
install -D [source] [/path/to/new/dir/dest]
说明
install copies files while setting permissions and ownership. It is primarily used in Makefiles and installation scripts to place files with correct attributes. The tool combines cp, chmod, chown, and mkdir functionality, streamlining installation tasks. It can also strip binaries and back up existing files. The default permission mode is rwxr-xr-x (755).
参数
- -m _mode_, --mode=_mode_
- Set permission mode (as in chmod), instead of the default rwxr-xr-x.
- -o _owner_, --owner=_owner_
- Set ownership (super-user only).
- -g _group_, --group=_group_
- Set group ownership instead of the process's current group.
- -d, --directory
- Treat all arguments as directory names; create all components of the specified directories.
- -D
- Create all leading parent directory components of dest, then copy source to dest.
- -t _DIRECTORY_, --target-directory=_DIRECTORY_
- Copy all source arguments into DIRECTORY.
- -T, --no-target-directory
- Treat dest as a normal file, not a directory.
- -C, --compare
- Compare source and destination; do not modify dest if content, ownership, and permissions are unchanged.
- -s, --strip
- Strip symbol tables from installed binaries.
- --strip-program=_PROGRAM_
- Program used to strip binaries (default: strip).
- -p, --preserve-timestamps
- Apply access/modification times of source files to destination files.
- -b
- Make a backup of each existing destination file.
- --backup=_CONTROL_
- Make a backup of each existing destination file, with optional version control method.
- -S _suffix_, --suffix=_suffix_
- Override the usual backup suffix.
- -v, --verbose
- Print the name of each file or directory as it is created.
- -c
- Ignored; for compatibility with older Unix versions.
- -Z, --context
- Set SELinux security context of destination files to the default type.
FAQ
What is the install command used for?
install copies files while setting permissions and ownership. It is primarily used in Makefiles and installation scripts to place files with correct attributes. The tool combines cp, chmod, chown, and mkdir functionality, streamlining installation tasks. It can also strip binaries and back up existing files. The default permission mode is rwxr-xr-x (755).
How do I run a basic install example?
Run `install -m [755] [source] [dest]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -m _mode_, --mode=_mode_ do in install?
Set permission mode (as in chmod), instead of the default rwxr-xr-x.