#!/usr/bin/env python # coding: utf-8 # # Command-Line Mystery # # This notebook sets you up for running Noah Veltman's [commandline mystery](https://github.com/veltman/clmystery). # To check where we are, display the current working directory. # # There are a several of ways we can do this, either using IPython magic: # In[38]: get_ipython().run_line_magic('pwd', '') # or a command line / shell command invocation: # In[39]: get_ipython().system('pwd') # ### Download the mystery # # The mystery files are provided in a zip file that we can download from `https://github.com/veltman/clmystery/archive/master.zip`. # # The `%%bash` block cell magic allows us to write several `bash` shell commands, that all execute wihting the same shell environment, in a single code cell: # In[11]: get_ipython().run_cell_magic('bash', '', '#Download (wget) the file from the specified URL quietly (-q)\nwget -q https://github.com/veltman/clmystery/archive/master.zip\n\n#Unzip the file very quietly (-qq)\nunzip -qq master.zip\n\n#Delete the downloaded zip file\nrm master.zip\n\n#Display the contents of the unzipped file directory\nls clmystery-master\n') # It probably makes sense to read the `README.html` # In[40]: get_ipython().system('cat clmystery-master/README.md') # Just before you get started on solving the mystery, it's worth noting that each time we run a shell command using `!`, or use the `%%bash` magic, the commands are run in their own shell: # In[30]: #Print (echo) the current directory (pwd) get_ipython().system('echo $(pwd)') #Change directory to the parent directory # then (;) show the current directoy get_ipython().system('cd ..; echo $(pwd)') #Show the current directory get_ipython().system('echo $(pwd)') # To "persistently" change the current directory, we need to change the directory used in the outer IPython environment from which the shell commands are run. We can do this using the `%cd` line magic: # In[33]: get_ipython().run_line_magic('cd', 'clmystery-master/mystery') get_ipython().system('pwd') # List the contents of the current directory...: # In[17]: get_ipython().system(' ls') # The instructions suggest we need to start by looking at the crimescene report: # In[ ]: get_ipython().system('cat crimescene') # There's rather a lot in there, but we're told the clues are marked as a `CLUE`. TO get you started, here's one way of filtering out those items — use the `grep` command to search for lines containing the word `CLUE`: # In[21]: get_ipython().system('grep CLUE crimescene') # Now get to it...