I want to batch re-name a number of files in a directory so that the preceding number and hypen are stripped from the file name.
Old file name: 2904495-XXX_01_xxxx_20130730235001_00000000.NEW
New file name: XXX_01_xxxx_20130730235001_00000000.NEW
How can I do this with a linux command?
If the first numbers are always the same length:
The
${parameter:number}
does a substring expansion - takes the string starting at the 8th character.There are many other string edits available in expansions to handle other cases.
I think this command would better if you execute the command below:
Here
ls * - lists files in curent folder
sed -e - executes expression
p; - prints old file name
s/old-name/new-name/ - produce new filename
xargs -n2 - handles two arguments to mv
mv - gets two parameters and do move operation
Recommendation: before executing mv verify what you do is what you want to achieve with echo.
Following example renames
SCCF099_FG.gz5329223404623884757.tmp to
SCCF099_FG.gz
Using renamer (Windows, Mac and Linux friendly):
This will strip all numbers and first hyphen from the start of all files in the current directory.