Results 1 to 4 of 4

Thread: Advance command for file rename

  1. #1
    Join Date
    Oct 2010
    Beans
    Hidden!

    Advance command for file rename

    Hello all,

    I am trying to rename files from "long file name.mkv" to "long file name - HD.mkv" in terminal. If the statement is true. any suggestions how can I do this?

  2. #2
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Advance command for file rename

    Quote Originally Posted by Deepak Jindal View Post
    Hello all,

    I am trying to rename files from "long file name.mkv" to "long file name - HD.mkv" in terminal. If the statement is true. any suggestions how can I do this?
    On a terminal please do this .

    Code:
    mv "long file name.mkv" "long file name - HD.mkv"
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  3. #3
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Advance command for file rename

    OK i re-read your post and seems like you want to rename files in batch .
    I have tried to write up the below .

    Code:
    #!/bin/bash
    
    
    for i in  *.dat
    do
            fname=${i%.*}
            renamed="$fname"" - HD.mkv"
            mv $i "$renamed"
    done
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  4. #4
    Join Date
    May 2009
    Location
    Courtenay, BC, Canada
    Beans
    1,661

    Re: Advance command for file rename

    Code:
    rename -n 's|.mkv$| - HD.mkv|' *
    once youre comfortable with the output, remove the -n and it will rename the files
    Last edited by HiImTye; June 23rd, 2012 at 02:53 PM. Reason: added a space before the '-' for proper output

Tags for this Thread

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
  •