Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Help with Directory Structure Naming

  1. #11
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,303
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Directory Structure Naming

    this is just an example what is supposed to happen if you have duplicates.
    cp -v is copying in verbose mode and you get to see something along the lines of
    Code:
    `./dir1/samefile' -> `./samefile' (backup: `./samefile.~1~')
    in its output.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  2. #12
    Join Date
    Apr 2012
    Beans
    5,357

    Re: Help with Directory Structure Naming

    yes my apologies - those other lines are just the verbose output from cp because I added the -v switch (just to show you the steps it was doing)

    For your case, you'd probably want to keep your current command but just add the --backup=numbered parameter

    Code:
    find /home/dad/Desktop/old -type f -exec cp --backup=numbered {} /home/dad/Desktop/new/ \;
    If you have LOTS of files you might want to consider using a form that handles long argument lists a bit more robustly, either

    Code:
    $ while read -r -d $'\0' file; do cp --backup=numbered "$file" /home/dad/Desktop/new/ ; done < <(find /home/dad/Desktop/old -type f -print0)
    or

    Code:
    find /home/dad/Desktop/old -type f -print0 | xargs -0 cp --backup=numbered -t /home/dad/Desktop/new/

  3. #13
    Join Date
    Oct 2008
    Location
    UK
    Beans
    1,079
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Help with Directory Structure Naming

    I've done some work and I think I am 'there' but I still need some help -if that's OK. In old I have 6530 items of which 258 are directories. So after running the command I should get 6272 items/photos in new. When I run all three versions of your command I get in new 4726 jpg photos and 1546 files in the form xxxx.jpg~1~ so the command is working - in new I get 6272 items. For example in old I have 4 different photos, with the same file name called DSCF0012.jpg. After I run the command I get in new DSCF0012.jpg, DSCF0012.jpg~1~, DSCF0012~2~, DSCF0012.jpg~3~. In nautilus I can see the image of DSCF0012.jpg but the other 3 ~x~ files are shown with a text type icon (see attached). I guess I need a new command to change these ~x~ into something like DSCF00121, DSCF00122, DSCF00123. I have 1546 of these files - and they are all unique file name wise.
    Attached Images Attached Images

  4. #14
    Join Date
    Apr 2012
    Beans
    5,357

    Re: Help with Directory Structure Naming

    You can probably just bulk rename those using the perl-based 'rename' command so that they have the correct .jpg suffix - something like

    Code:
    $ rename -vn 's/\.jpg\.~([0-9]+)~/-$1.jpg/' *.jpg.*
    The '-vn' switches make it report what it would do but not actually do it - once you have checked that it does the right thing you can remove the 'n' - it should produce something like

    Code:
    file.jpg.~1~ renamed as file-1.jpg
    file.jpg.~2~ renamed as file-2.jpg
    file.jpg.~3~ renamed as file-3.jpg
    We can play with the replacement name format if file-N.jpg is not to your liking

  5. #15
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,303
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Help with Directory Structure Naming

    try this
    Code:
    rename -nv 's/(.+)[.](.+)[.]~(.+)~/$1$3.$2/' *~?~
    n means dry run, if you are sure proposed names are ok, remove that n from the parameter.

    oops, too late
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  6. #16
    Join Date
    Apr 2012
    Beans
    5,357

    Re: Help with Directory Structure Naming

    Quote Originally Posted by Vaphell View Post
    oops, too late
    but more elegant - as always

  7. #17
    Join Date
    Oct 2008
    Location
    UK
    Beans
    1,079
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Help with Directory Structure Naming

    Done it - thank you so much for all your help. I believe your solutions will help a lot of people.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •