install - Linux
Overview
The install command in Linux is used for copying files and setting attributes. It is often utilized in Makefiles during the installation of software to ensure that proper file permissions and ownerships are set. The command provides more control compared to simply using cp, as it is designed to set up executable files and directories with specific attributes in place.
Syntax
The general syntax of the install command is:
install [OPTION]... SOURCE DEST
install [OPTION]... SOURCE... DIRECTORY
install [OPTION]... -t DIRECTORY SOURCE...
install [OPTION]... -d DIRECTORY...
SOURCE: Specifies the source file(s) to copy.DEST: Specifies the destination file or directory.DIRECTORY: Target directory for installing the files.
Options/Flags
-m, --mode=MODE: Set permission mode (as inchmod), instead of the default755(rwxr-xr-x).-o, --owner=OWNER: Set the owner of the installed file. TheOWNERcan be a user name or numeric user ID.-g, --group=GROUP: Set the group of the installed file. TheGROUPcan be a group name or numeric group ID.-t, --target-directory=DIRECTORY: Specify the directory to install the files.-d, --directory: Treat all arguments as directory names and create each of them.-c: Ignored; for compatibility with old Unix versions ofinstall.-D: Create all leading components ofDESTexcept the last, then copySOURCEtoDEST.-s, --strip: Strip symbol tables. Useful for reducing the executable file size by removing debugging information.-p, --preserve-timestamps: Preserve the time of the original files in the new files.-v, --verbose: Display verbose output.
Examples
-
Simple Installation of a File:
install -m 755 script.sh /usr/local/bin/scriptThis installs
script.shto/usr/local/bin/scriptwith execution permissions. -
Installing Multiple Files Into a Directory:
install -m 644 file1.txt file2.txt /usr/local/share/docsInstalls
file1.txtandfile2.txtinto/usr/local/share/docswith read/write permissions for user, and read-only for others. -
Creating Directories:
install -d /usr/local/share/myappCreates the directory
/usr/local/share/myapp.
Common Issues
- Permission Denied: Make sure you have the necessary permissions to install files in the destination directory.
- File Overwrite Concerns:
installwill overwrite files without warning. Use caution when specifying targets.
Integration
Combine install with shell scripts for robust installation routines. For instance, use a loop to install multiple files:
for file in $(ls *.sh); do
install -m 755 "$file" /usr/local/bin/"$file"
done
Related Commands
cp: Copies files and directories.chmod: Changes file modes or Access Control Lists.chown: Changes file owner and group.
For more advanced details, refer to the install man page by typing man install in your terminal. This provides a comprehensive guide to its usage and options.