Created
March 30, 2015 20:05
-
-
Save emreberge/44b57aab448753740cf8 to your computer and use it in GitHub Desktop.
Replaces all files found in specified directory three with their equal named counterparts from the other speicifed directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -u | |
set -e | |
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]:-$0}" )" && pwd )" | |
script_name="$( basename "${BASH_SOURCE[0]:-$0}" )" | |
print_usage_and_exit() | |
{ | |
echo "Replaces all files found in specified directory three with their equal named counterparts from the other speicifed directory." | |
echo "Usage: ${script_name} direcrory-to-replace-files-in directory-to-search-for-new-files" | |
exit 1 | |
} | |
trap 'print_usage_and_exit' EXIT | |
direcrory_to_replace_files_in="${1}" | |
directory_to_search_for_new_files="${2}" | |
trap - EXIT | |
bold=`tput bold` | |
normal=`tput sgr0` | |
main() | |
{ | |
ls "${directory_to_search_for_new_files}" | \ | |
xargs -n 1 | \ | |
while read file_to_copy | |
do | |
echo "${bold}${file_to_copy}${normal} replaced in following folders:" | |
find "${direcrory_to_replace_files_in}" -name "${file_to_copy}" | \ | |
while read file_to_replace | |
do | |
printable_name="${file_to_replace#$direcrory_to_replace_files_in}" | |
printable_name="${printable_name#/}" | |
echo "\t$(dirname "${printable_name}")" | |
cp "${directory_to_search_for_new_files}/${file_to_copy}" "${file_to_replace}" | |
done | |
echo | |
done | |
} | |
main | less |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment