The Linux install command is used to install or upgrade software or back up data.
Linux install command Function Description
Use the install command to copy files and set attributes. In the first three forms of the following command syntax, copy source files to a target file or copy multiple source files to a pre-existing directory while setting their ownership and permission modes. In the fourth form, create gives all the components in the target directory.
The install command is used to install or upgrade software or back up data, and it is used by all users. install is similar to the cp command in that both can copy files/directories to a specified location. However, install allows you to control the properties of the target file. install is usually used in a program’s makefile, which is used to copy the program to the target (installation) directory.
Linux install command Syntax
install [option] [-T] [source] [target]
install [options] [source] [directory]
install [options] -t [directory] [source file]
install [option] -d [directory]
The meaning of each option in the command is shown in the table –
Option | Description |
---|---|
-c |
Compare each set of source and target files, in some cases without modifying the target files |
-d |
Treat all parameters as directory names and create all components for the specified directory |
-D |
Create all necessary parent directories of the target directory and copy the source files to it |
-g |
Set the group to which you belong, not the group to which the process currently belongs |
-m |
Set your own permission mode (like chmod), not rwxr-xr-x |
-o |
Custom owner (Superuser only) |
-p |
Modify the access/modification time of the source file to be consistent with the target file |
-s |
Unpack the symbol table |
-S |
Overwrites the suffix of a common backup file |
-t |
Copies all parameters of the source file to the specified directory |
-T |
Treat the target file as a normal file |
-v |
Display the name of the directory when you create it |
Linux install command Examples
Create /root/apidemos folder
install -d /home/deepinout/apidemos
Output:
Copy the /root/install.log file to the /root/www folder
[root@rhel ~]# install /root/install.log /root/www
Copy the /root/install.log file to the /root/www folder and rename it to qq
[root@rhel ~]# install /root/install.log /root/www/qq
Copy the /root/install.log file to /root/www/ss file and set the permission to 644
[root@rhel ~]# install -m 644 /root/install.log /root/www/ss
Copy the /root/install.log file to the /root/ppp/bb file if there is no /root/ppp directory
[root@rhel ~]# install -D /root/install.log /root/ppp/bb
Modify the access/modification time of the source file /root/install.log to be the same as the target file /root/www/ooo
[root@rhel ~]# install -p /root/install.log /root/www/ooo
useful option -D
:
install -D x a/b/c
The effect is similar to:
mkdir -p a/b && cp x a/b/c
install [option] SOURCE [SOURCE...] DIRECTORY
Copy multiple SOURCE files to the destination directory:
install a/* d
where d
is the directory.