Skip to content

Instantly share code, notes, and snippets.

@rahulkrishnanfs
Created February 2, 2017 13:16
Show Gist options
  • Save rahulkrishnanfs/6d09eaefbc7ae12b5ccb016beb9d2a2d to your computer and use it in GitHub Desktop.
Save rahulkrishnanfs/6d09eaefbc7ae12b5ccb016beb9d2a2d to your computer and use it in GitHub Desktop.
copy files with extention
#!/bin/bash
SRC=$1
DEST=$2
EXT=$3
if [ -d $1 -a -d $2 ];then
for file in `ls *.$EXT `;do
name=$(echo $file | cut -d "." -f1)
if [ -d $DEST/$name ];then
cp $SRC/$file $DEST/$name/$file
else
mkdir $DEST/$name
cp $SRC/$file $DEST/$name/$file
fi
done
else
echo Enter the valid directory path
fi
### USAGE
script.sh <src path> <dest path> <extension>
Eg:
$./script.sh /tmp /opt txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment