Need Windows scripts conversion for Linux environment...


Results 1 to 5 of 5

Thread: Need Windows scripts conversion for Linux environment...

  1. #1
    Join Date
    Feb 2009
    Posts
    42

    Need Windows scripts conversion for Linux environment...

    I have a script that I use often in Windows, for renaming files.

    Specifically, the script removes the first couple of digits from system files, and leaves the last 2 digits -

    HPIM_00.jpg,
    HPIM_01.jpg,
    HPIM_02.jpg, etc., ...

    and gives

    00.jpg
    01.jpg
    02.jpg, etc., ...

    This is the script in 'Windese':
    Setlocal EnableDelayedExpansion



    PushD "J:\home\chuck-04d0\Desktop\Beach"

    For /F "Tokens=1 Delims=" %%I In ('dir /A-D /B IMG_*.JPG') Do (

    Set _tmp=%%I

    Set _tmp=!_tmp:~1!

    Ren "%%I" "!_tmp! "

    )

    PopD



    What would it look like in Torvaldese???

  2. #2
    Join Date
    Sep 1999
    Posts
    3,202
    Code:
    for i in `ls -1 *.[jJ][pP][gG]`
    do
      newfilename=`echo $i | cut -f 2 -d \_`
      mv $i $newfilename
    done
    Or similar should do it ... or at least get you started.

  3. #3
    Join Date
    Feb 2009
    Posts
    42
    Thanks there ph34r...

    Is the script, as you posted it, the entire contents of the script file?

    What will be the file extension?

    Thanks again there...

  4. #4
    Join Date
    Sep 1999
    Posts
    3,202
    Quote Originally Posted by buccaneere View Post
    Thanks there ph34r...

    Is the script, as you posted it, the entire contents of the script file?

    What will be the file extension?

    Thanks again there...
    Missing the first line - should start with

    #!/bin/bash

    Linux doesn't care about extensions - just make the script executable.

  5. #5
    Join Date
    Feb 2009
    Posts
    42
    How do I target ONLY files in a particular folder - using my earlier example, for instance...

    J:\home\chuck-04d0\Desktop\Beach

    What is ls -l ?

    Thanks again...

Posting Permissions

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