Need some help with basic some command line commands

Discussion in 'Programming/Scripts' started by Ovidiu, Jul 24, 2014.

  1. Ovidiu

    Ovidiu Active Member

    Warning: extreme newbie question!
    I decided to ask it here as I've tried countless different commands and can't get this done but I'm sure some linux cli guru can figure this out in a few minutes.

    I need a command that checks a folder for files (there will always only be two there and renames them.

    i.e.
    vzdump-qemu-105-2014_07_24-18_23_31.vma and
    vzdump-qemu-105-2014_07_24-18_23_31.log

    should get renamed to:
    vzdump-qemu-105.vma and
    vzdump-qemu-105.log

    My initial start was something like this but I can't get it right:
    Any help please?
     
  2. Watael

    Watael New Member

    hi,

    a bit late probably
    Code:
    $ mkdir vz
    $ touch vz/vzdump-qemu-105-2014_07_24-18_23_31.vma vz/vzdump-qemu-105-2014_07_24-18_23_31.log 
    $ rename -n 's/(vzdump-qemu-105)-2014_07_24-18_23_31(.*)/$1$2/' vz/*
    vz/vzdump-qemu-105-2014_07_24-18_23_31.log renamed as vz/vzdump-qemu-105.log
    vz/vzdump-qemu-105-2014_07_24-18_23_31.vma renamed as vz/vzdump-qemu-105.vma
    if it's ok, then remove the -n option.
     

Share This Page