install
Overview
install copies files with explicit mode/owner and optional directory creation. Preferred in Makefiles and packaging over cp + chmod + mkdir -p sequences.
Syntax
install [options] SOURCE DEST
install [options] SOURCE... DIRECTORY
install -d [options] DIRECTORY...Common Options
| Option | Description |
|---|---|
-d |
Create directories |
-m MODE |
Set permission mode (e.g. 755) |
-o owner -g group |
Set ownership (requires rights) |
-t DIR |
Target directory |
-D |
Create leading dirs for DEST |
-b / -S |
Backup existing DEST |
-v |
Verbose |
Key Use Cases
- Install binaries to /usr/local/bin
- Place config with correct mode
- Create directory trees with mode
- Reproducible packaging steps
Examples with Explanations
Install a script
sudo install -m 755 bin/tool /usr/local/bin/toolAtomic-ish copy with mode in one step.
Create a system directory
sudo install -d -m 755 /etc/myappDirectory with known permissions.
Config with ownership
sudo install -m 640 -o root -g adm myapp.conf /etc/myapp/myapp.confDrop privileges correctly for group-readable config.
Leading path create
install -D -m 644 share/app.desktop ~/.local/share/applications/app.desktop-D makes parent dirs as needed.