Skip to content

Instantly share code, notes, and snippets.

@Buravo46
Last active May 19, 2016 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Buravo46/924e68128f88ea86e91022da1c818114 to your computer and use it in GitHub Desktop.
Save Buravo46/924e68128f88ea86e91022da1c818114 to your computer and use it in GitHub Desktop.
拡張子を一括置換で変更

下記で拡張子の置換可能

for fname in *.<<置換前の拡張子>>; do mv $fname ${fname%.<<置換前の拡張子>>}<<置換後の拡張子>>; done

${fname%.<<置換前の拡張子>>}は、最短後置パターンの削除をしている。

詳細は下記を参照する。

http://qiita.com/bsdhack/items/597eb7daee4a8b3276ba

具体例

for fname in *.bad; do mv $fname ${fname%.bad}""; done

証跡

[Thu May 19 23:00:01.845 2016] Last login: Sun Apr 24 23:42:44 2016 from gateway
[Thu May 19 23:00:01.901 2016] [root@localhost ~]# 
[Thu May 19 23:00:04.276 2016] [root@localhost ~]# ll
[Thu May 19 23:00:05.340 2016] 合計 12
[Thu May 19 23:00:05.340 2016] -rw-------. 1 root root 938  2月 21 10:07 anaconda-ks.cfg
[Thu May 19 23:00:05.340 2016] -rw-r--r--. 1 root root 142  4月 24 23:33 change-extension.sh
[Thu May 19 23:00:05.340 2016] drwxr-xr-x. 3 root root  19  3月  5 18:31 github
[Thu May 19 23:00:05.340 2016] -rw-r--r--. 1 root root 505  3月  6 18:57 setting.sh
[Thu May 19 23:00:05.340 2016] [root@localhost ~]# 
[Thu May 19 23:00:05.756 2016] [root@localhost ~]# touch test.bad
[Thu May 19 23:00:15.805 2016] [root@localhost ~]# 
[Thu May 19 23:00:16.268 2016] [root@localhost ~]# touch test.test.bad
[Thu May 19 23:00:24.247 2016] [root@localhost ~]# 
[Thu May 19 23:00:24.843 2016] [root@localhost ~]# ll
[Thu May 19 23:00:27.867 2016] 合計 12
[Thu May 19 23:00:27.867 2016] -rw-------. 1 root root 938  2月 21 10:07 anaconda-ks.cfg
[Thu May 19 23:00:27.867 2016] -rw-r--r--. 1 root root 142  4月 24 23:33 change-extension.sh
[Thu May 19 23:00:27.867 2016] drwxr-xr-x. 3 root root  19  3月  5 18:31 github
[Thu May 19 23:00:27.867 2016] -rw-r--r--. 1 root root 505  3月  6 18:57 setting.sh
[Thu May 19 23:00:27.867 2016] -rw-r--r--. 1 root root   0  4月 24 23:53 test.bad
[Thu May 19 23:00:27.867 2016] -rw-r--r--. 1 root root   0  4月 24 23:53 test.test.bad
[Thu May 19 23:00:27.867 2016] [root@localhost ~]# 
[Thu May 19 23:00:28.417 2016] [root@localhost ~]# for fname in *.bad; do mv $fname ${fname%.bad}""; done
[Thu May 19 23:00:44.685 2016] [root@localhost ~]# 
[Thu May 19 23:00:45.121 2016] [root@localhost ~]# ll
[Thu May 19 23:00:46.978 2016] 合計 12
[Thu May 19 23:00:46.978 2016] -rw-------. 1 root root 938  2月 21 10:07 anaconda-ks.cfg
[Thu May 19 23:00:46.978 2016] -rw-r--r--. 1 root root 142  4月 24 23:33 change-extension.sh
[Thu May 19 23:00:46.978 2016] drwxr-xr-x. 3 root root  19  3月  5 18:31 github
[Thu May 19 23:00:46.978 2016] -rw-r--r--. 1 root root 505  3月  6 18:57 setting.sh
[Thu May 19 23:00:46.978 2016] -rw-r--r--. 1 root root   0  4月 24 23:53 test
[Thu May 19 23:00:46.978 2016] -rw-r--r--. 1 root root   0  4月 24 23:53 test.test
[Thu May 19 23:00:46.978 2016] [root@localhost ~]# 
[Thu May 19 23:00:47.556 2016] [root@localhost ~]# exit
[Thu May 19 23:00:52.030 2016] ログアウト
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment