bash - How do I truncate the last two characters of all files in a directory? -


so pretty simple question. of files in directory of form 6bfefb348d746eca288c6d62f6ebec04_0.jpg. want them 6bfefb348d746eca288c6d62f6ebec04.jpg. essentially, want take off _0 @ end of every file name. how go doing bash?

with perl's standalone rename command:

rename -n 's/..(\....)$/$1/' * 

if looks fine, remove -n.


it possible use standalone rename command syntax similar sed's s/regexp/replacement/ command. in regex . matches 1 character. \. matches . , $ matches end of line (here end of filename). ( , ) special characters in regex mark subexpression (here 1 . , 3 characters @ end of filename) can reused $1. sed uses \1 first back-reference, rename uses $1.

see: back-references , subexpressions sed


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -