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

Linux Shell Coding Lab Report

The goal of this lab is to gain a foundational understanding of Linux, its command-line interface (CLI), and shell scripting. The focus is on exploring Linux file structures, executing essential commands, and writing basic shell scripts to automate tasks.

Uploaded by

pharaohhbosss
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Linux Shell Coding Lab Report

The goal of this lab is to gain a foundational understanding of Linux, its command-line interface (CLI), and shell scripting. The focus is on exploring Linux file structures, executing essential commands, and writing basic shell scripts to automate tasks.

Uploaded by

pharaohhbosss
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab Report: Introduction to Linux and Shell Coding

Name: [Your Name]

Date: [Lab Date]

Course Name: [Course Name or Code]

Instructor: [Instructor's Name]

Objective:

The goal of this lab is to gain a foundational understanding of Linux, its command-

line interface (CLI),

and shell scripting. The focus is on exploring Linux file structures, executing essential

commands, and writing basic shell scripts to automate tasks.

Materials Required:

- A computer with Linux OS (e.g., Ubuntu, Fedora) or a Linux virtual machine.

- Terminal access.

- Text editor (e.g., Vim, Nano, or VS Code).

Theory:

1. What is Linux?

Linux is a Unix-like, open-source operating system widely used for its stability,

flexibility, and robust CLI.

2. What is a Shell?

The shell is a command-line interpreter that allows users to interact with the OS.

Examples include Bash, Zsh, and Fish.

Page 1
Lab Report: Introduction to Linux and Shell Coding

3. Shell Scripting:

A shell script is a file containing a series of commands executed by the shell. It

is used to automate repetitive tasks.

Experiment Steps:

Part 1: Linux Basics

1. Navigating the File System

- Command: ls, pwd,

cd Example:

pwd # Display current

directory ls # List files

and directories

cd /home # Change directory to /home

2. File and Directory Management

- Commands: mkdir, touch, rm,

cp, mv Example:

mkdir lab_folder # Create a new

directory touch file1.txt # Create a

new file

mv file1.txt lab_folder/ # Move file to the directory

3. Viewing File Content

Page 2
Lab Report: Introduction to Linux and Shell Coding

- Commands: cat, more, less,

head, tail Example:

Page 3
Lab Report: Introduction to Linux and Shell Coding

cat file1.txt # Display file content

head -n 5 file1.txt # Display the first 5 lines

4. File Permissions

- Commands: chmod, chown,

ls -l Example:

chmod u+x script.sh # Make the script

executable ls -l # View permissions of files

Part 2: Shell Scripting

1. Creating a Script

- Write a script

hello_world.sh:

#!/bin/bash

echo "Hello, World!"

2. Making the Script Executable

- Command: chmod +x hello_world.sh

3. Executing the Script

- Command: ./hello_world.sh

4. Adding Logic and Loops

- Write a script

basic_operations.sh:

Page 4
Lab Report: Introduction to Linux and Shell Coding

#!/bin/bash

echo "Enter two numbers:"

Page 5
Lab Report: Introduction to Linux and Shell Coding

read num1 num2

sum=$((num1 + num2))

echo "Sum: $sum"

Observations:

1. Basic Linux commands are intuitive and effective for file management.

2. Shell scripting provides a powerful way to automate tasks.

3. Common errors include missing permissions or syntax errors in scripts.

Results:

- Successfully navigated the Linux file system.

- Performed file and directory operations.

- Created and executed basic shell scripts.

Conclusion:

This lab provided hands-on experience with Linux commands and shell scripting,

enhancing the understanding of CLI operations and automation. The ability to write

scripts to perform calculations or manage files demonstrates the versatility of the Linux

environment.

Questions:

1. What is the purpose of the chmod command?

Answer: It is used to change the permissions of a file or directory.

2. How can you debug a shell script?

Page 6
Lab Report: Introduction to Linux and Shell Coding

Answer: Use the bash -x script.sh command to execute the script in debug mode.

Page 7
Lab Report: Introduction to Linux and Shell Coding

Page 8

You might also like