User Tools

Site Tools


ubuntu:file:rename_multiple_files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ubuntu:file:rename_multiple_files [2022/03/26 11:38] peterubuntu:file:rename_multiple_files [2022/06/13 11:32] (current) – removed peter
Line 1: Line 1:
-====== Ubuntu - File - Rename multiple files ====== 
- 
-===== Add an extension ===== 
- 
-<code bash> 
-ls 
-file1 file2 file3 
-</code> 
- 
-Add the extension ".txt" 
- 
-<code bash> 
-for F in $(ls);do mv $F $F.txt;done 
-</code> 
- 
-Check the result: 
- 
-<code bash> 
-ls 
-file1.rm file2.rm file3.rm 
-</code> 
- 
----- 
- 
-===== Change the extension ===== 
- 
-Change the extension from ".txt" to ".mp3": 
- 
-<code bash> 
-for F in $(ls);do mv $F $(echo $F|sed -e 's,\.rm,,').mp3 ;done 
-</code> 
- 
-Check the result: 
- 
-<code bash> 
-ls 
-file1.mp3 file2.mp3 file3.mp3 
-</code> 
- 
----- 
- 
-===== Remove the extension ===== 
- 
-<code bash> 
-for F in $(ls);do mv $F $(echo $F|sed -e 's,\.mp3,,') ;done 
-</code> 
- 
-Check the result: 
- 
-<code bash> 
-ls 
-file1 file2 file3 
-</code> 
- 
----- 
- 
-===== Only use ASCII characters ===== 
- 
-<code bash> 
-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' _ {} + 
-</code> 
- 
-<WRAP info> 
-**NOTE:  To test, use 
- 
-<code bash> 
-find . -type d -exec bash -c 'for f do d=${f%/*} b=${f##*/} nb=${b//[^A-Za-z0-9._-]/_}; [[ $b = "$nb" ]] || echo mv "$f" "$d/$nb"; done' _ {} + 
-</code> 
- 
-  * NOTE the **echo** statement included. 
-    * To actually do the action, just remove the **echo** part. 
- 
-</WRAP> 
- 
- 
-<WRAP info> 
-**NOTE:  For directories use 
- 
-<code bash> 
-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' _ {} + 
-</code> 
- 
-</WRAP> 
  
ubuntu/file/rename_multiple_files.1648294738.txt.gz · Last modified: 2022/03/26 11:38 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki