

[Bash] List All Files in Directory Recursively and Rename
source link: http://siongui.github.io/2015/02/02/bash-list-files-recursively-and-rename/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Bash] List All Files in Directory Recursively and Rename
February 02, 2015
Question:
I have a lot of files under content/articles directory. The filenames are something like abc-def-ghi#en.rst. I want to rename them all and replace the # with %. For example, abc-def-ghi#en.rst will be renamed as abc-def-ghi%en.rst, how do I do it?
Answer:
list-files-recursively-rename.sh | repository | view raw
#!/bin/bash # list-files-recursively-rename.sh # List All Files in Directory Recursively and Rename count=0 # count the number of processed files # list all files recursively for file in $(find content/articles -type f) do # rename the file by replacing # with % new=`echo $file | sed 's/#/%/g'` if [ $file != $new ]; then count=$((count+=1)) echo "$count . $file => $new" # files are version controlled by Git, so use git mv git mv $file $new fi done
References:
[1]List all files in a directory recursively but exclude directories themselves
Recommend
-
43
Introduction How do you recursively get a list of all the files in a directory using Node.js ? Node.js has a built-in
-
36
无法访问此网站 gist.github.com 拒绝了我们的连接请求。 ...
-
16
List all files (recursively) in a directory yourbasic.org/golang Directory listing Use the ioutil.ReadDir function in package
-
13
Recursively fixing file and directory permissions Posted: 2011-12-13 - Last updated: 2019-06-05 Tagged
-
13
TypeOfNaNHow to find all files of a specific type recursively in LinuxNick Scialli • September 28, 2021 • 🚀 1 minute readThe find...
-
4
Regarding linux cp same directory Similar files in another directory and rename? advertisements I need copy some zip files(...
-
8
[Bash] Convert Files in Directory From Big5 to UTF-8 March 18, 2016...
-
4
Use du and sort command to list directory size in descending and ascending order. List Folder Size (Descending)
-
9
[Bash] Rename Files in Directory to Lowercase April 25, 2016 Convert the name of...
-
5
[Bash] Remove Execute Permission of Files in Directory Recursively ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK