R you looking for shell script which rename all files in a directory to replace unnecssery spaces in file names with -. Check following BASH shell script which,
1. Iterate a perticular directory specified in FILES variable.
2. Replaces spaces with - hyphen, and put it in temparary variable new_file. (sed "s/ /-/g"`)
4. Then simple MV command to rename it.
- #!/bin/bash
- FILES=/path/to/dir/*
- for f in $FILES
- do
- new_file=`echo $f|sed "s/ /-/g"`
- if [ "$f" != "$new_file" ]
- then
- mv "$f" "$new_file"
- fi
- done
- exit 0
0 comments:
Post a Comment