Monday, April 23, 2012

Linux: Rename Expression To Remove First Character From a File Name

I've over 1000's of files starting with _ character as follows:
_file1.txt
_foo1.txt
_2424.txt
_bar10000.txt
How do I remove the first character from a file name:
file1.txt
foo1.txt
2424.txt
bar10000.txt

You can use the rename command as described in our previous faq. The syntax is as follows:
 
rename "s/regex-rule/replace/g" *.files
 
To remove _ first character and rename all *.txt files, enter:
 
rename -v "s/^_//g" *.txt
 
Use the ls command to verify the same:
$ ls -l

No comments:

Post a Comment