There is a list of folders:

2014-12-17 2014-12-21 2014-12-22 2014-12-23 2015-01-13 2015-01-14 2015-01-15 2015-01-16 2015-01-17 

How to archive folders whose names begin with "2014" with the creation of a single archive, or, with the creation of multiple archives, the names of which coincide with the name of the folders? Thank.

    3 answers 3

    Pack folders starting with the year number in the archive with the name of this year number:

     #!/bin/bash for year in {2012..2016} do zip -r $year $year-* >/dev/null 2>&1 done 

    The output is 2012.zip 2013.zip, etc.

    • what will be the output? I am not strong in scripts. thanks - Jenkamen
    • and how without displaying the added files in the console? 5 thousand 150 kb each in each folder - Jenkamen
    • @mee, this is written in the man-e to this program (you can execute the $ man zip command and read). This option is called (like many other programs) -q . - aleksandr barakin
    • And how each folder in your archive? - Jenkamen
     #!/bin/bash for y in {2016} do for m in {1} do for d in {1..9} do zip -r $y-$m-$d $y-0$m-0$d >/dev/null 2>&1 done for d in {10..31} do zip -r $y-$m-$d $y-0$m-$d >/dev/null 2>&1 done done done 

    Saved and named the file scr.sh. How to run it now?

    • one
      Give him the right to execute chmod + x scr.sh, and launching ./scr.sh if from the same directory with the script, or through the full path to it - carapuz
    • nothing happens after the command ./scr.sh - Jenkamen
     for i in `ls -1`; do zip $i.zip $i; done 
    • echo `$i` - what do you think should happen here? why do you need the `ls -1` if only * enough? and where is the semicolon between for and do ? probably you did not try to run what you propose. - aleksandr barakin
    • @alexanderbarakin I corrected a syntax error, tested it. for echo $i it was assumed that the name of the directory would be displayed before archiving, but in practice it turned out that zip can display the output of what was added to the archive. It looks like this: # adding: 2014-12-22/ (stored 0%) - Dmitrii