Last active
August 29, 2015 14:00
-
-
Save mbeall/11028862 to your computer and use it in GitHub Desktop.
Move all files from directory tree to single directory if match a pattern
This file contains 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 | |
# | |
# Accepts two arguments | |
src=$(echo $1) | |
dest=$(echo $2) | |
if [ -z $1 ] | |
then | |
if [ -z $(ls | grep googlefontsdirectory) ] | |
then | |
echo 'Source directory not found.' | |
echo 'Please explicitly declare source directory.' | |
echo 'Usage googlefonts.sh $src $dest' | |
exit 1 | |
else | |
src=$(echo 'googlefontsdirectory') | |
if [ -z $(find ./ -type d -name googlefonts -maxdepth 1) ] | |
then | |
mkdir googlefonts | |
dest=$(echo 'googlefonts') | |
else | |
echo "Destination directory already exists: $(find ./ -type d -name googlefonts -maxdepth 1)" | |
echo 'Please explicity declare destination directory.' | |
echo 'Usage googlefonts.sh $src $dest' | |
exit 1 | |
fi | |
fi | |
elif [ -z $2 ] | |
then | |
if [ -z $(find ./ -type d -name googlefonts -maxdepth 1) ] | |
then | |
mkdir googlefonts | |
dest=$(echo 'googlefonts') | |
else | |
echo "Destination directory already exists: $(find ./ -type d -name googlefonts -maxdepth 1)" | |
echo 'Please explicity declare destination directory.' | |
echo 'Usage googlefonts.sh $src $dest' | |
exit 1 | |
fi | |
fi | |
for i in $(find $src -type f -name "*.ttf") | |
do | |
cp -v $i $dest/ | |
done | |
for i in $(find $src -type f -name "*.otf") | |
do | |
cp -v $i $dest/ | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to move all of the fonts from their various subdirectories into a single directory so that I could easily copy these into my Font Book. Feel free to revise for your own purposes.