0% found this document useful (0 votes)
89 views13 pages

Lab2 SE181589

The document provides examples and syntax for various Linux commands including man, bg, fg, who, chown, chgrp, chmod, date, su, top, and kill. It asks to capture the output of running the command "grep "nhu nui" thoca.txt" and explain the result. It also asks to submit a C/C++ program that uses the system() function to run the command "man ls", capture the result, and explain the output.

Uploaded by

mannvse181589
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)
89 views13 pages

Lab2 SE181589

The document provides examples and syntax for various Linux commands including man, bg, fg, who, chown, chgrp, chmod, date, su, top, and kill. It asks to capture the output of running the command "grep "nhu nui" thoca.txt" and explain the result. It also asks to submit a C/C++ program that uses the system() function to run the command "man ls", capture the result, and explain the output.

Uploaded by

mannvse181589
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/ 13

Submission

• Present the content of manipulating of some command (including syntax, what


does it for?, capture two of examples for each command) as
o man: Displays the manual pages for commands and other documentation.
Syntax: man [OPTION …] [SECTION] PAGE …]
man -ls

man -sudo
o bg: Puts a suspended or background job into the background, allowing it to continue running.
Syntax: bg jobID
bg jobID1 jobID2 ... jobIDn
fg: Brings a job to the foreground, making it the active process in the terminal.
Syntax: fg jobID
fg jobID1 jobID2 ... jobIDn
bg %1 is used to resume the sleep command as a background job
fg %sleep is used to bring the sleep command to the foreground

o who: Displays a list of logged-in users with their usernames, terminal, and login time.
Syntax: who [OPTION]
who -q: Displays only the total number of logged-in users.

o chown, chgrp, chmod


chown: Change the ownership of files and directories in a filesystem.
Syntax: chown [OPTION] [USER]:[GROUP] FILE
chown se183682 thoca.txt: Change the owner of thoca.txt from root to user se183682
Chown root thoca.txt: Change the owner of thoca.txt from user se183682 to root user

chgrp: Changes the group ownership of a file or directory.


Syntax: chgrp [OPTION] … GROUP FILE

chgrp -hR root se183682

chmod: Changes the permissions of a file or directory.


Syntax: chmod [OPTION] … MODE[,MODE] … FILE …
chmod g+r thoca.txt: Adds read permission for the group of the file.

chmod -R 644 /hdh/windows/98: Set the permission of the folder 98 and all the files it contains

to mode 644

o date: Displays or sets the system date and time.


Syntax: date [OPTION] … [+FORMAT]
date
date -u: Displays the current date and time in UTC (Coordinated Universal Time).

o su, top, kill, jobs


su: Switches to another user account, typically to gain administrative privileges.
Syntax: su [OPTIONS] [-] [<USER> [<ARGUMENT>…]]
su se183682: switch to user se183682
su: switch to root user

top: Displays real-time information about system processes and resource usage.

Syntax: top [OPTIONS]

top
top -u se183682: Filters and displays processes owned by the user "se183682".

kill: Sends a signal to terminate or control a process specified by its process ID (PID).
Syntax: kill [OPTIONS] PID
kill 4436: kill the process top
• Capture the terminal screen using the “grep “nhu nui” thoca.txt” and give your
explanation the result. (Notes: thoca.txt is the file in above tutorial)

Explanation:
The command grep "nhu nui" thoca.txt is used to search for the string "nhu nui" in the contents
of the file thoca.txt.
When this command is run, grep will open the thoca.txt file and search for the occurrence of
the exact string "nhu nui" in its contents. If a line within the file contains the specified pattern,
grep will output that line to the terminal with the string “nhu nui” in red color.
• Submit the C/C++ files and objects files as the below content then capture the
result of the program and explanation your result that you get
Result:

Explanation:
The program declare an int variable “ret” to store the value returned by the system() function.
The code system(“man ls”) represents a command to be executed by the operating system's
shell. The line “man ls” displays the manual page for the "ls" command in Unix-like systems.
The system() function executes the command by invoking the shell, and it returns the exit status
of the command as an integer value.
The return value of the system() function is assigned to the ret variable.
Finally, the main() function returns the value stored in ret as the exit status of the program.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy