ubuntu:file:rename_multiple_files
This is an old revision of the document!
Table of Contents
Ubuntu - File - Rename multiple files
Add an extension
ls
file1 file2 file3
Add the extension “.txt”
for F in $(ls);do mv $F $F.txt;done
Check the result:
ls
file1.rm file2.rm file3.rm
Change the extension
Change the extension from “.txt” to “.mp3”:
for F in $(ls);do mv $F $(echo $F|sed -e 's,\.rm,,').mp3 ;done
Check the result:
ls
file1.mp3 file2.mp3 file3.mp3
Remove the extension
for F in $(ls);do mv $F $(echo $F|sed -e 's,\.mp3,,') ;done
Check the result:
ls
file1 file2 file3
Only use ASCII characters
find . -type f -exec bash -c 'for f do d=${f%/*} b=${f##*/} nb=${b//[^A-Za-z0-9._-]/_}; [[ $b = "$nb" ]] || mv "$f" "$d/$nb"; done' _ {} +
**NOTE: For directories use
find . -type d -exec bash -c 'for f do d=${f%/*} b=${f##*/} nb=${b//[^A-Za-z0-9._-]/_}; [[ $b = "$nb" ]] || mv "$f" "$d/$nb"; done' _ {} +
ubuntu/file/rename_multiple_files.1648294658.txt.gz · Last modified: 2022/03/26 11:37 by peter