If I have a tree of files, under say /usr/share/appname/, how can I install them all recursively with GNU install and mode 644?

I'm assuming that I'll first need to have install create the directories with -d as the directory permissions will need to be different (755).

Surely this isn't the solution:

  local dir file
  for dir in "${dirs_with_files[@]}"; do
    for file in "$srcdir/$dir"/*; do
      # install fails if given a directory, so check:
      [[ -f $file ]] && install -Dm644 -t "$dir" "$file"

There’s no magic incantation to make install install files recursively. install might not be the best tool in this scenario: you might be better off using cp to copy the files and directory structure, and then chmod to fix up the modes.

  • Or use rsync, e.g. rsync -av --no-o --no-g source target/ – reinierpost Nov 7 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.