End Course Assignment
Which of the following command is used to zip and .tar.gz file contents?
Ans: tar cvzf file.tar.gz [file or directory to be archived]
tar: stands for tape archive, which is used to create Archive and extract the Archive files.
-c: Creates an archive by bundling files and directories together.
-v: Displays verbose information, providing detailed output during the archiving or extraction process.
-z: Uses gzip compression when creating a tar file, resulting in a compressed archive with the ‘.tar.gz’ extension.
-f: Specifies the filename of the archive to be created or extracted.
Which of the following command is used to view text file contents compressed using gzip?
Ans: zcat <filename>
Find the Top 5 files in terms of disk usage in the system.
Ans: df | head -6
Find files bigger than +10M.
Ans: find / -size +10M
Which of the following suffix is used to run a process in the background?
Ans: <command> &
___________command is used to keep a process running even after shell logout.
Ans: nohup <command> <arguments>
Nohup, short for no hang up is a command in Linux systems that keep processes running even after exiting the shell or terminal. Nohup prevents the processes or jobs from receiving the SIGHUP (Signal Hang UP) signal. This is a signal that is sent to a process upon closing or exiting the terminal.
Starting a process in the background using Nohup
To start a process in the background use the
&
symbol at the end of the command. In this example, we are pinging google.com and sending it to the background.To check the process when resuming the shell use the
pgrep
command as shownIf you want to stop or kill the running process, use the
kill
command followed by the process ID as shown___________provide command interpreter environment.
Ans: Shell provides a command interpreter environment to the Linux kernel for giving instructions.
In Linux, the default configuration files are stored in ________ directory.
Ans: /etc
List all the processes whose commands don’t have any arguments. Mention the command along with the screenshot.
Ans:
a) ps - The ps (process statuses) command produces a snapshot of all running processes. Therefore, unlike the Windows task manager, the results are static.
b) top - The top command is used to discover resource-hungry processes. This Linux command will sort the list by CPU usage, so the process which consumes the most resources will be placed at the top. It’s also useful to check if a specific process is running.
c) htop - The htop command allows you to scroll vertically and horizontally. As such, you can see the complete list of your Linux processes along with their full command lines.
d) atop - The atop command is a tool for monitoring system resources in Linux. It is an ASCII full-screen performance utility that logs and reports the activity of all server processes.
You are asked to find out the IP address and MAC address of your system, which needs to be added to the whitelist of your company’s network. Mention the steps and provide the screenshot along with their respective command.
Ans: ifconfig or ip addr or ip a
Use cat to display /etc/hosts and /etc/resolv.conf. What is your idea about the purpose of these files?
Ans:
a) The /etc/hosts file in Linux or any other operating system is used to map connections between IP addresses and domain names.
b) In Linux, the /etc/resolv.conf file is known as the configuration file for DNS queries. Specifically, it translates domain names to IP addresses by querying the Domain Name Server (DNS). The /etc/resolv.conf file is the file that configures the domain name resolver.
Create two files (text.txt and text.jpg) under the Documents directory. List all the files under the Documents directory and paste the result in the results.txt file. Now display the content of the results.txt file. Mention the steps along with their respective screenshots.
Ans:
List all the files in the home directory and redirect the output to a new text file. Compress the newly generated text file and protect it with a password. Mention the steps along with their respective screenshots.
Ans:
Create a text file with some data in it. Using octal mode, change the permissions of the file such that:
User can read, write, and execute (4+2+1 =7)
Group can only execute (0+0+1 =1)
Others can only read the file (4+0+0=4)
Mention the command along with the screenshot.
Ans:
Using symbolic mode, change the permissions of a file such that:
User can read, write, and execute
Group can read and execute
Others can only execute the file
Mention the command along with the screenshot
Ans:
Execute a Linux Cron Jobs Every Second Using Crontab. Is it possible to schedule jobs every second?
Ans: You can not schedule a cron job to run every second. Cron only supports a time interval of at least 60 seconds (i.e 1 minute)
Schedule a Background Cron Job For Every 10 Minutes to find files bigger than +10M.
Ans: /10 * path/to/find / -size +10M
Syntax:
*/10 * * * * path/to/command
or
*/10 * * * * path/to/script
Schedule a Background Job Every Day using @daily to run a bash script to check disk space.
Ans: 00 11 * path/to/script
Cron job at 11:00 on every day.
Accepting Parameters-
For the inputs given along with the script, read all the inputs and display them as below-
Ans:
Read Data from Files
Have a txt file with content as the below –
Hello how ru
Iam fine
How are you doing
Iam doing good
The output should look like below –
Line No. 1 : Hello how ru
Line No.2 Iam fine
Line No.3 How are you doing
Line No.4 Iam doing good.
Total number of lines: 4
Ans: