You are not logged in.

#1 2009-04-10 21:16:11

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Using "install" with directories.

I need some help. I just can't figure out the syntax to do this. If I have a directory which contains both files and directories, how can I use install to copy everything to another directory?

The closest I've come is this:

install -Dm644 $srcdir/foo/bar/* -t $pkgdir/foo/bar

which copies the files but it omits all directories in $srcdir/foo/bar. I've tried using the "-d" option but I'm not sure what that actually does. Can this be done with a single "install" command? It would be trivial to do this using other commands but that feels ungainly.

Thanks for any suggestions.

*edit*
Here's what I'm using as a (temporary) solution:

function _install_dir {
  _src_dir=$1
  _dest_dir=$2
  _n=${#_src_dir}
  for _file in $(find $_src_dir -type f)
  do
    _dest_file=${_dest_dir}${_file:$_n}
    install -Dm644 $_file $_dest_file
  done
}

Last edited by Xyne (2009-04-11 01:02:13)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2009-04-11 03:01:25

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 440

Re: Using "install" with directories.

Xyne wrote:

I've tried using the "-d" option but I'm not sure what that actually does. Can this be done with a single "install" command?

There isn't really a way to do it with 1 command because 'install' isn't recursive.

'install -d' is basically just a drop-in for mkdir.  This will install a directory /path/to/dir with 755 perms:

install -dm755 /path/to/dir

To copy all the files in /home/xyne/foo/x to /home/xyne/bar/x, and also copy the files in /home/xyne/foo to /home/xyne/bar (and /home/xyne/bar/x doesn't exist yet):

install -dm755 /home/xyne/bar/x
install -m644 /home/xyne/foo/x/* /home/xyne/bar/x
install -m644 /home/xyne/foo/* /home/xyne/bar

Last edited by tdy (2009-04-11 03:07:55)

Offline

#3 2009-04-11 03:05:40

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Using "install" with directories.

Thanks for the reply, tdy.

I'll keep using the function then as I don't want to have to add specific lines for the entire directory tree.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB