1

I would like to rename a Multiple files in Multiple directories into a single filename. Let say i have files

  • k1-abc in one directory
  • k1-def in 2nd directory
  • k1-adt in 3rd directory

The common thing in all the file names is k1 followed by some other name

I need to rename all the filenames as Dockerfile I dont have rename command in my Linux

what is the best command to do this

Cena
  • 55
  • 3
  • 8
  • Possible duplicate of [Find and replace filename recursively in a directory](https://stackoverflow.com/questions/9393607/find-and-replace-filename-recursively-in-a-directory) – zwer May 23 '18 at 03:23
  • Thanks for the reply find . -name ''k1-*" -type f -exec bash -c 'mv "$1" "${1/\/k1-*_/Dockerfile/}"' -- {} \; It works only for one directory am i doing something wrong. it doesnt affect for all the directories – Cena May 23 '18 at 04:12

1 Answers1

0

This will rename all files only in /path/to/files that begin with k1 and renames them to Dockerfile.

find /path/to/files -type f -name "k1*" -exec mv -v {} Dockerfile \;