4

How can be done coping files that have some suffix at the end, into same dir with the smallest command possible:

Example have directory containing files:

  • cassandra.yml.example
  • database.yml.example
  • facebook.yml.example
  • cache.yml.example
  • system.yml.example

need to copy them and have names like this:

  • cassandra.yml
  • database.yml
  • facebook.yml
  • cache.yml
  • system.yml

2 Answers2

4
for x in /path/to/*.example
do
  cp "$x" "${x%%.example}"
done

Will make a copy without the .example into the same folder as the source file.

llua
  • 6,900
0

Requires find and a shell that supports string manipulation and process substitution (i.e. Bash and any compatible):

while read file
    do cp $file ${file%%.ext}
done < <(find -type f)

If you want to copy all files without extensions, you can use the glob (*) instead of ext.

laebshade
  • 2,176