ファイル名の一部を削除

ファイル名の一部を削除

サンプルファイル:

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他のプログラムがあります)。例:renameutil-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

おすすめ記事