Unzip and flatten multiple zip-files on a Mac (bash)

Here’s just a quick note to my future self (other people are free to take part of it too though).

When using the * character to unzip several files using the unzip command on a Mac, the * has to be escaped as unzip wants to do its file listing by itself, rather than having bash do it for it.

So instead of writing unzip *.zip, you would write \*.zip.

Also as a final note to self, to unzip several zip-files into e.g. the parent directory and also ignore any directory structure contained by the zip file + overwriting any duplicate files, one would write

unzip -o -j -d ../ \*.zip
Advertisement

Detect displays via command line

When I get to work, I connect my Macbook to a second monitor. However, in my case, if the monitor is not switched on, the Macbook cannot detect its ID (which lets it load the last set resolution, desktop background and physical arrangement). What I would have to do is to open the Display preference pane and click “Detect displays” which is quite annoying. Today I found a command line tool (which does the same thing), so now I just have to shift-cmd-enter to bring up my DTerm and type detectdisplays.