Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have the <code>rename</code> command on your UNIX, you should be able to use something like:</p> <pre><code>mkdir images_renamed cd images_renamed cp ../103*.jpg . rename 103 201003 *.jpg </code></pre> <p>The <code>rename FROM TO FILE</code> will rename all the files specified by <code>FILE</code>, changing the first occurrence of <code>FROM</code> to <code>TO</code>.</p> <p>If that's not available, you can use something like:</p> <pre><code>mkdir images_renamed for fspec in 103*.jpg ; do cp ${fspec} images_renamed/201003${fspec:3} done </code></pre> <p>To do this recursively, I would put it into a script with <code>find</code>:</p> <pre><code>#!/usr/bin/bash rm -rf images_renamed ls -lR images echo cd images find . -name '*.jpg' | while read -r; do mkdir -p "../images_renamed/$(dirname "$REPLY")" echo 'Copying from' [$REPLY] echo ' to' [../images_renamed/$REPLY] and renaming. echo cp "$REPLY" "../images_renamed/$REPLY" cd "$(dirname "../images_renamed/$REPLY")" rename 103 201003 "$(basename "$REPLY")" cd - &gt;/dev/null done cd .. ls -lR images_renamed </code></pre> <p>Only the middle bit of that is required, the rest is for testing. The output below shows how it works, copying across every file to the new directory structure and renaming the relevant files.</p> <pre><code>images: total 0 drwxr-xr-x+ 1 pax None 0 2010-08-12 20:55 dir1 drwxr-xr-x+ 1 pax None 0 2010-08-12 20:55 dir2 drwxr-xr-x+ 1 pax None 0 2010-08-12 20:56 dir3 images/dir1: total 0 -rw-r--r-- 1 pax None 0 2010-08-12 20:55 102xxx.jpg -rw-r--r-- 1 pax None 0 2010-08-12 20:55 103xxx.jpg images/dir2: total 0 -rw-r--r-- 1 pax None 0 2010-08-12 20:55 103yyy.jpg images/dir3: total 0 drwxr-xr-x+ 1 pax None 0 2010-08-12 20:55 dir 4 images/dir3/dir 4: total 0 -rw-r--r-- 1 pax None 0 2010-08-12 20:55 103zzz.jpg Copying from [./dir1/102xxx.jpg] to [../images_renamed/./dir1/102xxx.jpg] and renaming. Copying from [./dir1/103xxx.jpg] to [../images_renamed/./dir1/103xxx.jpg] and renaming. Copying from [./dir2/103yyy.jpg] to [../images_renamed/./dir2/103yyy.jpg] and renaming. Copying from [./dir3/dir 4/103zzz.jpg] to [../images_renamed/./dir3/dir 4/103zzz.jpg] and renaming. images_renamed: total 0 drwxr-xr-x+ 1 pax None 0 2010-08-12 21:19 dir1 drwxr-xr-x+ 1 pax None 0 2010-08-12 21:19 dir2 drwxr-xr-x+ 1 pax None 0 2010-08-12 21:19 dir3 images_renamed/dir1: total 0 -rw-r--r-- 1 pax None 0 2010-08-12 21:19 102xxx.jpg -rw-r--r-- 1 pax None 0 2010-08-12 21:19 201003xxx.jpg images_renamed/dir2: total 0 -rw-r--r-- 1 pax None 0 2010-08-12 21:19 201003yyy.jpg images_renamed/dir3: total 0 drwxr-xr-x+ 1 pax None 0 2010-08-12 21:19 dir 4 images_renamed/dir3/dir 4: total 0 -rw-r--r-- 1 pax None 0 2010-08-12 21:19 201003zzz.jpg </code></pre> <hr> <p>To flatten the file hierarchy, you can use something like:</p> <pre><code>#!/usr/bin/bash rm -rf images_renamed ls -lR images echo cd images mkdir -p ../images_renamed find . -name '*.jpg' | while read -r; do newfile="$(basename "$REPLY")" echo 'Copying from' [$REPLY] echo ' to' [../images_renamed/$newfile] and renaming. echo cp "$REPLY" "../images_renamed/$newfile" cd ../images_renamed rename 103 201003 "$newfile" cd - &gt;/dev/null done </code></pre> <p>which outputs:</p> <pre><code>cd .. ls -lR images_renamed images: total 0 drwxr-xr-x+ 1 allan None 0 2010-08-12 20:55 dir1 drwxr-xr-x+ 1 allan None 0 2010-08-12 20:55 dir2 drwxr-xr-x+ 1 allan None 0 2010-08-12 20:56 dir3 images/dir1: total 0 -rw-r--r-- 1 allan None 0 2010-08-12 20:55 102xxx.jpg -rw-r--r-- 1 allan None 0 2010-08-12 20:55 103xxx.jpg images/dir2: total 0 -rw-r--r-- 1 allan None 0 2010-08-12 20:55 103yyy.jpg images/dir3: total 0 drwxr-xr-x+ 1 allan None 0 2010-08-12 20:55 dir 4 images/dir3/dir 4: total 0 -rw-r--r-- 1 allan None 0 2010-08-12 20:55 103zzz.jpg Copying from [./dir1/102xxx.jpg] to [../images_renamed/102xxx.jpg] and renaming. Copying from [./dir1/103xxx.jpg] to [../images_renamed/103xxx.jpg] and renaming. Copying from [./dir2/103yyy.jpg] to [../images_renamed/103yyy.jpg] and renaming. Copying from [./dir3/dir 4/103zzz.jpg] to [../images_renamed/103zzz.jpg] and renaming. images_renamed: total 0 -rw-r--r-- 1 allan None 0 2010-08-12 22:41 102xxx.jpg -rw-r--r-- 1 allan None 0 2010-08-12 22:41 201003xxx.jpg -rw-r--r-- 1 allan None 0 2010-08-12 22:41 201003yyy.jpg -rw-r--r-- 1 allan None 0 2010-08-12 22:41 201003zzz.jpg </code></pre> <p>but you need to keep in mind that filename clashes (the same file name under different directories) will overwrite each other.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload