Navigate through files and directories#
First let us find out where we are by running a command called
Here, the response is the iPython chapter of the Jupyter tutorial in my home directory
On Windows the home directory will look like
C:\Documents and Settings\veit or
C:\Users\veit and on Linux like
To see the contents of our directory, we can use
create-delete.ipynb grep-find.ipynb pipes-filters.ipynb file-system.ipynb index.rst shell-variables.ipynb
/indicates a directory
@indicates a link
*indicates an executable
Depending on your default options, the shell might also use colors to indicate whether an entry is a file or a directory.
ls options and arguments#
!ls -F ../
debugging.ipynb myscript.py display.ipynb shell.ipynb examples.ipynb start.rst extensions.rst tab-completion-for-anything.png* importing.ipynb tab-completion-for-modules.png* index.rst tab-completion-for-objects.png* magics.ipynb unix-shell/ mypackage/
ls is the command, with the option
-F and the argument
Options either start with a single dash (
-) or two dashes (
--), and they change the behavior of a command.
Arguments tell the command what to operate on.
Options and arguments are sometimes also referred as parameters.
Each part is separated by spaces.
Also, capitalisation is important, for example
ls -swill display the size of files and directories alongside the names,
ls -Swill sort the files and directories by size.
total 184 24 create-delete.ipynb 24 grep-find.ipynb 16 pipes-filters.ipynb 96 file-system.ipynb 8 index.rst 16 shell-variables.ipynb
file-system.ipynb create-delete.ipynb shell-variables.ipynb grep-find.ipynb pipes-filters.ipynb index.rst
Show all options and arguments#
ls comes with a lot of other useful options. Using
man you can print out the built-in manual page for the desired UNIX/Linux-command:
LS(1) General Commands Manual LS(1) NAME ls – list directory contents SYNOPSIS ls [-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%,] [--color=____] [-D ______] [____ ___] DESCRIPTION For each operand that names a ____ of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a ____ of type directory, ls displays the names of files contained within that directory, as well as any requested, associated information. If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and in lexicographical order. The following options are available: -@ Display extended attribute keys and sizes in long (-l) output. … macOS 13.4 August 31, 2020 macOS 13.4
If you try to use an option that isn’t supported, the commands will usually print an error message, for example for:
ls: invalid option -- z usage: ls [-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]
-a option you can display all files:
. create-delete.ipynb index.rst .. file-system.ipynb pipes-filters.ipynb .ipynb_checkpoints grep-find.ipynb shell-variables.ipynb
In addition to the hidden directories
., you may also see a directory called
.ipynb_checkpoints. This file usually contains snapshots of the Jupyter notebooks.
Show directory treeThe command
tree lists contents of directories in a tree-like format.#
. ├── create-delete.ipynb ├── file-system.ipynb ├── grep-find.ipynb ├── index.rst ├── pipes-filters.ipynb └── shell-variables.ipynb 1 directory, 6 files
At first it may seem irritating to some that they cannot use
!cd to change to another directory.
The reason for this is that Jupyter uses a temporary subshell. If you want to change to another directory permanently, you have to use the magic command
%automagic function, these can also be used without the preceding
Automagic is ON, % prefix IS NOT needed for line magics.
Absolute and relative Paths#