Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'install' Command In Linux

2023-05-29 - By Robert Elder

     I use the 'install' command to copy and install files exactly how I want:

install my-file.txt

Using The 'install' Command Just Like The 'cp' Command

     The simplest use of the 'install' command works just like the 'cp' command, and all it does is make a copy of a file.  If I start out with the file 'notes.txt':

ls
notes.txt

     and run this install command:

install notes.txt notes_copy.txt

     you can see that a copy of the file has been created:

ls
notes_copy.txt  notes.txt

Directly Setting Permissions With The 'install' Command

     The 'install' command also lets you directly set the permissions on the new copied file.  For example, this command will grant all permissions on the copied file:

install --mode='ugo=rwx' notes.txt notes_copy.txt
ls -l notes_copy.txt
-rwxrwxrwx 1 robert robert 0 May 26 11:16 notes_copy.txt

     and this command will grant none of them:

install --mode='ugo=-rwx' notes.txt notes_copy.txt
ls -l notes_copy.txt
---------- 1 robert robert 0 May 26 11:18 notes_copy.txt

The Purpose Of The 'install' Command

     The primary application of the 'install' command is for use in Makefiles.  For example, if we take a look at the Makefile for the 'ncurses' application as well as the configure script, you can see that it creates some variables that reference the 'install' command:

...
configure:3812  if test "${ac_cv_path_install+set}" = set; then
configure:3813    INSTALL=$ac_cv_path_install
configure:3814  else
...
...
Makefile.in:71 INSTALL		= @INSTALL@
Makefile.in:72 INSTALL_PROGRAM	= @INSTALL_PROGRAM@
Makefile.in:73 INSTALL_SCRIPT	= @INSTALL_SCRIPT@
Makefile.in:74 INSTALL_DATA	= @INSTALL_DATA@
...

     The 'install' command is used in various places throughout the project's makefiles, specifically during the execution of the make install rule:

...
progs/Makefile.in:218 install.progs: $(AUTO_SRC) $(PROGS) $(DESTDIR)$(bindir)
progs/Makefile.in:219 @MAKE_TERMINFO@	$(LIBTOOL_INSTALL) $(INSTALL_PROG) tic$x     $(DESTDIR)$(bindir)/$(actual_tic)
progs/Makefile.in:220 @MAKE_TERMINFO@	$(LIBTOOL_INSTALL) $(INSTALL_PROG) toe$x     $(DESTDIR)$(bindir)/$(actual_toe)
progs/Makefile.in:221 @MAKE_TERMINFO@	@echo "linking $(actual_infotocap) to $(actual_tic)"
progs/Makefile.in:222 @MAKE_TERMINFO@	-@rm -f $(DESTDIR)$(bindir)/$(actual_infotocap)
progs/Makefile.in:223 @MAKE_TERMINFO@	( cd $(DESTDIR)$(bindir) && $(LN_S) $(actual_tic) $(actual_infotocap) )
progs/Makefile.in:224 @MAKE_TERMINFO@	@echo "linking $(actual_captoinfo) to $(actual_tic)"
progs/Makefile.in:225 @MAKE_TERMINFO@	-@rm -f $(DESTDIR)$(bindir)/$(actual_captoinfo)
progs/Makefile.in:226 @MAKE_TERMINFO@	( cd $(DESTDIR)$(bindir) && $(LN_S) $(actual_tic) $(actual_captoinfo) )
progs/Makefile.in:227 	$(LIBTOOL_INSTALL) $(INSTALL_PROG) infocmp$x $(DESTDIR)$(bindir)/$(actual_infocmp)
progs/Makefile.in:228 	$(LIBTOOL_INSTALL) $(INSTALL_PROG) clear$x   $(DESTDIR)$(bindir)/$(actual_clear)
progs/Makefile.in:229 	$(LIBTOOL_INSTALL) $(INSTALL_PROG) tabs$x    $(DESTDIR)$(bindir)/$(actual_tabs)
progs/Makefile.in:230 	$(LIBTOOL_INSTALL) $(INSTALL_PROG) tput$x    $(DESTDIR)$(bindir)/$(actual_tput)
progs/Makefile.in:231 	$(LIBTOOL_INSTALL) $(INSTALL_PROG) tset$x    $(DESTDIR)$(bindir)/$(actual_tset)
...

Using The 'install' Command To Strip Debug Symbols

     As described above, the 'install' command can be used to copy files, but it also contains a number of other features that are useful when installing programs.  For example the '-s' flag will strip debug symbols from an executable as it gets copied.  Here, I have a simple C program:

int main(){
        return 0;
}

     If I compile this program:

gcc -g main.c

     and use two different 'install' commands to create copies of the executable:

install -s a.out no-sym.out
install a.out with-sym.out

     you can see the 'with-sym.out' that copied without the '-s' flag still has all of its debug symbols:

vim -d <(objdump -t a.out) <(objdump -t with-sym.out)
With Debug Symbols

     but the one 'no-sym.out' that copied with the '-s' flag no longer has its debug symbols:

vim -d <(objdump -t a.out) <(objdump -t no-sym.out)
Without Debug Symbols

     The only difference between the two executables above is the omitted debug symbols that were stripped by the 'install' command.

     And that's why the 'install' command is my favourite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use