2015年11月26日 星期四

016 creative zip file (linux shell)

How to Create Zip File in a Creative Way

Step 1. prepare the original file valuable to you.

// for  example, and, as many times as you want
echo work smart play hard >> treasure.txt



Step 2. try to zip it first manually

zip 1.zip treasure.txt

Step 3. use shell script to play number in loop

for now in {1..10}; do next=`expr $now + 1`; echo $next $now; done

Step 4. use above shell script to play with zip

for now in {1..10}; do next=`expr $now + 1`; zip $next.zip $now.zip; done

by the way, if you want to keep the last zip only

for now in {1..10}; do next=`expr $now + 1`; zip $next.zip $now.zip; rm $now.zip; done

Step 5. now you get the 11.zip, which contains 10.zip; you can have a look on it by

unzip -lv 11.zip


Homework #1  How to unzip it repeatedly to get the  deepest one?



Step 6. if you have a shell script to print a triangle

for row in {1..10}; do col=`expr $row + 1`; i=1; while [ $i -lt $col ]; do printf " %s" $i; i=`expr $i + 1` ; done ; j=`expr $i - 2`; while [ $j -gt 0 ]; do printf " %s" $j; j=`expr $j - 1`; done; printf "\n"; done


Homework #2 How to create a nested zip file in the following rules



1.1) 1_.zip has treasure.txt
1.2) _1.zip has treasure.txt, too. But 1_.zip has different SHA-1 from _1.zip
2.1) 2_.zip has both 1_.zip and _1.zip.
2.2) _2.zip has both 1_.zip and _1.zip. However, 2_.zip has different SHA-1 from _2.zip
3.1) 3_.zip has 1_.zip, 2_.zip, _2.zip and _1.zip.
3.2) the same story for _3.zip and others



Homework #3 How to print a pascal triangle



Homework #4 How to create a nested zip file in the style of pascal triangle



沒有留言:

張貼留言