Skip to main content

Posts

Showing posts from December, 2013

Popular Rename Technics

Popular Batch Rename Technics in Linux

- using command :

for f in *; do mv -v "$f" "{prefix}$f"; done

for f in *; do mv -v "$f" "$f{suffix}"; done

 using rename .pl

 rename "expression1" "expression2" *.ext 

  ex: rename file1.mp3, file2.mp3...... to 1.mp3,2.mp3......

rename "file" ""  *.mp3


- using php

limit the filename to 20 characters

if ($handle = opendir('/path/to/files')) {
    while (false !== ($fileName = readdir($handle))) {
        $newName = substr($fileName,0,20);
        rename($fileName, $newName);
    }
    closedir($handle);
}

delete the last 4 characters of filename for all files



if ($handle = opendir('/path/to/files')) {
    while (false !== ($fileName = readdir($handle))) {
        $newName = substr($fileName,0,-4);
        rename($fileName, $newName);
    }
    closedir($handle);
}

rename all .ext files eg: rename all .mp3 files to song_*.mp3

if ($handle = opendir('./')) {
    while (fal…