0% found this document useful (0 votes)
7 views30 pages

OSd Lab

Oyoupculhlc
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)
7 views30 pages

OSd Lab

Oyoupculhlc
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/ 30

OSS Lab

Set 1

1. To display the last 20 lines of "logfile.txt", you can use the tail command:

tail -n 20 logfile.txt

1. To download a file from a remote server to the current directory on your


Linux server, you can use wget command:

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:

awk 'NR>1 {sales[$2]+=$3} END {for (category in sales) pri


nt "Category:", category, "Total Sales:", sales[categor
y]}' sales_data_table.txt

Assuming your data is stored in a file named sales_data_table.txt .

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:

git checkout main

Then, cherry-pick the commits from the feature branch that contain the
desired features:

git cherry-pick <commit1> <commit2> ...

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

1. To find all occurrences of the word "signin" in HTML files within a


directory and its subdirectories, ignoring case and displaying line
numbers, you can use grep command:

grep -rni "signin" /path/to/project/directory/*.html

1. Here's a shell script to display various system configurations:

#!/bin/bash

echo "Current shell: $SHELL"


echo "Home directory: $HOME"
echo "Operating system type: $(uname)"

Save the script as, for example, system_config.sh , and execute it.

1. To correct accidentally committing on the "master" branch instead of the


"feature" branch, you can:

Create a new branch at the current commit:

git checkout -b new-feature-branch

Then, reset the "master" branch to the previous commit:

git checkout master


git reset --hard HEAD~1

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:

grep "specific_pattern" input_file.txt > output_file.txt

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.

1. Here's a shell script to show various system configurations:

#!/bin/bash

echo "Current path setting: $PATH"


echo "Current working directory: $(pwd)"
echo "Number of users currently logged in: $(who | wc -l)"

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:

git log --graph --oneline --decorate

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

1. To accomplish the developer's task of finding files containing a particular


string within a directory and its subdirectories while excluding files with a
specific extension, you can use grep along with find and xargs

commands:

find /var/www/html -type f ! -name "*.log" -exec grep -Hn


"example_text" {} +

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.

1. Here's a shell script to show various system configurations:

#!/bin/bash

echo "Operating system type: $(uname)"


echo "Current path setting: $PATH"
echo "Current working directory: $(pwd)"

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:

Navigate to your Git repository's .git/hooks directory.

OSS Lab 4
Create a file named pre-commit (without any file extension) and add
your script commands to it.

Make the script executable by running chmod +x pre-commit .

Now, whenever a commit is attempted, Git will execute the script


defined in the pre-commit hook. You can use this to enforce coding
standards, run tests, or perform other custom actions before allowing
the commit to proceed.

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:

diff file1.txt file2.txt

1. To download multiple files from different websites and save them in a


specific directory, you can use the wget command with appropriate URLs:

wget -P /path/to/specific_directory <URL1> <URL2> <URL3>


...

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:

awk 'NR>1 {sales[$2]+=$3} END {for (category in sales) pri


nt "Category:", category, "Total Sales:", sales[categor
y]}' sales_data_table.txt

Assuming your data is stored in a file named sales_data_table.txt .

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:

git checkout -b feature-branch

Make the necessary changes to the file in this feature branch.

Once satisfied with the changes, add and commit them:

git add <file>


git commit -m "Description of changes"

Then, switch back to the master branch:

git checkout master

Merge the changes from the feature branch into the master branch:

git merge feature-branch

This will apply the changes made in the feature branch to the original
file in the master branch.

Set 6

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 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:

head -n 8 sample.txt | tail -n 5 > extracted_lines.txt

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".

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Memory Information
echo "Memory Information:"
free -h

# Hard Disk Information


echo "Hard Disk Information:"
df -h

# File System (Mounted)


echo "File System (Mounted):"
df -hT

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.

Switch to the master branch:

git checkout master

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:

head -n 8 sample.txt | tail -n 5 > extracted_lines.txt

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".

1. Here's a shell script to show various system configurations:

#!/bin/bash

# All available shells


echo "All available shells:"
cat /etc/shells

# Computer CPU information


echo "Computer CPU information:"
lscpu

# 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:

git checkout -b new_branch_name

This command creates and switches to a new branch named


"new_branch_name".

Globally:

git push -u origin new_branch_name

This command pushes the new branch to the remote repository,


creating it globally. Replace "origin" with the name of your remote
repository if it's different.

Now, you have a new branch both locally and globally.

Set 8

1. To create a new directory called "documents" in your current working


directory using basic Linux command, you can use the mkdir command:

mkdir documents

1. To sort a dataset containing student records based on grades in


descending order, you can use the sort command:

sort -k3,3nr dataset.txt

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).

1. Here's a shell script to show various system configurations:

OSS Lab 9
#!/bin/bash

# Home directory
echo "Home directory: $HOME"

# Operating system type


echo "Operating system type: $(uname)"

# 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:

Identify the conflicted files by running git status .

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.

Then, commit the changes using git commit -m "Resolved conflicts" to


finalize the resolution.

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:

diff -r dir1 dir2

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:

grep -rni "signin" /path/to/project/directory/*.html

Replace "/path/to/project/directory/" with the path to your project directory.


This command will search for "signin" in all HTML files within the directory and
its subdirectories, ignoring case ( -i flag) and displaying the line number ( -n
flag) for each match.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Current shell
echo "Current shell: $SHELL"

# Home directory
echo "Home directory: $HOME"

# Operating system type


echo "Operating system type: $(uname)"

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".

git checkout -b 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.

git push -u origin new_branch_name

Set 10

1. To move the file "data.txt" to a new location and rename it as


"new_data.txt" using basic Linux command, you can use the mv command:

mv data.txt /path/to/new_location/new_data.txt

1. To change the permissions of the "shared_data" directory so that only the


owner and group have access, and other users have no access at all, you
can use the chmod command:

chmod 770 shared_data

This command sets the permissions to drwxrwx--- , where the owner and group
have full access, and other users have no access.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Currently logged user and login name


echo "Currently logged user: $USER"
echo "Login name: $LOGNAME"

# 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.

1. To implement the scenario where Nautilus developers want to maintain


new changes in a separate branch, you can use Git commands as follows:

Create a new branch for the new features:

git checkout -b new_feature_branch

Work on implementing the new features on this branch.

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:

git checkout master


git merge new_feature_branch

Now, the new changes are incorporated into the main branch while still
being maintained separately in the "new_feature_branch".

Set 11

1. To access the manual (documentation) for a specific Linux command


using basic Linux command, you can use the man command followed by
the name of the command:

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:

wget -P /path/to/specific_directory <URL1> <URL2> <URL3>


...

Replace <URL1> , <URL2> , <URL3> , etc., with the URLs of the files you want to
download.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Currently logged user and login name


echo "Currently logged user: $USER"
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. The clone and fork commands are different in the context of version
control systems like Git:

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.

Fork: The fork command is specific to Git hosting platforms like


GitHub. It creates a copy of a repository under your account on the
platform. This allows you to freely experiment with changes to the
repository without affecting the original repository. Forking is

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

1. To move the file "data.txt" to a new location and rename it as


"new_data.txt" using basic Linux command, 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:

grep "specific_pattern" input_file.txt > output_file.txt

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.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Current working directory


echo "Current working directory: $(pwd)"

# Number of users currently logged in


echo "Number of users currently logged in: $(who | wc -l)"

# Hard disk information


echo "Hard disk information:"
df -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 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.

Fork: The fork command is specific to Git hosting platforms like


GitHub. It creates a copy of a repository under your account on the
platform. This allows you to freely experiment with changes to the
repository without affecting the original repository. Forking is
commonly used in open-source projects where contributors can
submit pull requests with their changes for review and integration into
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

1. To search for specific text patterns in multiple files stored on a Linux


server and display the lines containing that word or phrase, you can use
the grep command with the r option to search recursively:

grep -r "word_or_phrase" /path/to/search/directory

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:

awk 'NR>1 {sales[$2]+=$3} END {for (category in sales) pri


nt "Category:", category, "Total Sales:", sales[categor
y]}' sales_data_table.txt

Assuming your data is stored in a file named sales_data_table.txt .

OSS Lab 16
1. Yes, it is possible to create a repository in Git. Here are the steps to do so:

Navigate to the directory where you want to create the repository.

Run the following command:


This command initializes a new Git repository in the current directory.

git init

Optionally, you can add files to the repository using:

git add <file1> <file2> ...

Commit the added files using:


This command creates a new commit with the added files.

git commit -m "Initial commit"

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:

diff -r dir1 dir2

This command recursively compares the contents of the two directories and
outputs the differences.

1. To download a file from a remote server to the current directory on a Linux


server using the command line, you can use the wget command:

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

# Computer CPU information


echo "Computer CPU information:"
lscpu

# Memory information
echo "Memory information:"
free -h

# Number of users currently logged in


echo "Number of users currently logged in: $(who | wc -l)"

Save the script as, for example, system_info.sh , and execute it.

1. In Git, when Developer B is unable to push changes after Developer A has


already pushed changes to the main branch, it indicates that Developer B's
local branch is out of sync with the remote main branch. Developer B can
resolve this situation by pulling the latest changes from the remote main
branch into their local branch, resolving any conflicts, and then pushing
their changes. Here are the steps Developer B can follow:

First, stash or commit any uncommitted changes in their local branch


to avoid conflicts.

Pull the latest changes from the remote main branch:

git pull origin main

Resolve any conflicts that may arise during the pull operation.

Once conflicts are resolved, add and commit the changes.

Finally, push the changes to the main branch:

git push origin main

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.

1. To change the ownership of the "shared_data" directory to "yyy:admins"


using Linux commands, you can use the chown command:

sudo chown yyy:admins shared_data

This command changes the ownership of the "shared_data" directory to the


user "yyy" and the group "admins".

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Current shell
echo "Current shell: $SHELL"

# Home directory
echo "Home directory: $HOME"

# Operating system type


echo "Operating system type: $(uname)"

Save the script as, for example, system_config.sh , and execute it.

1. To upload the content of the local repository to the remote repository,


John can follow these steps:

Commit any changes he has made to the local repository using:

OSS Lab 19
git add .
git commit -m "Message describing the changes"

Push the changes to the remote repository:


This command will push the changes from the local repository's
master branch to the remote repository. If John is working on a
different branch, he should replace "master" with the name of his
branch.

git push origin master

Set 16

1. To create a new directory called "project" in the current working directory


using a basic Linux command, you can use the mkdir command:

mkdir project

This command will create a new directory named "project" in the current
working directory.

1. To change the permissions of the "shared_data" directory to ensure that


only the owner and group have access, and other users have no access at
all, you can use the chmod command:

chmod 770 shared_data

This command sets the permissions to drwxrwx--- , where the owner and group
have full access, and other users have no access.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Currently logged user and login name


echo "Currently logged user: $USER"

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:

Use git status to identify the files with conflicts.

Open the conflicting files in your preferred text editor.

Manually resolve the conflicts by editing the conflicting sections in the


files.

After resolving the conflicts, stage the changes using git add

<conflicted_files> or git add . to stage all changes.

Finally, commit the changes using git commit -m "Resolved conflicts" to


complete the merge process.

Set 17

1. To create a new directory called "documents" in the current working


directory using basic Linux command, you can use the mkdir command:

mkdir documents

This command will create a new directory named "documents" in the current
working directory.

1. To change the ownership of all files and directories within the


"documents" directory to the new user and group, you can use the chown

command recursively:

OSS Lab 21
sudo chown -R user2:group2 /path/to/documents

Replace "/path/to/documents" with the actual path to the "documents"


directory. The -R option makes the command recursive, so it applies to all
files and directories within the specified directory.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Current path setting


echo "Current path setting: $PATH"

# Current working directory


echo "Current working directory: $(pwd)"

# Number of users currently logged in


echo "Number of users currently logged in: $(who | wc -l)"

Save the script as, for example, system_config.sh , and execute it.

1. Git commands for Alex's tasks:


a) To move changes from the remote repository to his local repository,
Alex can use the
git pull command:

git pull origin master

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:

git add abc.txt


git commit -m "Description of changes"

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:

diff -r dir1 dir2

This command recursively compares the contents of the two directories and
outputs the differences.

1. To download multiple files from different websites and save them in a


specific directory, you can use the wget command with appropriate URLs:

wget -P /path/to/specific_directory <URL1> <URL2> <URL3>


...

Replace <URL1> , <URL2> , <URL3> , etc., with the URLs of the files you want to
download.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Operating system type


echo "Operating system type: $(uname)"

# Current path setting


echo "Current path setting: $PATH"

# Current working directory


echo "Current working directory: $(pwd)"

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:

Switch to Tom's branch where the new feature is added:

git checkout Tom's_branch_name

Merge Tom's branch into his own branch:

git checkout Jerry's_branch_name


git merge Tom's_branch_name

Resolve any merge conflicts if they occur and commit the changes:

git commit -m "Merged Tom's feature into Jerry's bra


nch"

Push the changes to the remote repository:

git push origin Jerry's_branch_name

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".

1. To search for specific text patterns in multiple files stored on a Linux


server and display the lines containing that word or phrase, you can use
the grep command with the r option to search recursively:

grep -r "word_or_phrase" /path/to/search/directory

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.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Memory information
echo "Memory information:"
free -h

# Hard disk information


echo "Hard disk information:"
df -h

# File system (Mounted)


echo "File system (Mounted):"
df -hT

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.

Navigate to your Git repository's .git/hooks directory.

Create a new file named post-commit (without any file extension).

Write your custom script inside the post-commit file. For example:

OSS Lab 25
#!/bin/bash
echo "A commit has been made!"

Make the script executable:

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:

diff -r dir1 dir2

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:

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".

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Currently logged user and login name


echo "Currently logged user: $USER"
echo "Login name: $LOGNAME"

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

1. To show the files in the directory called "documents" located in the


"/home/user" directory using a basic Linux command, you can use the ls

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".

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Memory information
echo "Memory information:"
free -h

# Hard disk information


echo "Hard disk information:"
df -h

# File system (Mounted)


echo "File system (Mounted):"
df -hT

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

branch command combined with the b option:

# 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:

sort data.txt > sorted_names.txt

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.

1. Here's a shell script to show various system configurations:

#!/bin/bash

# Home directory
echo "Home directory: $HOME"

# Operating system type


echo "Operating system type: $(uname)"

# 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

branch command combined with the b option:

# 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

You might also like