Posted By

alassiter on 03/10/11


Tagged

command unix linux line rename


Versions (?)

Rename files from command line


 / Published in: Bash
 

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.

  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
  3.  
  4. find . -name "*.rhtml" # List all files that end in .rhtml
  5. find . -type f # Find all regular files
  6.  
  7.  
  8. ## I can use wc (word count) with the -l flag to count the number of returned lines
  9.  
  10. find . -name "*.rhtml" | wc -l # Count the number of files that match
  11.  
  12.  
  13. ## I can then add a while and mv command to rename the files
  14.  
  15. find . -name "*.rhtml" | while read f; do mv ./"$f" "${f%rhtml}html.erb"; done

Report this snippet  

You need to login to post a comment.