0% found this document useful (0 votes)
10 views2 pages

Lab Manual for Systems Programming

The document provides instructions for a systems programming lab assignment. It outlines familiarizing oneself with basic Linux commands and performing tasks like changing file permissions, checking system details, combining files, searching files, and getting directory sizes. Students are asked to complete the outlined tasks and submit a zip file with commands and screenshots.

Uploaded by

umangtrivedi473
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 views2 pages

Lab Manual for Systems Programming

The document provides instructions for a systems programming lab assignment. It outlines familiarizing oneself with basic Linux commands and performing tasks like changing file permissions, checking system details, combining files, searching files, and getting directory sizes. Students are asked to complete the outlined tasks and submit a zip file with commands and screenshots.

Uploaded by

umangtrivedi473
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

Systems Programming – Lab Manual

______________________________________________________________________________

Lab 1 – OS Familiarity and Basic Shell Commands

Section A: There is no submission for this part of the assignment


• Install Ubuntu in Virtual Machine by the steps provided to you in Course
Detail PPT, if not already done so.
• Get familiarity with Unix/Linux environment – Login, editors gedit/vi, etc
• Get familiarity with directory commands and their options: ls, cd, mkdir,
rmdir, pwd
• Get familiarity with file operation commands with its options: cp, mv, rm,
cat, head, tail, more, less, chmod, chown etc
• Use redirection operators (>, >>, <) and pipe (|) operator
• Run examples from class presentations (and others) of awk, grep, find, sed
and cut commands for file editing operations to understand how they work.

Section B: In this part of the assignment, you will be required to write shell
commands to perform the following functions. After executing each command,
capture the output in image format.
1. Change the permission of [Link] to allow read, write and execute
permission for the current user but only read and execute for the group
and other users.
2. Display the OS and kernel versions that your system is currently running.
3. First, create two text files [Link] and [Link] using some editor (Gedit, Vi,
etc.). Create a new directory MyOut in the home directory and create a
third file [Link] in MyOut, which has combined content from both the
input files. (Hint: use redirection operators)
4. Search for a given word in all the three text files ([Link], [Link] and [Link])
5. Using the awk command, display the current directory's total size, including
all subdirectories in MegaBytes.
6. Display only the time part using date and cut shell commands.
Submission:
[Link] with all commands and screen shorts from Section B.

Common questions

Powered by AI

To search for a specific word across multiple text files in Unix/Linux, the 'grep' command is predominantly used due to its efficiency in pattern matching. Suppose you have files 'in1.txt', 'in2.txt', and 'out.txt'. The command 'grep -i 'word' in1.txt in2.txt out.txt' would locate occurrences of 'word' across these files. The '-i' option ensures the search is case-insensitive. This command lists all lines containing the word from each file, making 'grep' an effective utility for multi-file text searches .

Changing the ownership of a file in Unix/Linux involves using the 'chown' command, which assigns the ownership to a specified user and optionally, a group. The command 'chown newuser file' changes the owner to 'newuser'. To also change the group, 'chown newuser:newgroup file' is used. Adjusting file ownership is necessary when files are transferred between users, ensuring permissions align with organizational roles and maintaining security protocols. Ownership change allows the new user to modify permissions, providing control over file access and usage .

To calculate the total size of all files within a directory and its subdirectories in Unix/Linux, you can use a combination of the 'du' and 'awk' commands. The command 'du -sh' provides a summary total size of a directory in human-readable form, but for more control, especially in scripting, 'du -s' followed by 'awk' can be used to manipulate the output. Specifically, 'du -b' calculates the size in bytes and can be piped through '| awk '{sum += $1} END {print sum/1024/1024 " MB"}' to iterate through all entries and provide a summed total in Megabytes, by accumulating the byte totals and converting to MBs .

In Unix/Linux, file permissions determine who can read, write, or execute a file. Permissions are assigned at three levels: user, group, and others. To modify permissions, the 'chmod' command is used. For example, to change the permissions of a script file 'abc.sh' such that the current user can read, write, and execute, and the group and others can only read and execute, the command would be: 'chmod 755 abc.sh'. This ensures that while the user retains full control, security rules are enforced by restricting write access from the group and others, therefore balancing functionality with security .

To display just the time portion from a full date string in Unix/Linux, you can use the 'date' command in conjunction with 'cut'. The 'date' command provides the current date and time, and you can format it to display only the time using specifiers like '+%H:%M:%S' for hour, minute, and second. If you need further processing to extract the time, you might use a command like 'date +"%T" | cut -d' ' -f2', assuming that the date string is split by spaces. This pipes the full date output, truncating to show only the necessary hour, minute, and second, utilizing 'cut' to isolate the section following delimiters .

In Unix/Linux, combining contents from multiple files into a single file can be accomplished using redirection operators. You can create two text files, say 'in1.txt' and 'in2.txt', and then use a command that handles output to redirect their contents into a third file. For instance, 'cat in1.txt in2.txt > MyOut/out.txt' will concatenate the content of 'in1.txt' and 'in2.txt', redirecting the combined output into 'out.txt' located in the 'MyOut' directory. This operation exploits the 'cat' command and the output redirection operator '>', ensuring a seamless merge of file contents .

Commands like 'awk', 'grep', 'find', 'sed', and 'cut' are powerful tools in Unix/Linux for advanced text processing and editing tasks. 'awk' processes and analyzes text from files, useful for data extraction and reporting. 'grep' searches for specific patterns in files. 'find' locates files based on criteria such as name, size, or modification date, aiding in bulk file operations. 'sed' serves as a stream editor for tasks like substitution and deletion. 'cut' extracts sections from text lines, simplifying data parsing. Together, these utilities streamline complex editing and processing tasks by automating repetitive operations and reducing manual workload .

Understanding the OS and kernel versions is crucial for system administrators because it impacts compatibility with software and security updates. Knowledge of the specific kernel version (e.g., using 'uname -r') informs which features, drivers, and modules are supported, influencing system performance and reliability. Additionally, knowing the OS version aids in troubleshooting and ensures proper configuration and compliance with organizational or vendor specifications for software installations and patches. This insight helps in planning upgrades and avoiding issues that might arise from version mismatches or deprecated features .

Redirection operators (>, >>, <) and pipes (|) in Unix/Linux shell commands enable users to manage input and output effectively, allowing for efficient file manipulation and data handling. Redirection operators can direct the output of a command to a file rather than the terminal (using > or >> for appending) or read input from a file (using <). Pipes enable the output of one command to serve directly as input to another, facilitating a flow of data through multiple processing stages without the need to store intermediate results. This chaining capability allows for complex data processing tasks to be streamlined, reducing manual intervention and increasing automation efficiency .

Basic directory commands are essential in Unix/Linux for effective navigation and management of the file system. 'ls' lists files in a directory; 'cd' changes the current directory; 'mkdir' creates a new directory; 'rmdir' removes an empty directory; and 'pwd' displays the current directory path. Mastery of these commands allows users to traverse directories, manage file structures, and maintain an organized environment—a foundational skill for any task or operations performed within a Unix/Linux system .

You might also like