0% found this document useful (0 votes)
21 views3 pages

UNIX Command Lab Experiments Guide

The document outlines a series of UNIX command-based lab experiments aimed at teaching various aspects of the UNIX operating system, including file management, permissions, process management, and shell scripting. Each experiment includes specific objectives and example commands to help users practice and understand the concepts. The final experiment suggests a mini project for real-world application of the skills learned.

Uploaded by

paribikash2003
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)
21 views3 pages

UNIX Command Lab Experiments Guide

The document outlines a series of UNIX command-based lab experiments aimed at teaching various aspects of the UNIX operating system, including file management, permissions, process management, and shell scripting. Each experiment includes specific objectives and example commands to help users practice and understand the concepts. The final experiment suggests a mini project for real-world application of the skills learned.

Uploaded by

paribikash2003
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

UNIX Command-Based Lab Experiments

Experiment 1: Introduction to UNIX Environment


Objective: To familiarize with the UNIX operating system, directory structure, and basic commands.
Example Commands / Script:
date cal who uname -a man ls

Experiment 2: File and Directory Management Commands


Objective: To perform basic file and directory operations.
Example Commands / Script:
pwd ls -l mkdir test cd test touch [Link] cp [Link] [Link] mv [Link]
[Link] rm [Link] rmdir test

Experiment 3: File Permissions and Ownership


Objective: To understand and modify file permissions and ownership in UNIX.
Example Commands / Script:
ls -l chmod 755 [Link] chown user1 [Link] chgrp developers [Link]

Experiment 4: File Display and Comparison Commands


Objective: To display, concatenate, and compare file contents.
Example Commands / Script:
cat [Link] more [Link] head -5 [Link] tail -3 [Link] diff [Link]
[Link] cmp [Link] [Link]

Experiment 5: Filters and Piping


Objective: To use filters and piping for data processing.
Example Commands / Script:
cat [Link] | sort cat [Link] | grep "John" cat [Link] | cut -d" " -f2
cat [Link] | uniq cat [Link] | wc -l

Experiment 6: Input/Output Redirection


Objective: To use input/output redirection operators in UNIX.
Example Commands / Script:
ls -l > [Link] cat < [Link] echo "Hello World" >> [Link] sort <
[Link] > [Link]

Experiment 7: Using vi Editor


Objective: To learn editing operations using the vi text editor.
Example Commands / Script:
1. Create a new file using vi filename. 2. Insert text, delete lines, copy and
paste content. 3. Save and exit using :wq.

Experiment 8: Process Management


Objective: To manage and monitor processes in UNIX.
Example Commands / Script:
ps -e top sleep 100 & jobs fg %1 kill

Experiment 9: System Administration Commands


Objective: To execute system information and monitoring commands.
Example Commands / Script:
whoami id df -h du -sh * uptime history

Experiment 10: User and Group Management


Objective: To manage users and groups in UNIX.
Example Commands / Script:
sudo adduser testuser passwd testuser groups su testuser sudo deluser testuser

Experiment 11: Shell Scripting – Basics


Objective: To write and execute simple shell scripts.
Example Commands / Script:
#!/bin/bash echo "Welcome to UNIX Shell Scripting!

Experiment 12: Shell Script with Conditional Statements


Objective: To use if statements in shell scripts.
Example Commands / Script:
#!/bin/bash echo "Enter a number:" read num if [ $((num%2)) -eq 0 ] then echo
"$num is Even" else echo "$num is Odd" fi

Experiment 13: Shell Script with Loops


Objective: To use for and while loops in shell scripting.
Example Commands / Script:
#!/bin/bash for i in {1..5} do echo "Number: $i" done

Experiment 14: Command Line Arguments in Shell Scripts


Objective: To pass and use command line arguments.
Example Commands / Script:
#!/bin/bash echo "First Argument: $1" echo "Second Argument: $2" echo "Total
Arguments: $#

Experiment 15: File Handling in Shell Scripts


Objective: To perform file-related operations using shell scripts.
Example Commands / Script:
#!/bin/bash echo "Enter filename:" read file if [ -f "$file" ] then echo "File
$file exists." else echo "File $file not found!" fi

Experiment 16: Shell Script for Automation


Objective: To automate system or user-level tasks using shell scripting.
Example Commands / Script:
#!/bin/bash mkdir -p backup cp *.txt backup/ echo "Backup completed successfully!

Experiment 17: Mini Project


Objective: To design a real-world automation project using shell scripting.
Example Commands / Script:
Example Ideas: - System Resource Report Generator - Automatic Log File Cleaner -
File Organizer Script - User Login Tracker

Common questions

Powered by AI

Mastering 'vi' is foundational for UNIX users due to its ubiquity and versatility in text editing. Essential commands include entering insert mode with 'i', saving a file with ':w', exiting with ':q', and force quit without saving using ':q!' . These commands allow efficient file editing, allowing users to quickly navigate lines, make changes, and execute timely saves. Familiarity with 'vi' enhances overall UNIX proficiency by enabling powerful text and configuration file handling directly from the command line environment.

Input redirection uses symbols like '<' to redirect input from a file instead of standard input, while output redirection uses '>' or '>>' to direct output to a file instead of standard output . These operators enable the redirection of data flow, essential for handling data in scripts or batch processes. They facilitate tasks like logging outputs or automating data updates without manual entry. Their impact is significant as they streamline workflows, prevent data loss by ensuring outputs are saved, and integrate with other processes seamlessly.

Conditional statements in shell scripts, such as 'if', 'then', 'else', 'fi', enable decision-making by executing different blocks of code based on evaluated conditions . This capability allows scripts to handle scenarios dynamically, reacting to input, system states, or unexpected conditions. For example, determining if a number is even or odd using modulo operations demonstrates basic condition evaluation . Conditional logic is essential for creating robust scripts capable of intelligent responses, improving scripts' adaptability and fault tolerance.

Command-line arguments introduce flexibility by allowing scripts to accept input parameters, thus tailoring their operation based on user inputs or external data . They transform scripts into reusable tools across various contexts, as users can modify operations without altering the script. For instance, using "$1" and "$2" references in scripts allows immediate access to these inputs and adjusts operations accordingly. This flexibility is vital in creating versatile automation solutions, catering to dynamic operational requirements efficiently, and allowing scripts to be integrated into diverse workflows.

Shell scripting basics include understanding execution with the '#!/bin/bash' shebang line, utilizing 'echo' for output, and using variables for dynamic values . These concepts form the foundation of automation by allowing repetitive or complex tasks to be encapsulated within scripts. Fundamental to beginners are concepts like script permission settings, input/output redirection, and basic control structures for script flow. Mastering these elements is crucial for effectively automating tasks, reducing user workload, and improving operational efficiency on UNIX systems.

Within shell scripts, techniques for file handling include checking file existence with 'if [ -f "$file" ]', reading filenames from input, and performing operations like creating, copying, and deleting files . Such scripts automate repetitive file management tasks, reducing manual intervention, thus increasing efficiency. These techniques empower users to batch-process files, maintain organized data structures, and ensure data integrity through verification steps. Automation in file handling is essential for system efficiency, particularly in environments requiring regular file updates or backups.

Filters within UNIX, such as 'grep', 'sort', and 'uniq', process data streams textually, performing operations like text searching, sorting, and removing duplicates. Piping, represented by '|', connects multiple commands, allowing the output of one command to become the input of another, building a complex command workflow . A practical example is using "cat marks.txt | grep 'John' | sort | uniq", which filters lines containing 'John', sorts them, and removes duplicates, showing the pipeline's power to refine data processing efficiently.

The 'chmod' command is used to change the file permissions, which determine who can read, write, or execute the file. It modifies the permission bits of a file using numerical or symbolic representation . On the other hand, 'chown' changes the ownership of a file or directory, assigning it to a new user or group. This command affects who has administrative control over the file itself, rather than just permissions to access . Understanding these differences is crucial, as 'chmod' is for controlling access level while 'chown' shifts control of that access.

The 'ps' command lists currently running processes, providing essential information about them, such as process IDs and statuses . 'Jobs' displays tasks managed by the current shell session, including background tasks . 'Kill' terminates processes, using process IDs acquired through 'ps' or 'jobs', effectively controlling the execution of processes that may be unresponsive or unnecessary . This combination allows users to monitor, manage, and terminate processes efficiently, ensuring optimal system performance.

Shell scripts automate system tasks by encapsulating complex sequences of commands into executable scripts. Examples include scheduling periodic backups using cron jobs combined with shell scripts like 'mkdir -p backup; cp *.txt backup/' . These scripts manage log files by rotating or cleaning them, automate user management, or generate system reports for administrators. Real-world examples include log file clean-up utilities, system resource usage trackers, and automated software updates, all of which enhance operational efficiency, reduce user oversight, and minimize human error.

You might also like