Created
February 2, 2017 13:16
-
-
Save rahulkrishnanfs/6d09eaefbc7ae12b5ccb016beb9d2a2d to your computer and use it in GitHub Desktop.
copy files with extention
This file contains hidden or 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 | |
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