How is it right to create zip scrip in ubuntu?



  • There are some files, such as:

    /mnt/up/4534453.bak

    /mnt/up/rtytr45345.bak

    /mnt/up/cvbf5545ff.bak

    We need to get this:

    /mnt/backup/453434453.zip

    /mnt/backup/rtytr45345.zip

    /mnt/backup/cvbf5545ff.zip



  • If you need to keep the souffix .bakSo...

    #!/bin/bash
    

    for f in /mnt/up/*.bak
    do
    zip /mnt/backup/basename $f.zip $f
    done

    If you need to clean up, for example:

    #!/bin/bash

    for f in /mnt/up/*.bak
    do
    zip /mnt/backup/basename $f .bak.zip $f
    done

    It can be painted, without use basenameonly by means bash♪ With the maintenance of the souffix .bak

    #!/bin/bash

    for f in /mnt/up/.bak
    do
    echo $f
    zip /mnt/backup/${f##
    /}.zip $f
    done

    and without

    #!/bin/bash

    for f in /mnt/up/.bak
    do
    ff=${f##
    /}
    zip /mnt/backup/${ff%.*}.zip $f
    done


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2