Created
October 20, 2021 15:37
-
-
Save rogeruiz/3c6070f34f4482455441783619bc0c97 to your computer and use it in GitHub Desktop.
Find files and move them to a new place given the name of a file and the destination dirname and path.
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
#!/bin/bash | |
set -e | |
file_name=$1 | |
new_path=$2 | |
full_path=$(find docs/ -iname "${file_name}") | |
extracted_file_name=$(basename "${full_path}") | |
# shellcheck disable=2116,2086 | |
lowercase_file_name=$(echo ${extracted_file_name} | tr '[:upper:]' '[:lower:]') | |
if [ -f "${full_path}" ] | |
then | |
mv "${full_path}" "${new_path}${lowercase_file_name}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made a tweak to have this script output the part needed for the redirect flow. Then you can run
./migrate-by-filename.sh a-file-to-move.md docs/new/path/ | pbcopy