install is a versatile command for copying files in Linux and Mac OS. It's perfect for power users looking for efficiency. Read this article to learn how to work smarter ̵
Wait, it is not intended for the installation of software.
install may have the most misleading name of any Linux command. There is no software installed. If you are attempting to install a software package from the command line in Ubuntu or another Debian-based distribution, use the command
apt-get . Instead, use the package management tool of your Linux distribution on other Linux distributions. For example,
dnf under fedora or
zypper under openSUSE.
What is being installed?
install combines elements from the
chown (change ownership),
chmod (change mode),
] mkdir (directory make) and
strip (strip symbols). You can use functions from all these functions in a single action.
With the command
install you can:
- copy files like the command
- Choose if you want to do this Overwrite existing files.
- Create the target directory if it does not exist, such as
- Set the user permission flags of the files exactly as they would with the
- Set the owner of the files, as well as the command
- Remove unused baggage from executable files, just like the
stripcommand With all this functionality, the
installcommand does not have too many options to fight with.
When would you use them
] The installcommand is not likely to be used every day. It is useful, but only for certain situations. A scenario where
is installedis software development. For example, you program a new utility. You must test outside the development environment. To do this, you must copy the new program files to a test directory. You may need to create the test directory, and you must set the correct permissions and ownership for the files.
Because the development is an iterative activity, you can do this sequence of actions very often. The command
installdoes all the heavy work for you. When your new utility is ready for deployment, you can finally use it with
installto copy it to the final workstation with the correct permissions.
A programmer is currently working on such a new utility with the name
ana. It consists of an executable binary file and a database. After the test, it must be copied to
/ usr / local / binto make it available to all users of the Linux system. You must replace the file names and directory paths in our example with the files and paths that you use on your computer if you install
. Until it is ready to be published, it will be tested in a directory called
~ / test / ana. Members of the
geekgroup have read and execute permissions. Other users also have read and execute permissions. The command
installuses the same numeric representation for permissions as
chmod. Our programmer has decided that the permissions must be set to the following:
- Owner: Read, Write and Execute.
- Group: Read and Execute.
- Other: Run Only.
The working directory of our fictional programmer is
~ / work. He has written the program, compiled and produced a binary file called
ana. He has already created the database file with which
Words.dbworks. Thus, both files are ready for testing. Let's take a look:
ls -l ana Words.db
anathat he just wrote creates anagrams from a phrase provided on the command line. Verification tests are pretty simple.
Our programmer called
anawith the sentence "Biscuit" and everything seems to be good. He wants to copy these two files to the
~ / test / anadirectory to see if the new utility is working properly outside the development environment. It issues the following command:
install -D -v ana Words.db -t ~ / test / ana
The following options were used on the command line:  D : If necessary, create directories, including parent directories.
- v : In detail, list each directory as it is created, and each file copy as it runs.
- t : Target Directory
We can see that
install creates the
~ / test directory and then creates the
~ /. Directory test / ana . The files are listed one after the other when copying to the destination directory.
Listing the files in
~ / test / ana confirms that they were copied correctly.
ls -l [19659040lsim/test/ana" width="646" height="132" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>
The next step is to test utility
anaby calling it in
~ / test / ana,
The utility works as expected, which is great. The permissions are not correct. The prerequisite is that members of the
geekgroup have Read and Execute permissions and other users only have Execution.
We can easily address both issues with the following command. Note the use of
sudoto execute the command with root privileges. The options
-grequire this. We will be asked for our password when we issue the command.sudo install -b -S .bak -o dave -g geek -m 751 ana Words.db -t ~ / test / ana
- The option
-b(backup) creates backup copies of the files before they are overwritten.
-S(suffix) option defines the suffix for the backup files. If you do not specify a suffix, a
~(tilde) is used. We ask
installto use a suffix of
- We set the owner of the file to
dave- with the
- o(owner) option.
- The option
-g(group) requires the name of a group. This becomes the owner of the files. The group we will use is called
- The option
-m(mode) sets the file modes for the files, using the default
chmod] numeric syntax.
-D (create directories) no longer needs to be used because the test directory already exists. We have also omitted the option
-v (verbose). Listing the files in our directory
~ / test / ana shows us the file details:
This confirms that all our requirements were met.
- The files have been copied to the test directory.
- The permissions have been set correctly.
daveis the owner of the files.
- The group
geekis the owner group of the two files.
- Backups of each file were created, named ana.bak and Words.db.bak.
Everything that was achieved by using a command. Neat.
Our programmer makes some recent changes to the utility and compiles again. The changed files must be copied to the directory
~ / test / ana from the directory
~ / work . You can do this with the option
-C (Compare). If source file and destination file are the same, the source file will not be copied.
sudo install -C -b -S .bak -o dave -g geek -m 751 ana Words.db -t ~ / test / ana
The Listing the files in the destination directory tells us that the file size of the file
ana has changed. It is larger than the file
ana.bak . The timestamp on
ana has also changed. These changes are due to the fact that the new version of the file has been copied here.
The file size and timestamp of
Words.db file has not been changed. No changes were made to the file
Words.db so it was not copied. For a project with many files, the
-C (Compare) option can save a lot of time and disk loss by copying only the changed files.
The programmer has retested that
ana utility is still running.
It is time to use
install to copy the files to the
/ usr / local / bin directory. This will make the new utility available to all users of this Linux computer. We know that
/ usr / local / bin exists, so we do not need to create this directory. We can use a modified version of our last command.
We changed the destination directory to
/ usr / local / bin . We have removed the option
-C (Compare) because there are not any copies of these files in the target directory, so there is nothing to compare. Likewise, there is nothing to backup, so we can remove the option
-b (backup) and the option
sudo install -o dave -g geek -m 751 ana Words.db -t / usr / local / bin
We can list the files that arrived in
/ usr / local / bin :
As a last test we change that Directory in our home directory and see if we can call our new utility from there.
Note that we do not run the command
/ usr / local / bin . Mission accomplished.
We mentioned that the installation can remove redundant symbol tables and other baggage from the binary file to reduce size. Let's do this now. Note that the following command does not contain Words.db. This is because Words.db is a database file and not a binary executable. To copy and shrink the binary file
ana you can use the following command. We added the option -s (reduction) with a lowercase letter "s". We have added the option -b (backup) and the option -S (suffix) with a capital letter "S" (19659027). sudo install -s -b -S .bak -o dave -g geek -m 751 ana -t / usr / local / bin
Listing files in
] / usr / local / bin allows you to compare the size of the
ana file with its backup version. The file
ana has been reduced to almost 60% of its previous size.
ls -l / usr / local / bin
] The command
install is suitable for a pretty niche use. For many people, it is not used day to day or possibly month to month. Nevertheless, the command
install is a good tool to familiarize yourself with tricks and to have in your arsenal. In the cases you need it, it rewards your learning curve with efficiency gains, simplicity, and fewer keystrokes.