Skip to content

Instantly share code, notes, and snippets.

@enobufs
Last active October 6, 2018 23:55
Show Gist options
  • Save enobufs/cc219a84ba5db1fd9041d7fe746ee285 to your computer and use it in GitHub Desktop.
Save enobufs/cc219a84ba5db1fd9041d7fe746ee285 to your computer and use it in GitHub Desktop.
Copy files with modifying file names in Bash
#!/bin/bash
srcdir=./sample
dstdir=.
array=(`find $srcdir -type f`)
#echo Length: ${#array[@]}
for i in "${array[@]}"
do
from="$i"
to=$dstdir/`sed -e "s/\.cfg.*/\.cfg/g" <<< $(basename $i)` # modify this line as you need
cp $from $to
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment