install command in Linux with examples
The 'install' command in Linux is a versatile tool used for copying files and setting their attributes, such as permissions, ownership, and group. Unlike commands like 'cp' that simply copy files, 'install' allows you to fine-tune these settings, making it ideal for installation scripts or manual file management. It can copy files to a specified destination and set permissions, ownership, or group attributes, all in one go.
Syntax:
install [OPTION]... [-T] SOURCE DEST install [OPTION]... SOURCE... DIRECTORY install [OPTION]... -t DIRECTORY SOURCE... install [OPTION]... -d DIRECTORY...
Here,
- The first three forms are used to copy files from SOURCE to DEST or multiple SOURCE files to an existing DIRECTORY, with the ability to set permissions, ownership, and group attributes.
- The fourth form is unique as it creates all components of the specified DIRECTORY.
Key Options for the 'install' Command
Here’s a breakdown of the essential options available with the 'install' command:
Options | Description |
---|---|
--backup[=CONTROL] | Creates a backup of each existing destination file. |
-b | Similar to --backup but does not accept an argument. |
-C, --compare | Compares each pair of source and destination files; may not modify the destination in some cases. |
-d, --directory | Treats arguments as directory names and creates all specified directories. |
-g, --group=GROUP | Sets group ownership instead of using the current group. |
-m, --mode=MODE | Sets permission mode (similar to chmod ). |
-o, --owner=OWNER | Sets file ownership; requires super-user privileges. |
-p, --preserve-timestamps | Applies access and modification times of source files to corresponding destination files. |
-t, --target-directory=DIRECTORY | Copies all source arguments into the specified directory. |
-T, --no-target-directory | Treats the destination as a normal file, not as a directory. |
-v, --verbose | Displays the name of each directory as it is created. |
--help | Displays the help message and exits the command. |
--version | Shows version information and exits the command. |
Examples of Using the 'install' Command
1. Copy Files to a Directory: Copies two files 'rocket.c' and 'rocket' to directory 'demo'.

2. Compare and Copy Files: Use the '-C' option to compare files before copying:
If the files are identical, 'install' will not overwrite the destination.
3. Use the -T Option: This option treats DEST as a file rather than a directory:
This command creates 'destination.txt' as a regular file even if the path resembles a directory structure.
4. Set Ownership and Permissions: Change the owner to user and set permissions to 755:
This command copies 'rocket.c' to '/usr/local/bin/' with specified ownership and permissions.
5. Printing version information: Check the version of install:
Conclusion
The install command in Linux is a powerful tool that does more than just copy files. It lets you set permissions, change file ownership, and more, all in one step. This makes it great for installing files manually or using scripts where you need specific control over how files are set up. By learning how to use the install command and its options, you can easily manage files and folders while keeping control over their settings.