Linux install Command: Copy Files and Set Attributes

This guide explains how to use the Linux install command to copy files while setting modes, owners, groups, timestamps, and destination directories in deployment scripts. It focuses on practical Linux usage, predictable automation, and the cases where a seemingly small path or option mistake can change the result.

The examples use GNU Coreutils behavior. Check install --help, man install, and your distribution documentation when portability or a version-specific option matters.

What Is the install Command?

GNU install copies files while applying a requested mode, owner, group, timestamp policy, or directory layout. It is a deployment utility, not a package manager: it does not resolve dependencies or track package installation and removal.

Basic Syntax

install [OPTION]... SOURCE DESTINATION
install [OPTION]... SOURCE... DIRECTORY
install -d [OPTION]... DIRECTORY...

Quote paths that contain spaces. When supported, place -- before operands that begin with a hyphen so they are not interpreted as options.

Basic install Usage

Install an executable

Copy the binary to a system path and state the intended executable mode. Use sudo explicitly when the destination requires elevated privileges.

sudo install -m 0755 mytool /usr/local/bin/mytool

Install a configuration file

Configuration files usually should not be executable. Define an overwrite and rollback policy before replacing a live configuration.

sudo install -m 0644 mytool.conf /etc/mytool/mytool.conf

Create an installation directory

With -d, install creates directories instead of copying a file and can assign mode, owner, and group.

sudo install -d -m 0750 -o myapp -g myapp /var/lib/myapp

Check mode after installation

install performs file copying and permission setting at once, but it generally does not display a success message.

printf '#!/bin/sh\n' > demo-tool
install -m 755 demo-tool demo-tool-installed
stat -c '%a %n' demo-tool-installed

Example output:

755 demo-tool-installed

This result only checks the permission mode of the target file. Check separately whether the script actually runs correctly and whether the installation location matches the service path.

Key Options

Option Purpose
-m MODE Set the installed mode.
-o OWNER Set the owner when permitted.
-g GROUP Set the group.
-d Create directories and required parents.
-D Create the final destination's missing parents and install the file.
-t DIR Specify the target directory.
-p Preserve source access and modification times.
-s Strip symbol tables during installation.
-C Avoid changing a destination when content and selected attributes already match.

Long options often make reviewed scripts easier to understand. When a script must run on non-GNU systems, verify every non-POSIX option on the target platform.

Practical Examples

Install a file with its parent path

The -D option creates parents for the final file path. Use a separate install -d step when parent ownership or modes need independent control.

sudo install -D -m 0644 myapp.service /etc/systemd/system/myapp.service

Install several files into one directory

The -t form clearly identifies the destination before a generated source list.

sudo install -m 0644 -t /usr/local/share/myapp templates/*.html

Verify installed attributes

Check the path, mode, owner, group, file type, and runtime dependencies appropriate for the deployed artifact.

stat -c '%A %U:%G %n' /usr/local/bin/mytool
file /usr/local/bin/mytool

install and Related Commands

Command or method Primary role Best fit
install Copy and set attributes Build installation and deployment
cp General file copying Attributes are managed separately
mkdir Create ordinary directories Workspace directory trees
apt or dnf Manage packages and dependencies Distribution-provided software

Important Cautions

It is not a package manager

Files copied with install are not automatically tracked for upgrades, dependency changes, or clean removal.

Do not rely on the default mode

State -m for configuration files, secrets, and executables so permissions match their role.

Plan replacement of live files

Directly overwriting an active configuration or executable can cause outages. Use backup, validation, atomic switching, and rollback where required.

FAQ

Does install install software packages?

No. It copies files and applies attributes; it does not manage package dependencies.

Why use install instead of cp?

It combines copying with explicit modes, ownership, and destination directory creation.

Can it create only a directory?

Yes. Use install -d DIRECTORY and add -m, -o, or -g as needed.

How do I preserve source timestamps?

Use -p or --preserve-timestamps.

Related Resources

More in This Category
Linux lsmod Command: List Loaded Kernel Modules

Linux lsmod Command: List Loaded Kernel Modules

Learn how to list Loaded Kernel Modules with the Linux lsmod command, including practical examples, key options, and important precautions.

Linux Tutorial / Compare Files with diff and cmp

Linux Tutorial / Compare Files with diff and cmp

Use diff and cmp to compare two files, read unified diff output, and distinguish a detected difference from an actual command error.

Linux whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux tr Command: Translate and Delete Characters

Linux tr Command: Translate and Delete Characters

Learn how to translate and Delete Characters with the Linux tr command, including practical examples, key options, and important precautions.

Linux pacman Command: Manage Packages on Arch Linux

Linux pacman Command: Manage Packages on Arch Linux

Learn how to manage Packages on Arch Linux with the Linux pacman command, including practical examples, key options, and important precautions.

Linux Tutorial / Standard Input, Output, Redirection, and Pipes

Linux Tutorial / Standard Input, Output, Redirection, and Pipes

Understand standard input, output, and error; practice file redirection and pipes; and learn why overwrite risk and redirection order matter.

Linux help Command: Read Help for Bash Built-in Commands

Linux help Command: Read Help for Bash Built-in Commands

Learn how to use the Linux help command to read usage information for Bash built-in commands, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux ssh Command: Connect to a Remote Host Securely

Linux ssh Command: Connect to a Remote Host Securely

Learn how to connect to a Remote Host Securely with the Linux ssh command, including practical examples, key options, and important precautions.

Linux ps Command: Inspect Running Processes

Linux ps Command: Inspect Running Processes

Learn how to inspect Running Processes with the Linux ps command, including practical examples, key options, and important precautions.

Linux dnf Command: Manage RPM Distribution Packages

Linux dnf Command: Manage RPM Distribution Packages

Learn how to manage RPM Distribution Packages with the Linux dnf command, including practical examples, key options, and important precautions.