Skip to content

Instantly share code, notes, and snippets.

@kitusmark
Last active December 23, 2015 19:50
Show Gist options
  • Save kitusmark/67ce44102982a909bc6b to your computer and use it in GitHub Desktop.
Save kitusmark/67ce44102982a909bc6b to your computer and use it in GitHub Desktop.
finds the specified type of file in a directory and copies them in the destination directory
#!/bin/bash
# Script that finds a type of file in the current directory (recursive)
# and copies them into a destination directory
# Remember you need to put the absolute path of directories i.e ~/Desktop/...
# 1st parameter is the type of file to search
# 2nd parameter is the origin directory
# 3rd parameter is the destination directory
numberOfParameters=3
if [ "$#" -ne $numberOfParameters ]; then
echo "Illegal number of parameters!"
exit 1
fi
echo "The type of file you search: "$1
echo "The origin directory: "$2
echo "The destination directory: "$3
cd $2
find . -type f -iname "$1" -exec cp -r -v -n {} $3 \;
cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment