Linux install Command

Linux install command is used to copy files to a specified destination and set attributes. It copies files to a specified destination. It is not used to install programs as its name specifies. To download and install a program, we have to use apt-get, apt, yum, and more utilities, depending on the type of distribution.

It is quite similar to the 'cp' command. Additionally, it allows us to control the attributes of the destination files. It is commonly used to copy programs into makefiles to their destination directory. It refuses to copy files on itself.

The install command combines elements from the different commands such as cp, chown, chmod, mkdir, and strip commands. It allows us to use features of all these commands in one single action.

The features of the install command are as following:

  • It is used to copy files like the cp command.
  • It provides the functionality to select whether to overwrite existing files or not.
  • It is used to create the destination directory if it does not exist.
  • It is used to set the user permission flags of the files, like the chmod command.
  • It is used to set the owner of the files.
  • It is used to remove non-essential baggage from executable files.

Syntax:

Option:

The supported options by install command are as following:

  • --backup[=CONTROL]: This option creates a backup file for each existing destination file.
  • -b: It is like a "--backup" option, but it does not take an argument.
  • -C, --compare: It is used to compare each pair of source and destination files, and in some cases, it does not modify the destination at all.
  • -d, --directory: If the "-d or -directory" option is specified, it will treat all arguments as directory names.
  • -D: It is used to create all components of the target directory; after that, it copies the SOURCE to DESTINATION.
  • -g, --group=GROUP: It is used to set group holdings.
  • -m, --mode=MODE: It is used to set the permission mode (as in chmod), instead of rwxr-xr-x.
  • -o, --owner=OWNER: It is used to set the ownership. It can be used only by the superuser.
  • -p, --preserve-timestamps: It applies the access time of source file to the specified file.
  • -s, --strip: It is used for the strip symbol tables.
  • --strip-program=PROGRAM: It used to strip binaries in the program.
  • -S, --suffix=SUFFIX: It is used to override the usual backup suffix.
  • -t, --target-directory=DIRECTORY: It is used to copy all source arguments into the specified directory.
  • -T, --no-target-directory: It is used to treat destination file as a normal file.
  • -v, --verbose: It is used to print the name of each directory.
  • --preserve-context: It is used to preserve the SELinux security context.
  • -Z: It is used to set the SELinux security context of the destination file, and each created directory to default type.
  • --help: The '-help' option displays the help manual.
  • --version: It is used to display the version information.

How to copy files to a directory?

We can customize each folder and file according to our needs by using the install command. It is used as follows:

From the above command, the '-D' option will copy all the text files from the source folder to the destination folder.

If you are needed to create a new destination folder, execute the below command:

The above command will create a 'New_folder' in the specified directory. For example, to copy two files 'Demo.txt' and 'Test.txt' to 'Downloads' directory, execute the command as follows:

The above command will copy the given files to the 'Downloads' folder. Consider the below output:

Linux install Command