bash:files:rename_multiple_files
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
bash:files:rename_multiple_files [2021/01/26 12:32] – peter | bash:files:rename_multiple_files [2022/06/13 11:33] (current) – peter | ||
---|---|---|---|
Line 42: | Line 42: | ||
The actual documentation for the ' | The actual documentation for the ' | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Add an extension ===== | ||
+ | |||
+ | <code bash> | ||
+ | ls | ||
+ | file1 file2 file3 | ||
+ | </ | ||
+ | |||
+ | Add the extension " | ||
+ | |||
+ | <code bash> | ||
+ | for F in $(ls);do mv $F $F.txt;done | ||
+ | </ | ||
+ | |||
+ | Check the result: | ||
+ | |||
+ | <code bash> | ||
+ | ls | ||
+ | file1.rm file2.rm file3.rm | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Change the extension ===== | ||
+ | |||
+ | Change the extension from " | ||
+ | |||
+ | <code bash> | ||
+ | for F in $(ls);do mv $F $(echo $F|sed -e ' | ||
+ | </ | ||
+ | |||
+ | Check the result: | ||
+ | |||
+ | <code bash> | ||
+ | ls | ||
+ | file1.mp3 file2.mp3 file3.mp3 | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Remove the extension ===== | ||
+ | |||
+ | <code bash> | ||
+ | for F in $(ls);do mv $F $(echo $F|sed -e ' | ||
+ | </ | ||
+ | |||
+ | Check the result: | ||
+ | |||
+ | <code bash> | ||
+ | ls | ||
+ | file1 file2 file3 | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Only use ASCII characters ===== | ||
+ | |||
+ | <code bash> | ||
+ | find . -type f -exec bash -c 'for f do d=${f%/*} b=${f##*/} nb=${b// | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | <code bash> | ||
+ | find . -type d -exec bash -c 'for f do d=${f%/*} b=${f##*/} nb=${b// | ||
+ | </ | ||
+ | |||
+ | * NOTE the **echo** statement included, which just prints out the command that will be run. | ||
+ | * To actually do the move action, just remove the **echo** part. | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | <code bash> | ||
+ | find . -type d -exec bash -c 'for f do d=${f%/*} b=${f##*/} nb=${b// | ||
+ | </ | ||
</ | </ | ||
bash/files/rename_multiple_files.1611664355.txt.gz · Last modified: 2021/01/26 12:32 by peter