[英]linux - rename command to remove all text after final dash before extension in filename
我有以下格式的文件:
word1 word2 word3-6b3kZ3q2i.mp4
word-8x2u3p6b4.mkv
其中一些破折號不止一個。 它們都有一個名稱,后跟一個破折號和一個字母數字ID。
我想做的是從當前目錄中的每個文件名中刪除最后的破折號和其后的所有文本(文件擴展名除外)。
例如:將word1 word2 word3-6b3kZ3q2i.mp4
為word1 word2 word3.mp4
我嘗試過的所有類似問題的解決方案似乎都無效。 每當我在字符串中放置破折號以查找或替換時, rename
起作用。
有任何想法嗎?
假設您具有基於Perl的rename
命令,則可以使用以下rename
命令:
rename -n 's/-[^.-]+(?=\.)//' *.*
正則表達式分手:
- # match a hyphen
[^.-]+ # match 1 or more of any char that is not hyphen or dot
(?=\.) # lookahead to assert that next char is dot
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.