-2

I have several files with the extension *.php in different subfolders in the folder /root/Hello. I try to rename all .php files to .html but I want to keep the structure i.e. the path to the file should remain identical.

I found all files with the following command:

find /root/Hello -name "*.php" 

But I don't know how I can rename all files with *.php to *.html and keep the structure I think I must use:

-exec 

But I don't which argument I should use with -exec

Cœur
  • 37,241
  • 25
  • 195
  • 267
M. Antony
  • 161
  • 2
  • 3
  • 12
  • 4
    Look into [`rename(1)`](http://man7.org/linux/man-pages/man1/rename.1.html). – L3viathan Mar 20 '19 at 12:17
  • 1
    In addition to the duplicate, also see [Recursively change file extensions in Bash](https://stackoverflow.com/q/21985492/608639), [How do I rename the extension for a batch of files?](https://stackoverflow.com/q/1224766/608639), [find a pattern in files and rename them](https://stackoverflow.com/q/15290186/608639), [How to rename multiple files using find](https://unix.stackexchange.com/q/227662/56041), [How to rename a file using find command](https://askubuntu.com/q/605125), [Find files, rename in place unix bash](https://stackoverflow.com/q/15007058/608639), etc. – jww Mar 20 '19 at 12:34

1 Answers1

1

use find:

find /path -depth -name "*.php" -exec sh -c 'mv "$1" "${1%.php}.html"' _ {} \;