Linux Command Reference ยท Files and Directories
Linux install command
Reference for the Linux install command: copy files while setting mode, owner and group, create directories with -d, and replace files safely.
install copies files and sets their permissions (and optionally owner and group) in a single step. It is the command behind make install in most build systems, and it is just as useful in your own deploy scripts: instead of cp, chmod and chown, you write one line.
Unlike cp, install is careful about the destination. When it replaces an existing file, it first removes it and writes a new one, so a running program that has the old file open keeps working with the old content instead of seeing it change underneath.
install [OPTION]... SOURCE... DEST
install -d [OPTION]... DIRECTORY...
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
install [-bCDdpsv] [-m MODE] [-o OWNER] [-g GROUP] [-t DIR] SOURCE... DEST
| Option | Description |
|---|---|
-m MODE |
Set the permissions (octal or symbolic). The default is 755, not the source's mode. |
-o OWNER, -g GROUP |
Set owner and group. Changing them normally needs root. |
-d, --directory |
Treat all arguments as directory names and create them, with parents. |
-D |
Create all missing leading directories of the destination. |
-t DIR |
Copy all sources into DIR (target first, handy with xargs). |
-b, --backup[=CONTROL] |
Make a backup of an existing destination (numbered, simple, existing, none). |
-C, --compare |
Do nothing if the destination is already identical, including mode. |
-p |
Preserve modification time of the source. |
-s, --strip |
Run strip on the copied binary. |
-v, --verbose |
Print each action. |
Returns: 0 if everything was installed; non-zero if any item failed.
Usage notes
- The default mode is 755. A data file installed without
-mbecomes executable. Give data files-m 644(or600for secrets). - Mode applies at creation.
install -m 600never exposes the file with looser permissions, unlikecpfollowed bychmod, which leaves a short window. - Not recursive:
installdoes not copy directory trees. Combine it withfindor usecp -rfollowed by explicit permission fixes. - Setting an owner needs privileges. Without root,
-oand-gfail with "Operation not permitted" unless they name you and your groups. - Replacing a running binary works with
installbut can fail with "Text file busy" when youcpover it. -dis a goodmkdir -pwhen you want a mode and ownership at the same time:install -d -m 755 -o app -g app /srv/app.-Cis useful in provisioning scripts that run often, because unchanged files keep their timestamps and do not trigger service restarts.- Source and destination on different file systems are fine;
installcopies the bytes.
Related
cp,mkdir,mv,stat- Lessons: Copy, move and remove, File permissions