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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.