Linux/C2/File-System/English
Title of script: The Linux File System
Author : Anirban Roy Choudhury
Keywords: Files, directories, make directory, remove directory, copy directory
Resources for the tutorial: File:Resources for file system.zip
|
|
Display slide 1 | Welcome to this spoken tutorial on Linux File System. |
Display Slide 2 | I am using Ubuntu 10.04. We assume that you know how to get started with the Linux operating system and have some basic idea about commands. If you are interested, it is available through another spoken tutorial, on the following website http://spoken-tutorial.org. |
Also note that linux is case sensitive. All the commands used in this tutorial are in lower case unless otherwise mentioned. | |
Display Slide 3 | In Linux almost everything is a file. So what is a file? In real life we know that a file is where we store our documents and papers. Similarly in Linux a file is a container for storing information. |
Display Slide 4 | Next what is a directory? A directory can be understood as a collection of files and other (sub)directories. |
A directory helps us in organising our files in a systematic manner. This is like what we call folders in Windows. It allows different users to have there own directories with their files which others cannot access or modify. | |
Also if there are no directories, all the files on the system need to have unique names,which would be very difficult to maintain. | |
Though these definitions of files and directories are good to get a general feel about them, they are not entirely accurate. | |
Display Slide 5 | As well as its contents, a file has a name and some properties, or “administrative information”; that is, the file’s creation/modification date and its permissions. |
The properties are stored in the file’s inode, a special block of data in the file system that also contains the length of the file and where on the disk it’s stored. | |
The system uses the number of the file’s inode; the directory structure just names the file for our benefit as its easier for us to remember names than large numbers. | |
Contrary to its oversimplified definition, a directory doesnot actually store other files ,it is itself a file that holds the inode numbers and names of other files. | |
Display Slide 6 | In fact in Linux there are three kinds of files:
|
Display Slide 7 | All files in Linux are related, in short all form a family much like we do. A directory containing say some files and subdirectories will have a parent – child relationship with each other. This gives rise to the Linux File System Tree. |
At the top is the root( denoted by a frontslash /). It contains all the other files and directories. This also helps in easy navigation from one file or directory to other, if we know the correct path. As we work with a Linux file system, it seems that we are moving along this tree. One command and there you are teleported from one place to other. | |
Sounds interesting!! Indeed it is. As we will see. | |
Display Slide 8
(upto first bullet) |
When we login into the Linux system we are by default in a home directory. |
Switch to the terminal | Switch to the terminal. Ctrl+alt+T helps to start a terminal in Ubuntu. This command may not work in all unix systems, however. |
Type at the command prompt
"echo $HOME" |
A general procedure to open a terminal is already explained in another spoken tutorial. To see the home directory
Type at the command prompt "echo space dollar HOME in capital" and press enter. |
This gives the pathname of our home directory. | |
Display Slide 8
(Second bulleted point) |
We can move around from one directory to other. But any time we can be in one directory and this directory is known as the current directory or working directory. Now go back to slides. |
The pwd command helps us to see the current directory. pwd stands for present working directory. | |
Type at the command prompt
"pwd" |
Type at the command prompt
"pwd" and press enter. Now this is our present working directory. |
Display Slide 9 | We have said that we can move from one directory to other. But how do we do so? We have the cd command for this purpose. |
You have to type the command cd followed by the pathname of the directory you want to move to. | |
Type at the command prompt "pwd" | Lets again see our current directory by typing pwd at the command prompt. Press enter. So, now we are placed in this directory. |
Type at the command prompt
"cd /usr" |
Now say we want to move to slash usr directory. So, type
"cd space slash usr" . Remember here slash in linux means front slash and press enter. |
Type at the command prompt "pwd" | Now lets see our current directory. Type pwd and press enter.
Yes we have moved to slash usr directory. |
Display Slide 8(modify the directory names according to your system) | The problem here is the pathnames can be very long, this is because these are Absolute Pathnames that enlist the entire path staring from the root directory. |
Instead we may use Relative pathnames that begin from the current directory. Here we need to know two special characters.
| |
(change the portion 'anirban' in the narration according to your computer) | Now let us have a brief session on cd command |
Type at the command prompt
"cd" |
The command cd without any argument is used to move back to the home directory. Type at the command prompt
"cd" and press enter. |
Type at the command prompt
"pwd" |
Now check our current directory by the pwd command.
So, now we are back in our home directory /home/gnuhata [ narration- slash home slash gnuhata ] |
Type at the command prompt
"cd Music/" |
Now let us move to music directory. Type at the command prompt "cd space Music(M in capital) slash" and press enter |
Type at the command prompt
"pwd" |
Now check our current directory by the pwd command. pwd and press enter.
See, we have moved /home/gnuhata/Music |
Type at the command prompt
"cd .." |
Let us go to the parent directory of Music. For that you have to use cd command with dot dot. Type at the command prompt cd space dot dot and press enter. |
Type at the command prompt
"pwd" |
Now check our present directory by typing pwd. We are again in /home/gnuhata |
Type at the command prompt
"cd ./Documents/" |
Now lets try to move to a subdirectory of the current directory using dot. Type at the command prompt cd space dot slash Documents(D in capital) slash. Press enter. |
Type at the command prompt
"pwd" |
Check our current directory by typing pwd. We are at /home/gnuhata/Documents |
Type at the command prompt
"cd" |
Let me clear the screen by pressing control L. So you can see clearly.Go back to our home directory by cd command.
Type cd and press enter. |
Type at the command prompt
"pwd" |
Again check our current directory by pwd command. We are back to /home/gnuhata . |
We can combine any number of .. [narration - dot dot] separated by / [narration- slash] in a relative path .
In this slide, we can see the file system hierarchy. Root or / is at the top. home and bin are two sub-directories under root. username , here the directory named gnuhata is a sub-directory under home. So, now we are in /home/gnuhata. Now how can we go to the bin directory? | |
Type at the command prompt
"cd ../../bin" |
Type at the command prompt
"cd space dot dot slash dot dot slash bin" and press enter. |
Type at the command prompt
"pwd" |
Check our current directory by the command pwd.
We are at /bin [narration - slash bin] The first .. [narration-dot dot] takes us from /home/gnuhata [narration - slash home slash gnuhata] to /home [narration - slash home] . The next takes us from /home to root. Now from / or root, we have moved to /bin directory. |
Type at the command prompt
"cd" |
Go back to our home directory by the command cd. |
Display Slide 11 | To create a directory we use the mkdir command.
You have to type the command and name of directory to be created and a directory would be created under the current directory. |
Type at the command prompt
"mkdir testdir" |
To create a directory named testdir, type the command "mkdir space testdir" and press enter.This creates the testdir directory successfully. |
Note that, there is no explicit notification of successful directory creation or removal. If you do not get any error message, it denotes successful execution. | |
We can also use the relative or absolute pathname to create a directory anywhere in the tree provided we have the permission to do so and a directory by that name doesnot already exist. | |
This process can be used for making multiple directories or even a hierarchy of directories. | |
Type at the command prompt "mkdir test1 test2" | Type "mkdir space test1 space test2 and press enter ,this will make two directories named test1 and test2 under the present directory. |
Type at the command prompt
"mkdir testtree testtree/test3" |
Type "mkdir space testtree space testtree slash test3". This will make a directory testtree and another directory test3 which is a sub-directory under testtree. |
So, we have created four directories namely testdir,test1,test2 and testtree in the current directory, out of which first three are empty and the last one contains a subdirectory namely test3. | |
Display Slide 12
(upto first bullet) |
Similar to mkdir is the rmdir command which is used for removing a directory or directories. |
Type at the command prompt "rmdir test1" | The command "rmdir space test1" removes the test1 directory successfully. |
Display Slide 11
(Second bullet onwards) |
A directory can be removed only if you are its owner,
your current directory is hierarchically above the directory to be removed and the directory is empty. |
Type at the command prompt
"cd testtree/test3" |
Now type at the command prompt
"cd space testtree slash test3" |
So, we are now in test3 directory which is a subdirectory under testtree. | |
Type at the command prompt
"rmdir testdir" |
Lets try to remove the testdir directory by typing the command "rmdir space testdir". Press enter. |
We see it can't be done, because the current directory is not hierarchically above the directory to be removed. | |
Type at the command prompt
"cd ../.." |
So,we have to go to the directory which is hierarchically above testdir directory. Type "cd space dot dot" and press enter. |
Now, go back to our parent directory by typing the command "cd space dot dot". | |
Type at the command prompt
"rmdir testdir" |
Now, again try the previous command. Type "rmdir space testdir". Press enter. The testdir directory is successfully deleted. Note that, testdir directory was also empty. |
Multiple directories or a hierarchy of directories can be removed at once.So, try to delete the testtree directory along with its subdirectory test3. | |
Type at the command prompt
"rmdir testtree testtree/test3/" |
Type at the command prompt
"rmdir space testtree space testtree slash test3 "press enter. See, it is giving the error message that 'testree' directory cannot be removed because testtree is not empty. |
Type at the command prompt
"cd testtree" |
But one thing which you may miss is that testtree/test3 has been deleted as it was empty. To check that, type at the command prompt "cd space testtree" and press enter. |
Type at the command prompt
"ls" |
Now type "ls" and press enter. See, the directory contains nothing. So, test3 was deleted. |
Display Slide 13 | So in this linux tutorial we have learnt about Linux Files and directories and how to work with Linux Directories. See them, move between them, make them,remove them. This brings me to the end of this tutorial. Spoken Tutorials are a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT.
More information on the same is available at the following link http://spoken-tutorial.org/NMEICT-Intro. This is Anusha Kadambala signing off . Thanks for joining. |