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

exp_12

The document outlines an experiment to create a shell script that displays executable files, directories, and zero-sized files from the current directory. It emphasizes understanding file permissions in UNIX-like systems, utilizing shell commands, and implementing scripts to filter directory content. The procedure includes iterating through files, categorizing them based on their attributes, and highlights the significance of execute permissions for files and directories.

Uploaded by

kamaliyakaran011
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)
10 views

exp_12

The document outlines an experiment to create a shell script that displays executable files, directories, and zero-sized files from the current directory. It emphasizes understanding file permissions in UNIX-like systems, utilizing shell commands, and implementing scripts to filter directory content. The procedure includes iterating through files, categorizing them based on their attributes, and highlights the significance of execute permissions for files and directories.

Uploaded by

kamaliyakaran011
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/ 3

Experiment No: 12

Aim: Write a shell script to display all executable files, directories, and zero-sized
files from the current directory.

Date:

Competency and Practical Skills:


1. Understand file and directory permissions in UNIX-like operating systems.
2. Utilize shell commands to detect specific attributes of files and directories.
3. Implement conditional statements in scripts to filter and display files based on their
properties.
4. Design and implement scripts that provide insights into the content of directories.

Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system.

Objectives:
1. To educate students about the permission system of UNIX-like operating systems and its
significance.
2. To demonstrate the ability to filter and display directory content based on specific criteria using
shell scripting.
3. To encourage students to explore various commands and options that can be used to glean
information about files.
4. To provide a hands-on experience in creating scripts that present organized information based
on file attributes.

Equipment/Software: PC/Laptop, Windows Operating System, Installation file of Linux OS

Theory:
In UNIX-like operating systems, files and directories have associated *permissions* that
determine who can read, write, or execute them. An executable file is one that has the execute
permission set for the user, group, or others. Directories with the execute permission can be
accessed and traversed. A zero-sized file, as the name suggests, has a size of 0 bytes.

Using the ls command with specific options and filters, one can list files based on their attributes.
Combined with if conditions, shell scripts can be used to detect and display files with specific
properties.

Procedure:
1. Start the script.

2. List and Filter Files:


- Iterate over all files and directories in the current directory.
- For each item:
a. If it's an executable file, display it under the "Executable Files" category.
b. If it's a directory, display it under the "Directories" category.
c. If it's a zero-sized file, display it under the "Zero-sized Files" category.

3. End the script.

Observations:

Result:
Code:-

Outpute:-

Conclusion: This script demonstrates how to use basic file tests in shell scripting to filter and
display files based on specific properties. It can be helpful for tasks such as organizing files,
performing system checks, or automating system maintenance. By using commands like -x, -d,
and -s, the script is able to classify files effectively based on attributes.

Quiz:
1. How can you identify an executable file in a UNIX-like system?
ANS:- An executable file can be identified by checking if it has the execute permission
(-x) set for the user, group, or others. In a shell script, this can be done using the
[ -x "$file" ] condition.
2. What is the significance of the execute permission on a directory?
ANS:- The execute permission on a directory allows users to enter the directory and
access its contents. Without the execute permission, users cannot navigate into the
directory using the cd command.

3. What size, in bytes, does a zero-sized file have?


ANS:- A zero-sized file has a size of 0 bytes. It is an empty file with no content.

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total
Marks

You might also like