Introduction to Unix File System with Jupyter Lab

Sergio J. Rey

2024-01-25

Overview

  • Welcome to the lecture on Unix File System!
  • In this session, we’ll learn about Unix, its file system, and how to work with it using Jupyter Lab.

Outline

  • File System Basics
  • Navigation
  • Creating and Managing Directories
  • File Operations
  • Hands-on

File System Basics

What is Unix?

  • Unix is a powerful operating system used in many fields, including data science and computer science.
  • Understanding its file system is crucial for efficient work.

Unix File System Basics

  • The Unix file system is hierarchical.
  • It consists of directories and files organized in a tree-like structure.

Directory Structure

  • The root directory is the top-level directory.
  • Home directories are where users have their own spaces.

Where am I?

Using the File Browser

(a) home

Figure 1: (b) data

Where am I?

Using the terminal

(a) terminal home

Figure 2: (b) terminal pwd

ls

ls lists the contents of the pwd

tree

tree lists the directory structure/tree of the pwd

First level tree of the root system

First level tree of the /home directory

My Home

All Home(s)

Clearing the terminal

  • clear will clear the terminal

history

To recall what you have done, use history

Rerunning a command

After using history you can rerun a command without having to retype it:

(a) recall

Figure 3: (b) result

Tab completion

Another efficiency feature is tab completion:

(a) tab start

Figure 4: (b) tab completion

Paths

  • Paths are used to specify the location of files and directories.
  • There are relative and absolute paths.

cd change directory

cd shortcuts

  • cd .. moves up one directory to the parent of the current directory
  • cd will move you back to your home

Creating and Managing Directories

Creating and Managing Directories

  • Learn how to create directories using mkdir.
  • Use rmdir and rm -r to remove directories.

mkdir

(a) before

Figure 5: (b) after

File Operations

File Operations

  • Creating files with touch.
  • Copying, moving, and deleting files.

Creating a file in a directory

cd handson

touch data.txt

Creating a file in a directory (2)

You can also create a file in the current directory by selecting the + in the toolbar and selecting Markdown File

Figure 6: File Browser

Creating a file in a directory (2)

You can also create a file in the current directory by selecting the + in the toolbar and selecting Markdown File

Figure 7: README.md

Copying Files

cp data.txt data.txt.bak

Deleting Files

rm data.txt

Copying Again

Let’s restore our backup

Copying Between Directories

Moving Files Between Directories

Creating and Removing Directories

Creating and Removing Directories

Practical Exercises

  • Let’s put what we’ve learned into practice.
  • Hands-on exercises to reinforce your understanding.
  • Get together with two-three colleagues
  • One person will “drive” and enter commands
  • Other members “navigate” by giving instructions
  • Rotate through exercises
  • For all these exercises you should record notes in a juptyer notebook for future reference

Exercise 0

  1. Create a directory called notes
  2. In that directory create a new jupyter notebook and rename it to files.ipynb
  3. Practice using Markdown in files.ipynb to structure your notes with headings
  4. Practice taking screenshots and dragging the images into your notebook.
  5. Practice formatting code in Markdown cells.

You will use this notebook to take notes on the remaining exercises.

Exercise 2

Using the File Browser, delete your handson directory and the files living in there

Exercise 3

Using a terminal:

  1. Create a directory called handson in your home directory
  2. Select the new directory in the File Browser
  3. From the Launcher create a new Markdown file with the name README.md
  4. Add some content (using Markdown) inside the README.md file
  5. Before using any unix commands, ask youself what the path is for the README.md file.

Exercise 4

Using a terminal:

  1. Create a directory called week_2 inside your handson directory
  2. Copy the README.md file into the week_2 directory.

Exercise 5

Using a terminal

  1. Create a directory called temp in the week_2 directory.
  2. Create a file in the temp directory called data.txt
  3. Delete the directory temp in the week_2 directory

Questions?