{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to Use Custom Line/Cell Magic\n", "### Quick Introduction to Magic Commands\n", "IPython offers special functions called **Magic** commands. These commands allow the user to quickly use special features within a Jupyter cell. To call these commands we use ``` % ``` for a single line magic or ``` %% ``` for an entire cell magic, for example using ```%lsmagic``` will show all the available built in magic functions. **try it now!**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%lsmagic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can even use magics to run bash commands right from the notebook, no need to open a terminal. For example using ```%ls``` to list all segments in the present working directory, or ```%cd``` to change working directory. Another option is to use the entire cell magic ```%%bash``` to run multiple commands within one cell. See the example below where we use a ```%%bash``` cell. Once we turn the cell into a bash cell we can use the ```factor``` command or the ```apt-get``` command for example." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%bash\n", "factor 1337\n", "apt-get moo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another very useful magic command is the ``` %%html ``` cell magic. This magic command turns an entire code cell into a fully functioning html cell. **Check it out!**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%html\n", "
Within this cell we can use most HTML tags including the script tag.
\n", "