Rename files from command line

/ Published in: Bash
Save to your folder(s)

A couple of snippets useful for file management. I use these to make sure I understand how many files I'm about to modify, and then rename them.

Copy this code and paste it in your HTML
  1. ## Use find to search for the files I want recursively from the current path
  2. ## Powerful utility, man find to read the man pages
  4. find . -name "*.rhtml" # List all files that end in .rhtml
  5. find . -type f # Find all regular files
  8. ## I can use wc (word count) with the -l flag to count the number of returned lines
  10. find . -name "*.rhtml" | wc -l # Count the number of files that match
  13. ## I can then add a while and mv command to rename the files
  15. find . -name "*.rhtml" | while read f; do mv ./"$f" "${f%rhtml}html.erb"; done

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.