Linux recursively replace periods for all directorys and all but last period for files with underscores
问题 I have the following command which recursively renames all the files/directory's to lowercase and replaces spaces with _. find . -iname "*" | rename 'y/A-Z/a-z/; s/ /_/g;' How do I extend it to remove all periods from directories and leave just the last period for files? So input would be: this.is.a.directory this.is.a.file.txt Output this_is_a_directory this_is_a_file.txt 回答1: You can do this using find in a while loop and using a regex to leave last DOT for files: while IFS= read -rd ''