示例文件:
1_this is_file one-xhdjsnsk.mp4
2_this_is file two-hdksbdg.mp4
3_this is_file three-hsislnsm.mp4
4_this is file four-gwywkkd.mp4
我如何删除从'-'
到 的所有内容'.'
,结果将如下所示:
1_this is_file one.mp4
2_this_is file two.mp4
3_this is_file three.mp4
4_this is file four.mp4
答案1
Perl 版本的rename
实用程序可以做到这一点(还有另一个名为它的程序,rename
它是程序包的一部分util-linux
)。例子:
$ touch '1_this is_file one-xhdjsnsk.mp4' '2_this_is file two-hdksbdg.mp4' '3_this is_file three-hsislnsm.mp4' '4_this is file four-gwywkkd.mp4'
$ ls -l
total 0
-rw-r--r-- 1 ja users 0 Feb 24 12:43 1_this is_file one-xhdjsnsk.mp4
-rw-r--r-- 1 ja users 0 Feb 24 12:43 2_this_is file two-hdksbdg.mp4
-rw-r--r-- 1 ja users 0 Feb 24 12:43 3_this is_file three-hsislnsm.mp4
-rw-r--r-- 1 ja users 0 Feb 24 12:43 4_this is file four-gwywkkd.mp4
$ perl-rename 's,\-.+\.,.,' *
$ ls -l
total 0
-rw-r--r-- 1 ja users 0 Feb 24 12:43 1_this is_file one.mp4
-rw-r--r-- 1 ja users 0 Feb 24 12:43 2_this_is file two.mp4
-rw-r--r-- 1 ja users 0 Feb 24 12:43 3_this is_file three.mp4
-rw-r--r-- 1 ja users 0 Feb 24 12:43 4_this is file four.mp4
rename
程序在您的系统上的名称可能有所不同,例如在 Ubuntu 上它是file-rename
.