Linux Exp 6, 7, 8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

EXPERIMENT NO 6

Aim / Title: Working with directories

Problem Statement: Study and execute directory related commands

Objectives: To get familiarity with directory related commands.

Outcomes: After going through this section, you should be


able to: Recognize, understand and make use of various
directory related commands. Gain hands on experience of
directory related commands.

Pre-requisite: Basic knowledge about operating system

Hardware requirements: Intel G645 Dual Core 3.0 GHz


4 GB RAM, 500 GB Hitachi HDD

Software requirements: UBUNTU 16.0 LTS

Theory:

A UNIX command line consists of the name of a UNIX command


(actually the "command" is the name of a built-in shell command, a
system utility or an application program) followed by its "arguments"
(options and the target filenames and/or expressions). The general
syntax for a UNIX command is

$ command -options targets

Directory Related Commands:

S.No. Command Description Syntax


Name
1 mkdir This command will create a new $mkdir
directory, provided it doesn't exists. [directory
name]
2 rmdir This command will remove/delete an $rmdir
existing directory, provided it is empty. [directory name]

3 cd This command is used to change $cd


directory. dir1/dir2/dir3
4 pwd This command displays the $pwd
present working directory where
you are currently in.
5 ls This command will list the content of a $ls
directory. The ls command without any
options lists files and directories in a
plain format without displaying much
information like file types, permissions,
modified date and time

6 ls -a This command will list all the content $ls -a


of a directory including the hidden
files and directories.

7 ls -l This command will list the $ls -l


permissions of the files and
directories as well as other attributes
such as folder names, file and
directory sizes, and modified date and
time.

8 ls -p It is used to identify the directory $ls -p


easily by marking the directories with
a slash (/) line sign.

9 ls -r It is used to print the list in reverse $ls -r


order
10 ls -- It checks the version of ls command. $ls --version
version

Instructions: NA
Program: NA

Output:
Conclusion:

__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
______________________

Sample Viva Questions and Answers:

Q1. Describe the term directory in UNIX?


__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Q2. Specify the difference between absolute path and related path.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Q3. What is the UNIX command to make a new directory?


__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Q4. Enlist some commonly used directory related commands.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Roll Name of Date of Date of Grade Sign of Sign of


No. Student Performance Evaluation Student Faculty
EXPERIMENT NO 7

Aim / Title: Working with Files

Problem Statement: Study and execute file related commands

Objectives: To get familiarity with file related commands.

Outcomes: After going through this section, you should


be able to: Recognize, understand and make use of
various file related commands. Gain hands on experience
of file related commands.

Pre-requisite: Basic knowledge about operating system

Hardware requirements: Intel G645 Dual Core 3.0 GHz


4 GB RAM, 500 GB Hitachi HDD

Software requirements: UBUNTU 16.0 LTS

Theory:

A UNIX command line consists of the name of a UNIX command (actually


the "command" is the name of a built-in shell command, a system utility or
an application program) followed by its "arguments" (options and the target
filenames and/or expressions). The general syntax for a UNIX command is

$ command -options targets

File Related Commands:

S.No. Command Description Syntax


Name
1 Touch This command will create a new file of $touch fn1
0 Bytes
2 cat >filename This command will create a new file $cat >fn2
containing some contents
3 cat fn2 This command is used to display $ cat fn2
contents of a file
4 cat It is used to Append contents of a file $ cat >>fn2
>>filename after another

5 cat fn3 fn4 It is used to concatenate contents of $ cat fn3


file fn3 and fn4 fn4

6 rm It is used to remove a file $ rm fn1

7 sort It is used to sort a file. $sort file1

8 sort -r It is used to sort a file. $sort -


r file1

9 sort -n file It is used to sort a file numerically $sort -n file

10 wc -l file It is used to the number of lines $wc -l file


count

11 wc -w file It is used to count the number of $wc -w file


words

12 wc -m file It is used to count the number of $wc -m file


characters

Instructions: NA

Program: NA
Output:
Conclusion:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
______________________

Sample Viva Questions and Answers:

Q1. What is the UNIX command to list files/folders in alphabetical order?


__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Q2. Describe the usage and functionality of the command rm –r.

__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Roll Name of Date of Date of Grade Sign of Sign of


No. Student Performance Evaluation Student Faculty
EXPERIMENT NO 8

Aim / Title: File Permissions

Problem Statement: Study & use of the Command for changing file
permissions. (Both the syntax of chmod numeric and alphabetic)

Objectives: To get familiarity with command for changing file permissions


using both the syntax of chmod (numeric and alphabetic)

Outcomes: After going through this section, you should


be able to: Change file permissions.

Pre-requisite: Basic knowledge about operating system

Hardware requirements: Intel G645 Dual Core 3.0 GHz


4 GB RAM, 500 GB Hitachi HDD

Software requirements: UBUNTU 16.0 LTS

Theory: chmod command changes the permission of a file.


Permissions:
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.

Numeric Permissions:
CHMOD can also to attributed by using Numeric
Permissions:
400 read by owner
040 read by group
004 read by anybody
(other) 200 write by
owner
020 write by
group 002 write
by anybody 100
execute by owner
010 execute by
group
001 execute by anybody

Examples:
The above numeric permissions can be added to set a certain permission,
for example, a common HTML file on a Unix server to be only viewed over
the Internet would be:

chmod 644file.htm
This gives the file read/write by the owner and only read by everyone
else (-rw-r--r--). Files such as scripts that need to be executed need
more permissions. Below is another example of a common permission
given to scripts.
chmod 755 file.cgi
This would be the following 400+040+004+200+100+010+001 = 755
where you are giving all the rights except the capability for anyone to write
to the file.cgi file(-rwxr-xr-x).
Finally, another common CHMOD permission is 666, as shown below,
which is read and write by everyone.
chmod 666 file.txt

Additional information
Below is an example of how a file may be listed when typing ( ls -l ) at the prompt
as well as information on how to interpret it.
-rw-rw-r-- 1 hope 123 Feb 03 15:36 file.txt

‐ Rw rw‐ r‐‐ 1 hope 123 Feb 03 15:36 file.txt

File owner group everyone else links owner size mod date file name

Instructions: NA
Program: NA
Output:

Conclusion:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

Sample Viva Questions and Answers:


Q1. chmod command can take multiple filenames as arguments.
a. True
b. False
_________________

Q2. Which of the following characters specify the user and group category?
a. ‘u’ and ‘g’
b. ‘g’ and ‘o’
c. ‘us’ and ‘gr’
d. ‘u’ and ‘o’
_________________

Q3. Which of the following symbol is used with chmod to assign permission to a
file?
a. –
b. /
c. +
d. *
_________________

Roll Name of Date of Date of Grade Sign of Sign of


No. Student Performance Evaluation Student Faculty

You might also like