install

file managementLinux/Unix
The install command is one of the most frequently used commands in Linux/Unix-like operating systems. install Copy files and set attributes

Quick Reference

Command Name:

install

Category:

file management

Platform:

Linux/Unix

Basic Usage:

install [options] [arguments]

Common Use Cases

    Syntax

    install [options] source... destination

    Options

    Option Description
    -b, --backup[=CONTROL] Make a backup of each existing destination file
    -c (Ignored, for compatibility with old versions)
    -d, --directory Treat all arguments as directory names; create all components of the specified directories
    -D Create all leading components of destination except the last, then copy source to destination
    -g, --group=GROUP Set group ownership, instead of process' current group
    -m, --mode=MODE Set permission mode (as in chmod), instead of rwxr-xr-x
    -o, --owner=OWNER Set ownership (super-user only)
    -p, --preserve-timestamps Apply access/modification times of source files to corresponding destination files
    -s, --strip Strip symbol tables (strip command)
    --strip-program=PROGRAM Program used to strip binaries
    -S, --suffix=SUFFIX Override the usual backup suffix
    -t, --target-directory=DIRECTORY Copy all source arguments into DIRECTORY
    -T, --no-target-directory Treat destination as a normal file
    -v, --verbose Print the name of each directory as it is created
    --help Display help information and exit
    --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the install command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    install file.txt /usr/local/bin/
    Copy file.txt to /usr/local/bin/ with default permissions.
    install -m 755 script.sh /usr/local/bin/
    Copy script.sh to /usr/local/bin/ with executable permissions (755).
    # Advanced Examples Advanced
    install -d -m 755 /opt/myapp/logs Create the directory /opt/myapp/logs with permissions 755. install -o root -g wheel -m 644 config.conf /etc/ Copy config.conf to /etc/ and set owner to root, group to wheel, and permissions to 644. install -v -b myapp /usr/local/bin/ Verbose copy of myapp to /usr/local/bin/ with backup of existing file. install -s binary /usr/local/bin/ Copy binary to /usr/local/bin/ and strip debugging symbols. install -t /usr/local/share/doc/myapp/ README.md LICENSE.txt Copy README.md and LICENSE.txt to the target directory /usr/local/share/doc/myapp/. install -D -m 644 myconfig.conf /etc/myapp/conf/myconfig.conf Create parent directories as needed and copy myconfig.conf with mode 644.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The install command is a versatile utility that combines the functionality of copying files, creating directories, and setting file attributes like permissions and ownership. It's commonly used in software installation scripts and Makefiles to place files in their correct locations with appropriate permissions. Key features of install: 1. Multi-functional Utility: install combines the features of mkdir, cp, chown, chmod, and strip into a single command, streamlining file installation operations. 2. Directory Creation: With the -d option, install can create directories with specified permissions, similar to mkdir -p but with more control over attributes. 3. Permission Setting: The -m option allows setting specific permissions on files during copying, ensuring they have the correct access rights immediately. 4. Ownership Control: The -o and -g options enable setting the owner and group of files, which is crucial for system files that need specific ownership. 5. Binary Handling: For executable files, the -s option can strip symbol tables from binaries, reducing their size after installation. 6. Path Creation: The -D option creates parent directories as needed, similar to mkdir -p, before copying the file to its destination. 7. Backup Functionality: The -b option creates backups of existing destination files before overwriting them, providing a safety measure during updates. The install command is particularly useful in: - Software installation scripts, where files need to be placed in system directories with specific permissions - Makefiles for properly installing compiled binaries and documentation - System administration scripts that deploy configuration files - Package building processes - Deployment scripts that need to ensure files have consistent attributes Compared to simply using cp followed by chmod and chown, install offers several advantages: - It's more concise, requiring a single command instead of multiple commands - It's atomic, reducing the chance of files existing temporarily with incorrect permissions - It provides built-in features for creating directories and handling special cases - It's designed specifically for software installation scenarios install is available on virtually all Unix-like systems, including Linux and macOS, making it a reliable choice for cross-platform installation scripts.

    Related Commands

    These commands are frequently used alongside install or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the install command works in different scenarios.

    $ install
    View All Commands