rename file code example
Example 1: linux change file name
mv oldfile.txt newfile.txt
Example 2: how to rename a file in terminal
mv "old location" "new location"
mv /home/user/my_static /home/user/static
mv "file1.ext" "file2.ext"
Example 3: batch rename folders
REM
REM
REM
REM
REM
@echo off
setlocal EnableDelayedExpansion
set "pattern_to_replace= "
set "replace_text=_"
for /d %%N in ("*") do (
set "InitName=%%N"
call set NewName=%%InitName:!pattern_to_replace!=!replace_text!%%
if NOT !InitName!==!NewName! (
echo rename "!InitName!" "!NewName!"
rename "!InitName!" "!NewName!"
)
)
@echo on
REM
REM
REM
@echo off
setlocal EnableDelayedExpansion
set "pattern_to_replace= "
set "replace_text=_"
for /d /R "%cd%" %%N in ("*") do (
set "InitName=%%~nN%%~xN"
call set NewName=%%InitName:!pattern_to_replace!=!replace_text!%%
if NOT %%N==%%~dN%%~pN!NewName! (
echo rename "%%~dN%%~pN!InitName!" "!NewName!"
rename "%%~dN%%~pN!InitName!" "!NewName!"
)
)
@echo on
REM
Example 4: rename multiple files linux
rename 's/old-name/new-name/' files
Example 5: batch rename file
REM
rename "C:/Users/JacquesK/ChangeMyName.txt" "NameChanged.csv"
REM
REM
Example 6: batch rename folder
REM
rename "C:/Users/JacquesK/ChangeMyName" "NameChanged"
REM
REM