0% found this document useful (0 votes)
5 views

Linux Environment Lab - Linux File System

Lab Manual
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Linux Environment Lab - Linux File System

Lab Manual
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Linux Environment Lab 1

1
© 2021 C-DAC, Hyderabad
Table of Contents
Objective 3

Prerequisites 3

Problem Statement 3

Fundamental concepts 3

Summary 3

Template for each step 5


Step-1: Explore the content of each directory inside root directory 5
Step-2: Execute Directory & File related commands 6

References 15

2
© 2021 C-DAC, Hyderabad
1. Objective

Understanding the Linux Architecture, File System, Commands etc.

2. Prerequisites

Prerequisites Version

Operating System Linux (Any flavor)

3. Problem Statement
To understand the Linux File System, Explore the content of each directory present in the
root directory. Understand different Linux commands and execute the same.

4. Summary

Steps Description

Step 1 Explore the content of each directory inside root


directory
Step2 Execute Directory and File related commands

Step3 Output

Step4 Analyzing the Output with Program

3
© 2021 C-DAC, Hyderabad
5. Fundamental Concept

A Linux file system is a structured collection of files on a disk drive or a partition. A partition
is a segment of memory and contains some specific data. Linux file system is generally a
built-in layer of a Linux operating system used to handle the data management of the
storage. It helps to arrange the file on the disk storage. It manages the file name, file size,
creation date, and much more information about a file.

Directory and File related Linux Commands:

Command Description

pwd It prints the path of the working directory, starting from the root

ls Lists directory contents of files and directories

cd It is used to change current working directory

mkdir Allows the user to create directories. This command can create
multiple directories at once

rmdir Used to remove empty directories from the filesystem in Linux

cp Used to copy files or group of files or directory

mv Used to move one or more files or directories from one place to


another in file system like UNIX

touch Used to create, change and modify timestamps of a file

less Used to read contents of text file one page(one screen) per time

more Used to view the text files in the command prompt, displaying one
screen at a time in case the file is large

cat Reads data from file and gives their content as output. It helps us
to create, view, concatenate files

head Prints the top N number of data of the given input

tail Prints the last N number of data of the given input

4
© 2021 C-DAC, Hyderabad
6. Template for each step

1. Step-1: Explore the content of each directory inside


root directory
● Open the Terminal by clicking on Activities and type terminal or use keyboard
shortcut Ctrl + Alt + T

● Go to the root directory by executing command cd / and then list the contents of
root directory using ls commands

● Now, go inside each directory using command cd and list the content of that
directory using command ls or execute the command ls followed by directory
name from the root directory

5
© 2021 C-DAC, Hyderabad
2. Step-2: Execute Directory and File related commands
1. pwd: Print Working Directory
Execute the command pwd. This will print the current working directory

2. ls: List Directory Contents


Execute the command ls. This will print the content of the current working
directory on the terminal

3. cd: Change Directory


Change the directory to Desktop using command cd

6
© 2021 C-DAC, Hyderabad
4. mkdir: Create Directory
Create a new directory newDir using command mkdir and using ls command
you can check the newly created directory

5. rmdir: Remove Directory


Remove the directory newDir using command rmdir and using ls command
you can check the directory has been deleted or not.
o Note: Directory deleted using rmdir gets deleted permanently. They can’t be
recovered.

6. cp: Copy
First create a new file with command touch and a directory using command
mkdir and confirm using ls command

7
© 2021 C-DAC, Hyderabad
● Now using cp command copy the hello.txt file to foo directory and then
check the contents of foo directory using ls command.
● You can also copy the directory using cp.

7. mv: Move
First create a new directory using command mkdir and confirm using ls
command.

Now, move the file hello.txt inside newly created directory and then check
the content of current directory and newly created directory using ls command

8
© 2021 C-DAC, Hyderabad
9
© 2021 C-DAC, Hyderabad
8. less: Allows you to view the contents of a file and navigate
through file
First we will create a new file which has large content in it, for that execute
below command:

Now we will read the content of the file temp.txt using command less. This
command will only show the one page at a time on the screen. If you can press Enter
key it will show next line on the screen. And, if you press page down key, it will show
the next page on the screen. Similarly, page up key will take you one page back.

10
© 2021 C-DAC, Hyderabad
9. more: Open a given file for interactive reading
Now, we will use the more command to read the content of temp.txt. You can
scroll through the contents of the file by pressing ENTER or SPACE BAR keys.

Note: The main difference between more and less is that less command is
faster because it does not load the entire file at once and allows navigation
though file using page up/down keys.

11
© 2021 C-DAC, Hyderabad
10. cat: Concatenate
Now, we will use the cat command to display the content of temp.txt on the
screen.

12
© 2021 C-DAC, Hyderabad
Now, we will use cat command to copy the content of temp.txt file to another
text file. So, first we will create an empty text file using touch command and then
copy the content of temp.txt to newly created file.

Now, print the content of newFile.txt using cat command and you can see
that the content of temp.txt has got copied to newFile.txt using cat command

13
© 2021 C-DAC, Hyderabad
11. head: Print the top N number of data of the given input
We can use a head command to display the content of temp.txt on the
screen. By default it will print first 10 lines on the screen.

You can specify the no of lines to be printed on the screen by using -n


followed by no of lines.

14
© 2021 C-DAC, Hyderabad
12. tail: Print the last N number of data of the given input
We can use a tail command to display the content of temp.txt from the end
of the file. By default it will print last 10 lines on the screen.

We can specify the no of lines to print using option -n.

15
© 2021 C-DAC, Hyderabad
7. References
● https://en.wikipedia.org/wiki/File_system
● https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

16
© 2021 C-DAC, Hyderabad

You might also like