Created
May 25, 2016 08:57
-
-
Save batigolix/81a6ccf596f1b5529991ba4e44f61b58 to your computer and use it in GitHub Desktop.
Rename files folder and strings in files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To quickly start with a new custom module is can be convenient to copy an exisiting. But you then need a quick way to rename files, folders and string within files. | |
##Rename files and folders | |
Look for files that contain STRINGTOLOOKFOR in name: | |
`find . -name "STRINGTOLOOKFOR*" -exec rename -v 's/STRINGTOLOOKFOR/STRINGTOREPLACEWITH/i' {} \;` | |
For example: | |
`find . -name "bcca_tools*" -exec rename -v 's/bcca_tools/project_tools/i' {} \;` | |
## Rename strings inside files | |
cd into folder that holds the files: | |
`cd project_tools/` | |
Replace all occurences of 'STRINGTOLOOKFOR' with 'STRINGTOREPLACEWITH' | |
`find ./ -type f -exec sed -i 's/STRINGTOLOOKFOR/STRINGTOREPLACEWITH/i' {} \;` | |
For example: | |
`find ./ -type f -exec sed -i 's/bcca_tools/project_tools/i' {} \;` | |
## Cleanup filenames | |
bash script to clean up filenames | |
#! /bin/bash | |
find ./ -name "* *" -type f | rename 's/_/-/g' | |
find ./ -name "* *" -type f | rename 's/ /-/g' | |
for f in *; do mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done | |
find ./ -type f -exec bash -c 'mv "$1" "$(iconv -f UTF8 -t ASCII//TRANSLIT <<< $1)"' -- {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment