OSd Lab
OSd Lab
Set 1
1. To display the last 20 lines of "logfile.txt", you can use the tail command:
tail -n 20 logfile.txt
wget <https://example.com/files/archive.zip>
1. Here's an AWK script to calculate the total sales for each category and
display the results:
1. To apply particular features from a feature branch to the main branch, you
can use git cherry-pick . First, switch to the main branch:
Then, cherry-pick the commits from the feature branch that contain the
desired features:
Replace <commit1> , <commit2> , etc., with the commit hashes of the commits
containing the features you want to apply.
Set 2
OSS Lab 1
1. To show the files in the "documents" directory located in "/home/user",
you can use the ls command:
ls /home/user/documents
#!/bin/bash
Save the script as, for example, system_config.sh , and execute it.
Now, your "master" branch is back to the state before the accidental
commit, and your changes are on the new feature branch.
Set 3
OSS Lab 2
1. To move the file "data.txt" to a new location and rename it as
"new_data.txt" using basic Linux commands, you can use the mv
command:
mv data.txt /path/to/new_location/new_data.txt
1. To extract specific data from a text file and save it in a new file, you can
use the grep command along with redirection:
Replace "specific_pattern" with the pattern you want to extract from the input
file. Execute the command in the terminal, and it will create a new file named
"output_file.txt" containing the extracted data.
#!/bin/bash
Save the script as, for example, system_info.sh , and execute it.
1. To know if a branch has been combined into the master in Git, you can use
the git log command:
This command will display the commit history with a graphical representation.
If a branch has been merged into the master, you will see its commits in the
history. To get the current status of the local repository, you can use:
git status
OSS Lab 3
This command will show the current status of your working directory and
staging area, indicating which changes are staged, unstaged, or untracked.
Set 4
1. To display the calendar for the current month in the terminal, you can use
the cal command:
cal
commands:
This command finds all files within the specified directory and its
subdirectories, excluding those with the ".log" extension, and then searches
for the string "example_text" within each file, displaying the filename, line
number, and context of the matching lines.
#!/bin/bash
Save the script as, for example, system_config.sh , and execute it.
1. To create custom scripts in Git that run when certain actions occur, you
can use Git hooks. For example, to run a script when a commit occurs, you
can create a pre-commit hook:
OSS Lab 4
Create a file named pre-commit (without any file extension) and add
your script commands to it.
Set 5
1. To compare the contents of two text files, "file1.txt" and "file2.txt", and see
if they are identical, you can use the diff command:
Replace <URL1> , <URL2> , <URL3> , etc., with the URLs of the files you want to
download.
1. Here's an AWK script to calculate the total sales for each category and
display the results:
1. To make changes in a file without affecting the original file (master branch)
and then apply those changes to the original file, your team member can
follow these steps using Git:
OSS Lab 5
Create a new branch:
Merge the changes from the feature branch into the master branch:
This will apply the changes made in the feature branch to the original
file in the master branch.
Set 6
command:
mv data.txt /path/to/new_location/new_data.txt
1. To accomplish the task of extracting the first 8 lines from "sample.txt" and
then copying the last 5 lines from those 8 lines, you can use a combination
of head and tail commands:
OSS Lab 6
This command will first extract the first 8 lines using head , and then from
those 8 lines, it will copy the last 5 lines using tail , saving the result in a file
named "extracted_lines.txt".
#!/bin/bash
# Memory Information
echo "Memory Information:"
free -h
Save the script as, for example, system_info.sh , and execute it.
1. To include changes made in a file in a branch into the master branch, you
can follow these steps:
Replace
<other_branch_name> with the name of the branch where the changes were
made. This command will incorporate the changes from the other branch
into the master branch. If there are any conflicts, you will need to resolve
them manually.
Merge the changes from the other branch into the master branch:
OSS Lab 7
git merge <other_branch_name>
Set 7
1. To display the last 20 lines of "logfile.txt" to see the most recent log
entries, you can use the tail command:
tail -n 20 logfile.txt
1. To extract the first 8 lines from "sample.txt" and then copy the last 5 lines
from those 8 lines, you can use a combination of head and tail
commands:
This command will first extract the first 8 lines using head , and then from
those 8 lines, it will copy the last 5 lines using tail , saving the result in a file
named "extracted_lines.txt".
#!/bin/bash
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_info.sh , and execute it.
OSS Lab 8
1. To create a branch both locally and globally in Git, you can follow these
steps:
Locally:
Globally:
Set 8
mkdir documents
Replace "dataset.txt" with the name of your dataset file. This command sorts
the dataset based on the third column (assuming grades are in the third
column) in descending order ( -nr flag for numerical sorting in reverse order).
OSS Lab 9
#!/bin/bash
# Home directory
echo "Home directory: $HOME"
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_info.sh , and execute it.
1. To fix a conflict in Git during an operating day, you can follow these steps:
Open the conflicted file(s) in your text editor and resolve the conflicts
manually, keeping the desired changes.
Once conflicts are resolved, add the modified file(s) to the staging area
using git add <file> for each file.
If you're working on a branch, you may need to merge it back into the
main branch using git merge or git rebase after resolving the conflicts.
Set 9
1. To compare the contents of two directories, "dir1" and "dir2", and identify
any differences between them using basic Linux command, you can use
the diff command:
This command recursively compares the contents of the two directories and
outputs the differences.
OSS Lab 10
1. To find all occurrences of the word "signin" in HTML files within a
directory and its subdirectories while ignoring case and displaying the line
number for each match, you can use the grep command:
#!/bin/bash
# Current shell
echo "Current shell: $SHELL"
# Home directory
echo "Home directory: $HOME"
Save the script as, for example, system_config.sh , and execute it.
1. To create a branch both locally and globally in Git, you can follow these
steps:
Locally:
This command creates and switches to a new branch named
"new_branch_name".
Globally:
This command pushes the new branch to the remote repository,
OSS Lab 11
creating it globally. Replace "origin" with the name of your remote
repository if it's different.
Set 10
mv data.txt /path/to/new_location/new_data.txt
This command sets the permissions to drwxrwx--- , where the owner and group
have full access, and other users have no access.
#!/bin/bash
# Current shell
echo "Current shell: $SHELL"
# Memory information
echo "Memory information:"
free -h
OSS Lab 12
Save the script as, for example, system_info.sh , and execute it.
Once the new features are implemented and tested, add and commit
the changes:
git add .
git commit -m "Implemented new features"
If the changes are ready to be merged into the main branch (e.g.,
master), switch to the main branch and merge the new feature branch
into it:
Now, the new changes are incorporated into the main branch while still
being maintained separately in the "new_feature_branch".
Set 11
man command_name
Replace "command_name" with the name of the command you want to learn
more about. This will display the manual page for that command, including its
usage and options.
OSS Lab 13
1. To download multiple files from different websites and save them in a
specific directory, you can use the wget command with appropriate URLs:
Replace <URL1> , <URL2> , <URL3> , etc., with the URLs of the files you want to
download.
#!/bin/bash
# Current shell
echo "Current shell: $SHELL"
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_info.sh , and execute it.
1. The clone and fork commands are different in the context of version
control systems like Git:
OSS Lab 14
commonly used in open-source projects where contributors can
submit pull requests with their changes for review and integration into
the original repository.
Set 12
mv data.txt /path/to/new_location/new_data.txt
1. To extract specific data from a text file and save it in a new file, you can
use the grep command along with redirection:
Replace "specific_pattern" with the pattern you want to extract from the input
file. Execute the command in the terminal, and it will create a new file named
"output_file.txt" containing the extracted data.
#!/bin/bash
Save the script as, for example, system_info.sh , and execute it.
1. The clone and fork commands are different in the context of version
control systems like Git:
OSS Lab 15
Clone: The clone command is used to create a copy of a repository
from a remote server to your local machine. This allows you to work on
the repository locally and make changes without affecting the original
repository.
Set 13
1. To display the last 20 lines of "logfile.txt" to see the most recent log
entries, you can use the tail command:
tail -n 20 logfile.txt
Replace "word_or_phrase" with the word or phrase you want to search for, and
"/path/to/search/directory" with the directory where you want to start the
search.
1. Here's an AWK script to calculate the total sales for each category and
display the results:
OSS Lab 16
1. Yes, it is possible to create a repository in Git. Here are the steps to do so:
git init
Now your repository is created and initialized with the initial commit.
Set 14
1. To compare the contents of two directories, "dir1" and "dir2", and identify
any differences between them using basic Linux command, you can use
the diff command:
This command recursively compares the contents of the two directories and
outputs the differences.
wget <https://example.com/files/archive.zip>
This command downloads the file "archive.zip" from the specified URL and
saves it in the current directory.
OSS Lab 17
1. Here's a shell script to show various system configurations:
#!/bin/bash
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_info.sh , and execute it.
Resolve any conflicts that may arise during the pull operation.
OSS Lab 18
Set 15
1. To display the calendar for the current month in the terminal using basic
Linux command, you can use the cal command:
cal
This command will display the calendar for the current month.
#!/bin/bash
# Current shell
echo "Current shell: $SHELL"
# Home directory
echo "Home directory: $HOME"
Save the script as, for example, system_config.sh , and execute it.
OSS Lab 19
git add .
git commit -m "Message describing the changes"
Set 16
mkdir project
This command will create a new directory named "project" in the current
working directory.
This command sets the permissions to drwxrwx--- , where the owner and group
have full access, and other users have no access.
#!/bin/bash
OSS Lab 20
echo "Login name: $LOGNAME"
# Current shell
echo "Current shell: $SHELL"
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_info.sh , and execute it.
1. To fix a conflict that arises in Git during an operating day, you can follow
these steps:
After resolving the conflicts, stage the changes using git add
Set 17
mkdir documents
This command will create a new directory named "documents" in the current
working directory.
command recursively:
OSS Lab 21
sudo chown -R user2:group2 /path/to/documents
#!/bin/bash
Save the script as, for example, system_config.sh , and execute it.
This command pulls changes from the remote repository's master branch
and merges them into his local repository.
b) After making changes to the file "abc.txt" locally, Alex can push the
changes back to the remote repository using the git push command:
OSS Lab 22
git push origin master
These commands add the file, commit the changes with a descriptive
message, and push the changes to the remote repository's master branch.
Set 18
1. To compare the contents of two directories, "dir1" and "dir2", and identify
any differences between them using basic Linux command, you can use
the diff command:
This command recursively compares the contents of the two directories and
outputs the differences.
Replace <URL1> , <URL2> , <URL3> , etc., with the URLs of the files you want to
download.
#!/bin/bash
OSS Lab 23
Save the script as, for example, system_config.sh , and execute it.
1. Jerry can add the feature added by Tom to his working branch by
following these steps:
Resolve any merge conflicts if they occur and commit the changes:
Set 19
1. To display the first 10 lines of the file "report.txt" using basic Linux
command, you can use the head command:
head -n 10 report.txt
This command will display the first 10 lines of the file "report.txt".
OSS Lab 24
Replace "word_or_phrase" with the word or phrase you want to search for, and
"/path/to/search/directory" with the directory where you want to start the
search.
#!/bin/bash
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_config.sh , and execute it.
1. To create custom scripts that run when certain Git actions occur, such as a
commit, you can use Git hooks. Git allows you to create custom scripts
that are executed automatically when specific Git events occur. For
example, to run a script after a commit, you can create a post-commit
hook script. Here's how you can do it:
Now, every time a commit is made in the repository, the script inside the
post-commit hook will be executed.
Write your custom script inside the post-commit file. For example:
OSS Lab 25
#!/bin/bash
echo "A commit has been made!"
chmod +x post-commit
Set 20
1. To compare the contents of two directories, "dir1" and "dir2", and identify
any differences between them using basic Linux command, you can use
the diff command:
This command recursively compares the contents of the two directories and
outputs the differences.
1. To take the first 8 lines from the file "sample.txt" for analysis and then
copy the last 5 lines from those 8 lines extracted previously using Linux
commands, you can use head and tail commands:
This command will extract the first 8 lines from "sample.txt" using head and
then select the last 5 lines from those 8 lines using tail , and finally, save
them to a new file named "extracted_lines.txt".
#!/bin/bash
OSS Lab 26
# Current shell
echo "Current shell: $SHELL"
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_config.sh , and execute it.
1. To hide the details you made in the Railway Reservation System Project
from your project manager at the end using Git, you can use the git stash
command. Stashing allows you to temporarily shelve changes and revert
your working directory to match the HEAD commit. Here's how you can do
it:
git stash
This command will stash away any changes you've made, allowing you to
switch to a different branch or perform other tasks without those changes
being visible. Later, when you're ready to continue your work, you can apply
the stash or discard it as needed.
Set 21
command:
ls /home/user/documents
This command will list all the files and directories in the
"/home/user/documents" directory.
1. To take the first 8 lines from the file "sample.txt" for analysis and then
copy the last 5 lines from those 8 lines extracted previously using Linux
commands, you can use head and tail commands:
OSS Lab 27
head -n 8 sample.txt | tail -n 5 > extracted_lines.txt
This command will extract the first 8 lines from "sample.txt" using head and
then select the last 5 lines from those 8 lines using tail , and finally, save
them to a new file named "extracted_lines.txt".
#!/bin/bash
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_config.sh , and execute it.
1. To create a branch both locally and globally in Git, you can use the git
# Locally
git branch branch_name
# Globally
git branch -m branch_name
Replace "branch_name" with the desired name of your branch. The -b option
is used to create a new branch, and -m option is used to create and switch to
the new branch at the same time.
OSS Lab 28
Set 22
de
1. To sort the names in alphabetical order from the file "data.txt" and save
the sorted list to a new file called "sorted_names.txt" using basic Linux
command, you can use the sort command:
This command will sort the names in "data.txt" alphabetically and save the
sorted list to a new file named "sorted_names.txt".
1. To download a file from a remote server using the command line and save
it to the current directory on your Linux server, you can use the wget
command:
wget <https://example.com/files/archive.zip>
This command will download the file "archive.zip" from the specified URL and
save it to the current directory.
#!/bin/bash
# Home directory
echo "Home directory: $HOME"
# Memory information
echo "Memory information:"
free -h
Save the script as, for example, system_config.sh , and execute it.
OSS Lab 29
1. To create a branch both locally and globally in Git, you can use the git
# Locally
git branch branch_name
# Globally
git branch -m branch_name
Replace "branch_name" with the desired name of your branch. The -b option
is used to create a new branch, and -m option is used to create and switch to
the new branch at the same time.
OSS Lab 30