Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
install [OPTION]... SOURCE... DEST
install -d [OPTION]... DIRECTORY...

Try it

Bash Copy with a mode

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.

Bash Directories, verbose and backups

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

Terminal
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 -m becomes executable. Give data files -m 644 (or 600 for secrets).
  • Mode applies at creation. install -m 600 never exposes the file with looser permissions, unlike cp followed by chmod, which leaves a short window.
  • Not recursive: install does not copy directory trees. Combine it with find or use cp -r followed by explicit permission fixes.
  • Setting an owner needs privileges. Without root, -o and -g fail with "Operation not permitted" unless they name you and your groups.
  • Replacing a running binary works with install but can fail with "Text file busy" when you cp over it.
  • -d is a good mkdir -p when you want a mode and ownership at the same time: install -d -m 755 -o app -g app /srv/app.
  • -C is 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; install copies the bytes.