Skip to content

Instantly share code, notes, and snippets.

@okovalov
Created September 9, 2016 01:49
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 okovalov/8f3be1e1e68c47d18cb34992527492b1 to your computer and use it in GitHub Desktop.
Save okovalov/8f3be1e1e68c47d18cb34992527492b1 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$1" ]
then
echo "No destination path is given"
exit 1
fi
if [ -z "$2" ]
then
echo "No folder name pattern is given"
exit 1
fi
if [ -z "$3" ]
then
echo "No command is given"
exit 1
fi
destination=$1
namepattern=$2
command=$3
printf "Searching for pattern $namepattern in $destination\n\n"
for dir in `find $destination -name $2 -type d`
do
cd $dir
echo "Target directory is '$dir'"
echo "Executing command: $command"
read -p "Are you sure? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
eval "$command"
fi
done
@okovalov
Copy link
Author

okovalov commented Sep 9, 2016

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