Wisdom of Jim
  • Blog
  • About Jim

A place to obtain the wisdom of Jim.

Linux Terminal Zip Contents of Folder and Save to Some Other Directory

4/7/2016

Comments

 
This is something that I needed to do in a recent AngularJS project. I had scaffolded the project with my favorite yeoman generator, Gulp-Angular, and I would build my project with the simple gulp command. However, in order to actually deploy it I had to hand off the files to some one else. The company was using a small time CMS that only allowed for manual upload of files, and I wasn't even given access being that I was just a contractor at the time. 

Seizing the Automation Opportunity!

I found myself over and over doing the same bit of manual work- something that annoys the heck out of me. But what annoyed the heck out of me even more is that I knew I should automate this step I was wasting my own damn precious time and energy. To review, here's what the manual work entailed:
  • running the gulp command to build my angular.js project.
  • drilling down into the output build folder and zipping up the files.
  • renaming the zip file to v127 (or v + next version number).
  • moving the zip onto a drive shared between coworkers.

I should be noted that I could have done this by adding a gulp task at the end of everything it does to zip up the proper files so that everything would happen from the gulp command. However, I didn't want to have to keep opening up the gulp files in order to change the version number. I was also already in the terminal window to run gulp so I figured I'd just do it with normal linux commands.
It's a bit scary, but I'll just throw it out there and then explain it:
gulp; cd dist; zip -r /Volumes/ai_temp/Jim\ Lynch/latest\ build/v128.zip  *; cd ..; 

The first thing to realize is that we can chain commands one after another by separating them with a semicolon. We can see the first part of this command is the good old gulp​ command as usual. Then we have another straightforward command, cd dist, which drills down into the dist ​folder creates by gulp (so that we don't include the dist folder in the zip we're about to do). Next we're going to zip up everything in the current folder. We use the zip command with the recursive -r flag, point to the exact path and name of the zip we're creating (you should change this to reflect the place on your computer where'd you'd like to save the zip file), and finally tell it to zip everything in this folder with the * character. I then cd out of the dist folder, bringing back where I started. If I then check in my "latent builds" folder, I'll see the zip there smiling at me!

Good Times!

I can always run this code above wherever I would run the gulp command, and it doesn't this extra bit of manual work for me. Some people would say this is overkill; that's is unnecessary. I say posh to them! I save a lot of time and agony with this script, and on top of that I feel like a real badass when I run it. So while they're right clicking around on compress /rename /move, I'm laughing all the way to the office game room.
Comments
comments powered by Disqus

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior-driven-development
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Illustrations
    Java
    Javascript
    Lean
    Life
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim

WoJ © 2015 - 2016