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 cmp Command: Compare Files Byte by Byte

Linux cmp Command: Compare Files Byte by Byte

Learn how Linux cmp compares two files byte by byte, reports the first mismatch, runs silently in scripts, limits ranges, and differs from diff and checksums.

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Learn how to use the Linux sudo command to run approved commands with elevated privileges or as another user, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Linux Terminal and Shell Basics: Command Syntax and Finding Help

Linux Tutorial / Linux Terminal and Shell Basics: Command Syntax and Finding Help

Learn the difference between a terminal and a shell, read command syntax and output, and use Bash help tools through a short hands-on exercise.

Linux bg Command: Resume a Shell Job in the Background

Linux bg Command: Resume a Shell Job in the Background

Learn how to resume a Shell Job in the Background with the Linux bg command, including practical examples, key options, and important precautions.

How to Check IP Addresses on Linux

How to Check IP Addresses on Linux

Learn how to check private and public IP addresses on Linux, identify the active interface and route, and distinguish IPv4, IPv6, and externally visible addresses.

Linux journalctl Command: Read systemd Logs

Linux journalctl Command: Read systemd Logs

Learn how to read systemd Logs with the Linux journalctl command, including practical examples, key options, and important precautions.

Linux scp Command: Copy Files over SSH

Linux scp Command: Copy Files over SSH

Learn how to copy Files over SSH with the Linux scp command, including practical examples, key options, and important precautions.

Linux unxz Command: Decompress xz Files

Linux unxz Command: Decompress xz Files

Learn how to decompress xz Files with the Linux unxz command, including practical examples, key options, and important precautions.

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Learn what ls, file, stat, and readlink each reveal about a Linux file, including type, size, timestamps, and symbolic-link targets.

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.