Commit 3ef58023 authored by Éamonn Murray's avatar Éamonn Murray

Initial set of files and examples

parents
*.swp
__pycache__/
tmp
*.py[cod]
Introduction to Scientific Computing
====================================
This is a collection of various notes and examples I've generated over the
past few years, that will hopefully be of use to students as supplementary
material to their courses.
I periodically add corrections and new content and sections. To ensure you
have the latest version:
- Go to <https://gitlab.com/eamonn.murray/IntroToScientificComputing>
- To download everything with git:
`git clone https://gitlab.com/eamonn.murray/IntroToScientificComputing.git`
- If you've cloned the repository previously and want to ensure you have
the most recent updates type `git pull` within the repository directory.
Contents
--------
There are currently sections on the following topics:
- [Computer Systems](systems/README.md)
- [Binary, Bits and Bytes](systems/README.md#binary-bits-and-bytes)
- [Components](systems/README.md#components)
- [High-Performance Computer Systems](systems/README.md#high-performance-computer-systems)
- [Internal Representation of Data](systems/README.md#internal-representation-of-data)
- [Linux - 1. The Command line](linux1/README.md)
- [Using the Terminal](linux1/README.md#using-the-terminal)
- [Tab Completion](linux1/README.md#tab-completion)
- [Permissions](linux1/README.md#permissions)
- [Reading Files](linux1/README.md#reading-files)
- [The Manual and man Command](linux1/README.md#the-manual-and-man-command)
- [Wildcards](linux1/README.md#wildcards)
- [IO Redirection](linux1/README.md#io-redirection)
- [History](linux1/README.md#history)
- [Other Useful Commands](linux1/README.md#other-useful-commands)
- [Linux - 2. More Advanced Use](linux2/README.md)
- [Editing Files](linux2/README.md#editing-files)
- [The Bash Shell](linux2/README.md#bash-shell)
- [Remote Access](linux2/README.md#remote-access)
- [Linux - 3. Useful Tools](linux3/README.md)
- [Version Control with Git](linux3/README.md#version-control-with-git)
- [Plotting](linux3/README.md#plotting)
- [Visualizing Atomic Structures](linux3/README.md#visualizing-atomic-structures)
- [Document Preparation with Latex](linux3/README.md#document-prepartion-with-latex)
- [Python - 1. The Basics](python1/README.md)
- [Installing Python](python1/README.md#installing-python)
- [Using Python](python1/README.md#using-python)
- [Hello World - Output](python1/README.md#hello-world-output)
- [Variables, Strings and IO](python1/README.md#variables-strings-and-IO)
- [Input](python1/README.md#input)
- [Basic Types](python1/README.md#basic-types)
- [Mathematical Operations](python1/README.md#mathematical-operations)
- [Compound Assignments](python1/README.md#compound-assignments)
- [More Advanced Math - Python Packages](python1/README.md#more-advanced-math-python-packages)
- [Branching - if statements](python1/README.md#branching-if-statements)
- [Python Data Structures - Strings and Lists](python1/README.md#python-data-structures-strings-and-lists)
- [Loops - while and for statements](python1/README.md#loops-while-and-for-statements)
- [More Compound Types - sets, tuples and dicts](python1/README.md#more-compound-types-sets-tuples-and-dicts)
- [Functions](python1/README.md#functions)
- [Modules](python1/README.md#modules)
- [Coding Style](python1/README.md#coding-style)
- [Working with Files](python1/README.md#working-with-files)
- [Python - 2. More Advanced Topics](python2/README.md)
- [List Comprehensions](python2/README.md#list-comprehensions)
- [Scope](python2/README.md#scope)
- [Classes](python2/README.md#classes)
- [Using Arguments in your Python Script](python2/README.md#using-arguments-in-your-python-script)
- [Installing Additional Packages](python2/README.md#installing-additional-packages)
- [Virtual Environments](python2/README.md#virtual-environments)
- [Catching Exceptions](python2/README.md#catching-exceptions)
- [Gotchas](python2/README.md#gotchas)
- [Jupyter](jupyter/README.md)
- [Installation](jupyter/README.md#installation)
- [Starting Jupyter](jupyter/README.md#starting-jupyter)
- [Shortcuts and Cell Types](jupyter/README.md#shortcuts-and-cell-types)
- [Full List of Shortcuts](jupyter/README.md#full-list-of-shortcuts)
- [Numpy](numpy/README.md)
- [Installation](numpy/README.md#installation)
- [Basic Usage](numpy/README.md#basic-usage)
- [A Simple Example](numpy/README.md#a-simple-example)
- [Comparison with Built-In Python](numpy/README.md#comparison-with-built-in-python)
- [Useful Numpy Operations](numpy/README.md#useful-numpy-operations)
- [Matplotlib](matplotlib/README.md)
In addition to the material collected here, there are also separate
repositories with material for:
- [Intro to C++](https://gitlab.com/eamonn.murray/IntroToCplusplus). This also
includes a brief section on Makefiles in the first section.
- [Intro to Mathematica](https://gitlab.com/eamonn.murray/IntroToMathematica)
- The content that was previously in [Intro to Linux](https://gitlab.com/eamonn.murray/IntroToLinux)
has been incorporated into this repository.
Additional Resources
--------------------
### Linux
- There are various useful
[guides at the Linux Documentation Project](http://www.tldp.org/guides.html),
in particular:
- [Introduction to Linux](http://www.tldp.org/LDP/intro-linux/html/index.html)
- [Bash Guide for Beginners](http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html)
### HPC and Scientific Computing
- Once you want to start thinking about more advanced scientific computing,
Victor Eijkhout's free textbook
[Introduction to High-Performance Scientific Computing](http://pages.tacc.utexas.edu/~eijkhout/istc/istc.html)
is an excellent resource.
### Python
- There are many excellent free resources available online, particularly at the
official python website:
- The python wiki: <https://wiki.python.org>. This links to beginner
guides and has other useful information such as recommended books.
- There is also a tutorial at
<https://docs.python.org/3/tutorial/index.html>.
- The official python documentation website:
<https://www.python.org/doc/>. This is particularly useful for finding
how particular functionality should work in the version of python you
have. Throughout the course, when a function is mentioned for the first
time, it will be linked to its official documentation page. Many
functions have options beyond what we will have time to cover so it's
worth checking these to get a better idea of what you can do.
- There are also many good books out there, in particular:
- Al Sweigart, _Automate the Boring Stuff with Python_, No Starch Press
(2015). This is a great introduction to Python language with a focus on
learning how to put python to work doing useful things for you. The
material in the book is free to read online at
<https://automatetheboringstuff.com/>.
- Christian Hill, _Learning Scientific Programming with Python_, Cambridge
University Press (2016). This is an excellent companion to the course
and will give you an alternative view on many of the topics covered
here.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Example Jupyter Notebook\n",
"\n",
"This is a simple example to show you what you can do.\n",
"This is a markdown cell. You can use it to generate a formatted description of what you're doing.\n",
"\n",
"It can parse LaTex style mathematical expressions:$$ \\Sigma_{i=0}^{10} x^2 = 285 $$\n",
"\n",
"If you enclose the expression in `$$` symbols it will be displayed on it's own line. And you can use single `$` symbols for inline equations: $\\alpha + \\beta = \\gamma$.\n",
"\n",
"There are more markdown examples at http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Working%20With%20Markdown%20Cells.html\n",
"\n",
"You can run a selected cell `ctrl+enter`, or run it and go to the next cell with `shift+enter`.\n",
"\n",
"Running a markdown cell, will render the markdown and any equations. You can double click the cell or press enter with the cell selected to go back to the source.\n",
"\n",
"Running a code cell will execute whatever code is in it. This works in the same way as an ipython notebook or using python interactively. You don't need to explicitly print output - the output of the last command in the cell will automatically be displayed. And variables or functions defined in any cell that us run will be available for use in any cell run subsequently."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# This will calculate the sum in the expression above using a list comprehension.\n",
"sum([x**2 for x in range(10)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a = 100"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(a)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "raw",
"metadata": {
"collapsed": true
},
"source": [
"# Example Jupyter Notebook\n",
"\n",
"This is a simple example to show you what you can do.\n",
"This is a markdown cell. You can use it to generate a formatted description of what you're doing.\n",
"\n",
"It can parse LaTex style mathematical expressions:$$ \\Sigma_{i=0}^{10} x^2 = 285 $$\n",
"\n",
"If you enclose the expression in `$$` symbols it will be displayed on it's own line. And you can use single `$` symbols for inline equations: $\\alpha + \\beta = \\gamma$.\n",
"\n",
"There are more markdown examples at http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Working%20With%20Markdown%20Cells.html\n",
"\n",
"You can run a selected cell `ctrl+enter`, or run it and go to the next cell with `shift+enter`.\n",
"\n",
"Running a markdown cell, will render the markdown and any equations. You can double click the cell or press enter with the cell selected to go back to the source.\n",
"\n",
"Running a code cell will execute whatever code is in it. This works in the same way as an ipython notebook or using python interactively. You don't need to explicitly print output - the output of the last command in the cell will automatically be displayed. And variables or functions defined in any cell that us run will be available for use in any cell run subsequently."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This will calculate the sum in the expression above using a list comprehension.\n",
"sum([x**2 for x in range(10)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a = 100"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(a)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Jupyter
=======
[Full topic list](../README.md)
`jupyter` offers a graphical notebook style interface to `ipython` (a command
shell for python) functioning in a similar way to Mathematica. This offers
many more features than simply using python interactively in a terminal.
Installation
------------
You can install `jupyter` using the python package manager `pip`. If you're
on an Ubuntu or Debian system you can do this system-wide for python3 with
```bash
sudo pip3 install --upgrade pip
sudo pip3 install jupyter
```
If you're using the TSM Linux VM I suggest you do this now.
Starting Jupyter
----------------
You can start `jupyter` by typing ``jupyter-notebook`` in a terminal.
Alternatively, depending on how you installed it, you may need to type
``jupyter notebook``. This will start a jupyter server in the terminal, and
open the server interface as a web page on your default browser that will
allow you to interact with it. An example of what you will see in your browser
when you first start jupyter in an empty folder is shown below: ![jupyter
browser interface](jupyter1.png).
You can do several things from this web interface. If you click the "new"
dropdown menu, you will see options to create a new text file or folder, or to
start a terminal, which gives you a terminal in your browser, followed by a
list of notebooks which can be started, which will likely just list "Python 3"
by default. Click this now to start a new python 3 notebook. The notebook
interface will be started in a new browser tab. How this looks is shown below:
![jupyter notebook](jupyter2.png).
The notebook interface offers many nice features. For example, it
automatically saves a checkpoints your work, will automatically close
brackets, and it can display graphics directly in the notebook. The input and
output is organised around cells, where you can enter commands in a similar
way as with an interactive python session, but you can edit and rearrange
cells easily. To execute the commands contained in a cell, press
``shift+enter`` as the enter key on its own will give you a new line in the
current cell allowing you to enter several lines of code to be executed
together. There are also menu buttons for many operations, such as executing
the current cell. You can hover over them to see what function they perform.
Each notebook you open from the server interface will have its own kernel that
runs in the server. This means that any function or variable definitions or
imports are local to the notebook, and will be available as long as the kernel
is running. When a notebook is saved, you can close the browser tab where it
is running and reopen it again to carry on from where you were. There is a
separate option to stop the kernel for a running notebook from the server
interface page. And if you close the browser interface page, the server will
still be running, so you can usually get back to it by visiting
[http://localhost:8888](http://localhost:8888). To shut down the server, go to
the terminal where you started it, and press ``ctrl+c``.
Shortcuts and Cell Types
------------------------
`jupyter` has many shortcuts for e.g. switching between input cell types, or
selecting, running, merging or deleting cells. You can bring up a list of
these by first pressing `Escape` to ensure you're in command mode (the cursor
will not be active in any cell), and then pressing `h`. It will take a while
to get to know them all, so I suggest trying to remember a few at a time as
you go. You can perform most operations using the mouse and menus so the
shortcuts are not mandatory but will make you more efficient.
There are three types of cell you can switch between:
1. Code (`Y`) - for entering sections of code of whatever language you've
chosen for the notebook. We've installed `jupyter` for python3 but many
other languages are possible.
2. Markdown (`M`) - for entering sections of text, with desired formatting
indicated by some simple rules. LaTex style mathematical expressions are
also supported.
3. Raw (`R`) - raw text with any highlighting or formatting disabled.
There is an example notebook given in the [`Example`](Example) directory that
contains a markdown cell and a few code cells. Launch `jupyter` and open this
to take a look. Try entering some code and markdown cells yourself.
Full List of Shortcuts
----------------------
Note shortcuts are not case sensitive.
- Command Mode (`Esc`)
- `F`: find and replace
- `Ctrl+Shift+F`: open the command palette
- `Ctrl+Shift+P` : open the command palette
- `Enter` : enter edit mode
- `P` : open the command palette
- `Shift+Enter` : run cell, select below
- `Ctrl+Enter` : run selected cells
- `Alt+Enter` : run cell, insert below
- `Y` : to code
- `M` : to markdown
- `R` : to raw
- `1` : to heading 1
- `2` : to heading 2
- `3` : to heading 3
- `4` : to heading 4
- `5` : to heading 5
- `6` : to heading 6
- `K` : select cell above
- `Up` : select cell above
- `Down` : select cell below
- `J` : select cell below
- `Shift+K` : extend selected cells above
- `Shift+Up` : extend selected cells above
- `Shift+Down` : extend selected cells below
- `Shift+J` : extend selected cells below
- `A` : insert cell above
- `B` : insert cell below
- `X` : cut selected cells
- `C` : copy selected cells
- `Shift-V` : paste cells above
- `V` : paste cells below
- `Z` : undo cell deletion
- `D,D` : delete selected cells
- `Shift+M` : merge selected cells, or current cell with cell below if only one cell selected
- `Ctrl+S` : Save and Checkpoint
- `S` : Save and Checkpoint
- `L` : toggle line numbers
- `O` : toggle output of selected cells
- `Shift+O` : toggle output scrolling of selected cells
- `H` : show keyboard shortcuts
- `I`,`I` : interrupt kernel
- `0`,`0` : restart the kernel (with dialogue)
- `Ctrl+V` : Dialogue for paste from system clipboard
- `Esc` : close the pager
- `Q` : close the pager
- `Shift+L` : toggles line numbers in all cells, and persist the setting
- `Shift+Space` : scroll notebook up
- `Space` : scroll notebook down
- Edit Mode (`Enter`)
- `Tab` : code completion or indent
- `Shift+Tab` : tooltip
- `Ctrl+]` : indent
- `Ctrl+[` : dedent
- `Ctrl+A` : select all
- `Ctrl+Z` : undo
- `Ctrl+Shift+Z` : redo
- `Ctrl+Y` : redo
- `Ctrl+Home` : go to cell start
- `Ctrl+Up` : go to cell start
- `Ctrl+End` : go to cell end
- `Ctrl+Down` : go to cell end
- `Ctrl+Left` : go one word left
- `Ctrl+Right` : go one word right
- `Ctrl+Backspace` : delete word before
- `Ctrl+Delete` : delete word after
- `Ctrl+M` : command mode
- `Ctrl+Shift-F` : open the command palette
- `Ctrl+Shift-P` : open the command palette
- `Esc` : command mode
- `Shift+Enter` : run cell, select below
- `Ctrl+Enter` : run selected cells
- `Alt+Enter` : run cell, insert below
- `Ctrl+Shift+Minus` : split cell
- `Ctrl+S` : Save and Checkpoint
- `Down` : move cursor down
- `Up` : move cursor up
Linux - 1. The Command Line
===========================
[Full topic list](../README.md)
Contents
--------
1. [Using the Terminal](#using-the-terminal)
2. [Files and Directories](#files-and-directories)
- [ls](#ls)
- [pwd](#pwd)
- [cd](#cd)
- [touch](#touch)
- [mkdir](#mkdir)
- [rm](#rm)
- [rmdir](#rmdir)
- [ln](#ln)
- [df](#df)
- [du](#du)
- [quota](#quota)
3. [Tab Completion](#tab-completion)
4. [Permissions](#permissions)
- [chmod](#chmod)
5. [Reading Files](#reading-files)
- [cat](#cat)
- [head](#head)
- [tail](#tail)
- [more](#more)
- [less](#less)
6. [The Manual and man command](the-manual-and-man-commands)
7. [Wildcards](#wildcards)
8. [IO Redirection](#io-redirection)
9. [History](#history)
10. [Other Useful Commands](#other-useful-commands)
- [grep](#grep)
- [cut](#cut)
- [awk](#awk)
- [sed](#sed)
- [tr](#tr)
- [find](#find)
- [diff](#diff)
- [sort](#sort)
- [uniq](#uniq)
- [tar](#tar)
- [bc](#bc)
11. [Job Control](#job-control)
Using the Terminal
------------------
Modern Linux distributions typically automatically set up desktop
environments, such as Gnome, KDE, or XFCE. These allow you to do quite a lot
without needing to type commands into a terminal. However, becoming familiar
with using the terminal will allow you to access the full power of a Linux
system, and is particularly useful when working on systems remotely, such as
when working with high-performance computing clusters.
The terminal allows you to type in various commands and instructions directly.
Open the terminal application by clicking on the appropriate icon. On the
Xubuntu installs you have been set up with, you can find "Terminal Emulator"
listed in the main menu as shown in the image:
![xfce terminal emulator in the main menu](img/xfce_terminal_emulator.png)
Note it is also listed under the accessories category, and the shortcut
`alt+ctrl+t` will open the terminal emulator by default. You can usually
customize the appearance to your preference by changing the text size, font
and colour scheme.
You can launch a program from the terminal by typing its name. For example
typing `firefox` will launch the firefox web browser by default.
Sometimes commands can generate a lot of output in the terminal. If you want
to scroll back up most terminals allow you to move up and down as follows:
- `shift+uparrow`: scroll up one line.
- `shift+downarrow`: scroll down one line.
- `shift+pageup`: scroll up one page.
- `shift+pagedown`: scroll down one page.
Files and Directories
---------------------
Once you have opened the terminal, the first thing you need to be able to do
is navigate the file structure.
### ls
`ls` is used to list the contents of a directory. Try typing it now. By
default you should start off in your home directory when you open a terminal,
so you should see several automatically generated directories. Note `ls` has
been set to use colour highlighting for you by default, so different types of
files are shown in different colours.
#### Useful Options
- `ls -lh`. The `-l` option requests a long listing format, giving extra
details about each file and folder, such as permissions, owner, size, and
modification date. The `-h` requests sizes in a human-readable format,
otherwise sizes are listed in bytes i.e. with this option `ls` would list
"4.0K" instead of "4096".
- `ls -a`. This tells `ls` to list _all_ files, i.e. to not to ignore files
starting with "." which are typically hidden by `ls` and often used to store
various user configuration files. Try typing this now, and you'll see many
more files and folders than previously.
### pwd
`pwd` will output the name of the present working directory. Try using it now.
It should respond with something like `/home/username`.
### cd
`cd` is used to change directory. You can specify either the full path, or a
directory relative to your current directory.
- `cd Documents` to move to the `/home/username/Documents` directory assuming
we are in `/home/username`.
- `cd /home/username/Desktop` to move to the users `Desktop` directory
regardless of where we start from.
- `cd ..` to move up one directory.
- `cd .` to move to the present directory (i.e. do nothing).
- `cd` and `cd ~` will both move to your home directory.
### touch
`touch` is mainly used to update a files timestamp (the time listed with
`ls -l` which is usually the most recent modification time). In your home
directory, try typing `touch Desktop` followed by `ls -l`, and you will see
the timestamp has been updated. However, the most common use for touch is as a
very quick way to create new, empty file. Try typing `touch tmp` in your home
directory. This will create a new empty file called `tmp`. This is useful when
a script or code requires a that a particular file exists.
### mkdir
`mkdir` is used to create new directories. For example `mkdir tmpdir1` will
create a new directory called `tmpdir1`.
#### Useful Options
- `mkdir -p` can be used to make parent directories as needed. For example,
`mkdir -p tmpdir1/tmpdir2/tmpdir3` if `tmpdir1` already exists will create
`tmpdir2` as a subdirectory of it, and `tmpdir3` as a subdirectory of
`tmpdir2`.
### rm
`rm` is used to delete files. For example, if we create a file with
`touch tmp` (this will update its timestamp if it already exists), we can
delete it with `rm tmp`.
#### Useful Options
- `rm -r` will recursively delete a directory and any files contained in it.
- `rm -f` can be used to force deletion without prompting. Combine with the
previous option with caution. There is no recycle bin when using `rm`.
When you use it to delete a file it is gone, unless you have a backup.
### rmdir
`rmdir` is used to delete directories. Note this will give an error if the
directory you try to delete is not empty.
### cp
`cp` is used to copy files. For example, `cp sourcefile newfile` would copy
the file `sourcefile` to `newfile`.
#### Useful Options
- `cp -r` will recursively copy a directory and any files contained in it.
### ln
`ln` is used to create links. These are somewhat similar to shortcuts in
windows except that they operate at the filesystem level. A link to a file can
be used in the same way as the file itself. They are useful for many reasons:
- Convenience: you may want to frequently use a particular directory, but it
has quite a long path. You can create a link to it in your home directory
and use the link in exactly the same manner as the original path.
- Saving space: For example, when working with a code that expects a certain
file as input in the current directory, you can make a link instead of
copying the file.
- If a parameter file is used in several places, you can use links so that
when you update when file, they are all updated, instead of having to update
several copies manually.
`ln` can create two types of links: hard links are created by default, and
symbolic links are created when the `-s` option is specified. Symbolic links
contain text which points to a particular file, while hard links point to the
same data on the disk as the original file. It's generally simplest to stick
to symbolic links, especially starting out. An example of how links can be
used is as follows:
1. `mkdir tmpdir1; mkdir tmpdir2; touch tmpdir1/tmpfile1` This will create two
directories and a file in one of them. Note semi-colons can be used to
separate commands on the same line.
2. `cd tmpdir2` Move to the tmpdir2 directory.
3. `ln -s ../tmpdir1/tmpfile1 tmpfile2` This will create a symbolic link to
the file.
3. `ln -s ../tmpdir1 .` will create a link to the `tmpdir1` directory in
`tmpdir2`.
4. Typing `ls` in the `tmpdir2` directory will show a files `tmpfile2` and
`tmpdir1`. If your colour highlighting is working, you should see these as
different colours to usual files (probably light blue). To see where the
links point you can use `ls -l`.
`cp -s` can also be used to create symbolic links (with `cp -l` creating hard
links), and can be a little easier to use, particularly for linking a set of
files.
- `cp -s ../results/*dat .` would create symbolic links from all the `.dat`
files in the results directory to the current directory.
#### Useful Options
- `ln -sf`: the additional `-f` option forces the link to overwrite any
pre-existing files or links.
- For example, if we had incorrectly done `ln -s ../tmpdir1/tmpdir1 .` in
the above example, the link would have been created, but wouldn't point
to any valid file. `ls` will usually show these invalid links as red. We
could then do `ln -sf ../tmpdir1 .` to overwrite the `tmpdir1` link with
the correct path, rather than deleting incorrect link and repeating the
`ln` command.
### df
`df` is used to report file system disk space usage for all mounted
partitions. This is a useful way to check how much space is free on the disks
and partitions used to store files by the system. It also tells you which
disks are are real local disks: these are the ones with labels like
"/dev/sda2" under the filesystem heading, while disks mounted across the
network will be labelled with the server address in this field. The "tmpfs"
label indicates a temporary filesystem, usually this is stored in RAM while
the system is running, but can be used through a directory in the file
hierarchy.
#### Useful Options
- `df -h` will list usage numbers in a human-readable format, i.e. instead of
10240, it would say "10M".
- `df -T` will list the filesystem type e.g. ext3/ext4 for disks using a
typical Linux filestructure, and nfs for disks mounted remotely over the
network.
### du