Results 1 to 3 of 3

Thread: batch remove the last 9 characters from folders names?

  1. #1
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    batch remove the last 9 characters from folders names?

    Hello, How can I batch remove the last 9 characters from folders names?

    for example I have many folders as follows

    jhgtyuioplgdrtghnbjk after will be jhgtyuioplg

    yt00:hnbfdkk ioiuyui after will be yt00:hnbfdk

    qw jh dd0ddyyt:jkopi after will be qw jh dd0dd

    thanks

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: batch remove the last 9 characters from folders names?

    Code:
    for d in *; do mv "$d" "${d%?????????}"; done
    or
    Code:
    rename 's/.{9}$//' *
    if the folders are mixed with files, then some condition to narrow down is required eg
    Code:
    [[ -d "$d" ]] || continue

    edit: it's possible to glob dirs only with */ but it would require accounting for that additional char (eg 10x'?' / .{10})
    Last edited by Vaphell; October 7th, 2014 at 04:09 PM.
    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

  3. #3
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    Re: batch remove the last 9 characters from folders names?

    perfect. thanks

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
  •