{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Maneuvering directories (i.e. folders)\n", "\n", "To get some practice with the command line, we will use an example directory with some files in it. You can download a ZIP file containing the directory [here](https://s3.amazonaws.com/bebi103.caltech.edu/data/command_line_recitation.zip).\n", "\n", "And we said we would use the terminal in Jupyter Lab, so let us open a terminal (another one!) and type `jupyter lab`. If you do not have Jupyter Lab installed, just use your normal terminal and install it after the class.\n", "Once Jupyter Lab opens in your browser you can open `File -> New -> Terminal`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## pwd and ls\n", "\n", "When the shell is ready for your input it will display a `$` at the beginning of the line, which means that you are a normal user (not an admin) and the terminal is ready.\n", "Let's start out by using the `pwd` command to figure out what directory we're in.\n", "\n", " pwd\n", "\n", "`pwd` tells you the **path** of your current directory. A path for a directory or file is the list of all its parent directories, separated by slashes (`/`), up to the root directory signified by the initial `/`. You are probably in your home directory.\n", "\n", "To list all files and folders in the current directory, we employ the `ls` command.\n", "\n", " ls" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## cd: change directory\n", "Let's make sure we are in the home directory:\n", "\n", " cd\n", "\n", "Use `pwd` to check where you are now. Invoking the `cd` command without specifying a target directory defaults to the home directory. Another way to specify your home directory is by its shortcut, `~/`. In general, the tilde-slash means \"home directory.\" \n", "\n", "From here, let's navigate to the `command_line_recitation` directory:\n", "\n", " cd command_line_recitation\n", " \n", "Note, that depending on where you saved this directory, you may have to do some additional navigation to get to it. For example, anything I download defaults to the `Downloads` directory, so I would navigate by:\n", "\n", " cd Downloads/command_line_recitation\n", " \n", "It's important to know that you can either specify the **full** path (beginning with your home directory) to the directory you want to navigate to or you can enter the **relative** path starting from your current directory.\n", "\n", "**HINT**: if you have changed directory and need to come back to where you were before, you can just type:\n", " \n", " cd -\n", "\n", "This will get you back to the previous directory quickly and without specifying the path." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## mkdir and rmdir\n", "\n", "To make a directory, the command is `mkdir`, hence the name ***m***a***k***e ***dir***ectory. followed by the name of the directory you want to create. For example, to make a directory called `rec01`:\n", "\n", " mkdir rec01\n", " \n", "You now have an empty directory called `rec01`. You can see it if you list the contents of the directory.\n", "\n", " ls\n", " \n", "We do not need (nor want) this directory, since this is just for practice, so let's delete it. To delete an *empty* directory, the command is `rmdir`.\n", "\n", " rmdir rec01\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "*Copyright note: In addition to the copyright shown below, this recitation was developed based on materials from Axel Müller.*" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 4 }