Skip to content

Instantly share code, notes, and snippets.

@mbeall
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbeall/11028862 to your computer and use it in GitHub Desktop.
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
#!/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
@mbeall
Copy link
Author

mbeall commented Apr 18, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment