Linux-Ubuntu/C2/File-System-in-Linux/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Title of the Script: File System in Linux

Author: EduPyramids Team.

Keywords: Linux, terminal, file, directories, pwd, ls command, cat command, video tutorial, EduPyramids.

Prerequisite tutorial: General Purpose Utilities


Visual Cue Narration
Slide 1

Title Slide

Welcome to this Spoken tutorial on File System in Linux.
Slide 2

Learning Objectives

In this tutorial we will learn to:
  • Define Files, directories and inode.
  • Create a file and add text in it.
  • Create directories and
  • Change and remove directories safely.
Slide 3

System Requirements

To record this tutorial, I am using,

Ubuntu OS version 24 point 04.

Slide 4

Pre-requisites

To follow this tutorial,

Learners should know the basics of using the Linux terminal.

For the prerequisite Linux tutorials please visit

https://EduPyramids.org

To follow this tutorial,
  • Learners should know the basics of using the Linux terminal.
  • For the prerequisite Linux tutorials please visit this website.
Slide 5

Code files

The following code file is required to practice this tutorial

  1. fs-commands.txt

This file is provided in the Code Files link of this tutorial page.

The following code file is required to practice this tutorial.

This file is provided in the Code Files link of this tutorial page.

Let us discuss files and directories.
Slide 6

Files

  • In real life, a file is used to store documents and papers.
  • Similarly, in Linux, a file is a container used to store information.
Now let us understand what a file is?

In Linux almost everything is treated as a file.

In real life, a file is used to store documents and papers.

Similarly, in Linux, a file is a container used to store information.

Slide 7

Directory

  • A directory is a collection of files and other sub-directories.
  • A directory helps us organize our files in a systematic manner.
Let us now see what a directory is?

A directory is a collection of files and other sub-directories.

A directory helps us organize our files in a systematic manner.

Slide 8

inode

inode.png

Every file has its own properties.

It has a name, creation, modification time and permission.

These properties are stored in a structure called inode.

An inode is a data structure identified by a unique number.

It is used by the system to identify a file.

It stores information about a file such as size, permissions, and ownership.

It also stores timestamps and the disk location of the file.

File name is only for human convenience.

A directory does not store files directly.

It is a file that maps file names to their corresponding inode numbers.

Slide 9

Linux File System hierarchy

Linux-filesystem.png

All the files are connected in a tree structure.

At the top of this tree is the root directory indicated by slash(/).

Every file and directory exists under root(/).

Slide 10

Types of Files

types-of-files1.png

Types of files in Linux.

Linux has three main types of files:

  1. Regular files : They store data as a stream of characters.

For example: text files, images, videos.

  1. Directories: Organize files and other directories.
  2. Device files: These represent hardware such as disks, USBs, Cds.

They can be read and written like files.

Screencast:

Press Ctrl, Alt and T keys on your keyboard

Let us now open the terminal window.
Type pwd

Point to the output

/home/spoken

By default we are always in the home directory.

Let me type pwd and press Enter.

The output shows /home/spoken as the present working directory.

Type ls -l and press Enter. Now type ls space hyphen l and press Enter.

Terminal shows the following output.

  • List of all files with file permissions,
  • file owner's name,
  • file size in bytes,
  • last modification time,
  • File or directory name.
Point to the information on the terminal. Instead of displaying all information on the screen, we can store it in a file.
Type at the prompt

ls -l >fileinfo and press Enter.

So type ls space hyphen l space greater than fileinfo and press Enter.

Observe that nothing is displayed on the screen.

Type at the prompt

cat fileinfo and press Enter.

To see the content of the files we have to use cat command.

So type cat space fileinfo and press Enter.

Output shows the file contents.

Type at the prompt

cat > file1.txt and press Enter.

The cat command is mainly used to display file contents.

It can also be used to create or append files.

Type cat space greater than file1 dot txt and press Enter.

Type I am creating a new file. and press Enter.

Press Ctrl + D keys to end the input.

After pressing Enter, the command waits for input from the user.

So let’s type I am creating a new file. and press Enter.

Whatever we type will be written into the file.

The input is ended by pressing Ctrl and D keys together.

Type at the prompt

cat >>file1.txt and press Enter.

If you wish to append to the end of an existing file type

cat space greater than greater than file1 dot txt and press Enter.

Type at the prompt

This is a new line in the file. and press Enter.

Press Ctrl + D keys together.

Again the command waits for input from the user.

So type, This is a new line in the file. and press Enter.

Press Ctrl and D keys together to end the input.

Type: cat file1.txt and press Enter. To see the contents written in file1 type,

cat space file1 dot txt and press Enter.

Type: clear and Press Enter. Type clear to clear the terminal window.
Type: mkdir test1 and Press Enter.

While recording, show the directory creation in the home directory.

Place the terminal and home directory side-by-side.

Let us now learn to create directories.

To create a directory I will type mkdir space test1 and press Enter.

If no output appears it means that the command has executed successfully.

Type mkdir test2 test3 and press Enter Let us now create multiple directories.

So I will type mkdir space test2 space test3 and press Enter.

Type mkdir -p test4/test4.1 and press Enter.

Show the folders test4 and test4.1

Highlight -p.

Now to show the directory hierarchy let me type mkdir space hyphen p space test4 slash test4 point 1 and press Enter.

This will create a directory test4 point 1 within the test4 directory.

Here the argument hyphen p creates parent directories if they do not already exist.

Then test4 point 1 directory is created inside test4.

Now let us learn to move into various directories.
Type: cd test1 press Enter. Type cd space test1 and press Enter.

We are now in the test1 directory.

Type cd .. and press Enter. Let us go back to the parent directory.

So type cd space dot dot

Type: cd test press Tab keys twice .

Press the backspace key to erase the prompt.

Now type cd test and press the Tab key twice.

All the directories with the name test will be displayed.

Press the backspace key to erase the prompt.

Type cd test4/test4.1 and press Enter. Type cd test4/test4 point 1 and press Enter to move to test4 point 1.
Type: cd ../../

Press the Enter key.

Now let us learn to do multi-level navigation to come back to the home directory.

Let me type cd space dot dot slash dot dot slash

Here the first two dots move up one level.

Second two dots moves up one more directory level.

Press the Enter key.

Type: rmdir test1 and press Enter. Now we will learn to delete the created test 1 directory.

Type rmdir space test1 and press Enter.

Now, we can see that the test1 directory is removed.

Type: rmdir test4 test4/test4.1

Highlight the output: rmdir: failed to remove 'test4': Directory not empty

Type rmdir space test4 space test4 slash test4 point 1.

The output shows

rmdir: failed to remove 'test4': Directory not empty.

This indicates that if the directory is not empty it cannot be deleted.

A directory must be empty before it can be removed using rmdir.

With this we come to the end of this tutorial.
Slide 9

Summary

In this tutorial we have learn to:

  • Define Files, directories and inode
  • Create a file and add text in it
  • Create directories and
  • Change and remove directories safely
Let us summarise.
Slide 10

Assignment

  • Create a file named myfile using the cat command
  • Write one line of text in it.
  • Display the contents of myfile using the cat command.
  • Create a directory named mydir and create sub-directories inside it.
As an assignment, please do the following.
Slide 11

Thank you

This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited SINE IIT Bombay.

Thank you.

Contributors and Content Editors

Ketkinaina, Madhurig