In a directory, I have a bunch of *.html
files. I'd like to rename them all to *.txt
How can I do that? I use the bash shell.
You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.
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
For an better solution (with only bash functionality, as opposed to external calls), see one of the other answers.
The following would do and does not require the system to have the rename
program (although you would most often have this on a system):
for file in *.html; do mv "$file" "$(basename "$file" .html).txt" done
EDIT: As pointed out in the comments, this does not work for filenames with spaces in them without proper quoting (now added above). When working purely on your own files that you know do not have spaces in the filenames this will work but whenever you write something that may be reused at a later time, do not skip proper quoting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With