Change filenames to lowercase in Ubuntu in all subdirectories [closed]

北城以北 提交于 2019-12-18 11:04:39

问题


I know it's been asked but what I've found has not worked out so far. The closet I came is this : rename -n 'y[A-Z]/[a-z]/' * which works for the current directory. I'm not too good at Linux terminal so what should I add to this command to apply it to all of the files in all the sub-directories from which I am in, thanks!


回答1:


Here's one way using find and tr:

for i in $(find . -type f -name "*[A-Z]*"); do mv "$i" "$(echo $i | tr A-Z a-z)"; done

Edit; added: -name "*[A-Z]*"

This ensures that only files with capital letters are found. For example, if files with only lowercase letters are found and moved to the same file, mv will display the are the same file error.




回答2:


Perl has a locale-aware lc() function which might work better:

find . -type f | perl -n -e 'chomp; system("mv", $_, lc($_))'

Note that this script handles whitespace in filenames, but not newlines. And there's no protection against collisions, if you have "ASDF.txt" and "asdf.txt" one is going to get clobbered.



来源:https://stackoverflow.com/questions/13051871/change-filenames-to-lowercase-in-ubuntu-in-all-subdirectories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!