Linux rename Regular Expressions
The rename command is mostly used to search a string and replace it with another string
Syntax:
Example:
Look at the above snapshot, all the ‘text’ are converted into ‘txt’.
You can also replace a string with the following syntax.
Syntax:
Example:
Look at the above snapshot, all ‘.txt’ are converted into ‘.TXT’.
In above two examples the strings used were present only at the end of the file name. But this example is different.
Example:
Look at the above snapshot, only the first occurence of sarched string is replaced.
A Global Replacement
In the above example only first ‘txt’ was replaced in ‘atxt.txt’. To replace both the ‘txt’ we can use a global replacement ‘g’.
Syntax:
Example:
Look at the above snapshot, both the ‘txt’ are replaced with ‘TXT’.
Case Insensitive Replacement
In case insensitive replacement, a string can be replaced with a case insensitive string.
Syntax:
Example:
Look at the above snapshot, all ‘.text’ are replaced with ‘.txt’.