公告
财富商城
积分规则
提问
发文
2019-01-04 15:29发布
Lonely孤独者°
In a directory, I have a bunch of *.html files.
*.html
I'd like to rename them all to *.txt
*.txt
I use the bash shell.
Here is what i used to rename .edge files to .blade.php
.edge
.blade.php
for file in *.edge; do mv "$file" "$(basename "$file" .edge).blade.php"; done
Works like charm.
If using bash, there's no need for external commands like sed, basename, rename, expr, etc.
for file in *.html do mv "$file" "${file%.html}.txt" done
If you prefer PERL, there is a short PERL script (orignally written by Larry Wall, the creator of PERL) that will do exactly what you want here: tips.webdesign10.com/files/rename.pl.txt. For your example the following should do the trick
rename.pl 's/html/txt/' *.html
= )
(Thanks @loretoparisi for the updated URL)
Try this
rename .html .txt *.html
usage:
rename [find] [replace_with] [criteria]
This question explicitly mentions Bash, but if you happen to have ZSH available it is pretty simple:
zmv '(*).*' '$1.txt'
If you get zsh: command not found: zmv then simply run:
zsh: command not found: zmv
autoload -U zmv
And then try again.
Thanks to this original article for the tip about zmv.
For Ubuntu Users :
rename 's/\.html$/\.txt/' *.html
最多设置5个标签!
Here is what i used to rename
.edge
files to.blade.php
Works like charm.
If using bash, there's no need for external commands like sed, basename, rename, expr, etc.
If you prefer PERL, there is a short PERL script (orignally written by Larry Wall, the creator of PERL) that will do exactly what you want here: tips.webdesign10.com/files/rename.pl.txt. For your example the following should do the trick
rename.pl 's/html/txt/' *.html
= )
(Thanks @loretoparisi for the updated URL)
Try this
usage:
This question explicitly mentions Bash, but if you happen to have ZSH available it is pretty simple:
If you get
zsh: command not found: zmv
then simply run:And then try again.
Thanks to this original article for the tip about zmv.
For Ubuntu Users :