Rename all files in a folder from camel case to lowercase and put underscore to separate words

MandMs

I have a bunch of files like FileNameX.cpp and I would like to rename all of them to their respective file_name_x.cpp.

Hadog

This bash command do the job. From the command line, enter the folder, and run this line:

for file in ./* ; do mv "$file" "$(echo $file|sed -e 's/\([A-Z]\)/_\L\1/g' -e 's/^.\/_//')" ; done

In script form it looks like this:

#!/bin/bash
for file in ./* ; do
    mv "$file" "$(echo $file|sed -e 's/\([A-Z]\)/_\L\1/g' -e 's/^.\/_//')"
done

Basically sed is used to manipulate strings. There're two expressions:

  1. s/\([A-Z]\)/_\L\1/g: searches for capitals to substitutes them for lower case and add the underscore

  2. s/^.\/_//: removes any underscore which was inserted due to the first letter being a capital (i.e. you don't want _file_name_x.cpp.

Consider using -v, --verbose on mv to explain what is being done.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Transform all keys from `underscore` to `camel case` of json objects in circe

From Dev

How to rename folder from lowercase to uppercase in git

From

How do I rename all files to lowercase?

From Dev

Rename files with spaces to underscore in all subcategories

From Dev

Rename all files in a folder in Ubuntu

From Dev

python rename all files in folder

From Dev

Python - Extracting all camel case words in a sequence

From Dev

Recursively rename all files and folders to Title Case from terminal

From Dev

Parsing string to separate words by upper case letter, hyphen, and underscore

From Dev

Extract text between two words from all files in a folder in R

From Dev

how to put all files from folder and subfolders into an array

From Dev

Batch rename files to lowercase

From Dev

Rename directories recursively from pascal or camel case to kebab case

From Java

How do I rename all folders and files to lowercase on Linux?

From Dev

script to rename all files & directories into lowercase (including unicode)

From Dev

Rename all files within a folder prefixed with foldername

From Dev

How to rename all files in a folder google colab

From Dev

Rename all files in folder to uppercase with batch

From Dev

rename all files and folder ftp in php language

From Dev

How to rename all the files in a folder in numeric order?

From Dev

Java convert camel case to underscore?

From Dev

How to individually rename the files in each separate folder in a batch file

From Dev

Send all files in folder as separate attachments

From Dev

tar + gz files from folder as is without to put inside all sub folder

From Dev

rename files in order from a folder using python

From Dev

How do I rename all files from folder to xxx{incremental}.jpg using command prompt

From Dev

How to rename(by adding a prefix) all the files and folders starting from the current folder?

From Dev

concatenate words from two separate files

From Dev

Is there a way to batch rename files to lowercase?

Related Related

  1. 1

    Transform all keys from `underscore` to `camel case` of json objects in circe

  2. 2

    How to rename folder from lowercase to uppercase in git

  3. 3

    How do I rename all files to lowercase?

  4. 4

    Rename files with spaces to underscore in all subcategories

  5. 5

    Rename all files in a folder in Ubuntu

  6. 6

    python rename all files in folder

  7. 7

    Python - Extracting all camel case words in a sequence

  8. 8

    Recursively rename all files and folders to Title Case from terminal

  9. 9

    Parsing string to separate words by upper case letter, hyphen, and underscore

  10. 10

    Extract text between two words from all files in a folder in R

  11. 11

    how to put all files from folder and subfolders into an array

  12. 12

    Batch rename files to lowercase

  13. 13

    Rename directories recursively from pascal or camel case to kebab case

  14. 14

    How do I rename all folders and files to lowercase on Linux?

  15. 15

    script to rename all files & directories into lowercase (including unicode)

  16. 16

    Rename all files within a folder prefixed with foldername

  17. 17

    How to rename all files in a folder google colab

  18. 18

    Rename all files in folder to uppercase with batch

  19. 19

    rename all files and folder ftp in php language

  20. 20

    How to rename all the files in a folder in numeric order?

  21. 21

    Java convert camel case to underscore?

  22. 22

    How to individually rename the files in each separate folder in a batch file

  23. 23

    Send all files in folder as separate attachments

  24. 24

    tar + gz files from folder as is without to put inside all sub folder

  25. 25

    rename files in order from a folder using python

  26. 26

    How do I rename all files from folder to xxx{incremental}.jpg using command prompt

  27. 27

    How to rename(by adding a prefix) all the files and folders starting from the current folder?

  28. 28

    concatenate words from two separate files

  29. 29

    Is there a way to batch rename files to lowercase?

HotTag

Archive