0% found this document useful (0 votes)
67 views34 pages

Practical 1 - 9 COM 115

computer science practicaltt

Uploaded by

ilelaboye1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views34 pages

Practical 1 - 9 COM 115

computer science practicaltt

Uploaded by

ilelaboye1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

NAME: KOMOLAFE JOSEPH OLUWATOYIN

MATRIC NO: F/ND/22/3210026


COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK ONE


1. What are the functions of operating system?
a. Security
The operating system uses password protection to protect user data and similar other techniques. it
also prevents unauthorized access to programs and user data.

b. Control over system performance:


Monitors overall system health to help improve performance records the response time between
service requests and system response to having a complete view of the system health. This can help
improve performance by providing important information needed to troubleshoot problems.

c. Job accounting:
Operating system Keeps track of time and resources used by various tasks and users, this information
can be used to track resource usage for a particular user or group of users.

d. Error detecting aids:


The operating system constantly monitors the system to detect errors and avoid the malfunctioning
of a computer system.

e. Coordination between other software and users:


Operating systems also coordinate and assign interpreters, compilers, assemblers, and other
software to the various users of the computer systems.

f. Memory Management:
The operating system manages the Primary Memory or Main Memory. Main memory is made up of a
large array of bytes or words where each byte or word is assigned a certain address. Main memory is
fast storage and it can be accessed directly by the CPU. For a program to be executed, it should be
first loaded in the main memory. An Operating System performs the following activities for memory
management.

g. Control over system performance –


Monitors overall system health to help improve performance records the response time between
service requests and system response to having a complete view of the system health. This can help
improve performance by providing important information needed to troubleshoot problems.

2. Explain different categories of operating system


BATCH OPERATING SYSTEMS
The batch operating system does not have a direct link with the computer. A different system divides
and allocates similar tasks into batches for easy processing and faster response. The batch operating system is
appropriate for lengthy and time-consuming tasks. To avoid slowing down a device, each user prepares their
tasks offline and submits them to an operator.
TIME-SHARING OR MULTITASKING OPERATING SYSTEMS
The time-sharing operating system, also known as a multitasking OS, works by allocating time to a
particular task and switching between tasks frequently. Unlike the batch system, the time-sharing system
allows users to complete their work in the system simultaneously. It allows many users to be distributed
across various terminals to minimize response time.

DISTRIBUTED OPERATING SYSTEMS


This system is based on autonomous but interconnected computers communicating with each other
via communication lines or a shared network. Each autonomous system has its own processor that may differ
in size and function. A distributed operating system serves multiple applications and multiple users in real-
time. The data processing function is then distributed across the processors.

Real-time operating systems


Real-time operating systems provide support to real-time systems that require observance of strict
time requirements. The response time between input, processing and response is tiny, which is beneficial for
processes that are highly sensitive and need high precision

3. Explain the types of operating system


Microsoft Windows:
Created by Microsoft, Microsoft Windows is one of the most popular proprietary operating systems for
computers in the world. Most personal computers come preloaded with a version of Microsoft Windows. One
downside of Windows is that compatibility with mobile phones has been problematic.

Apple iOS:
Apple iOS from Apple is used on smartphones and tablets manufactured by the same company. Users of this
system have access to hundreds of applications. The operating system offers strong encryption capabilities to
control unauthorized access to users' private data.\

Apple macOS:
Developed by Apple, this proprietary operating system runs on the manufacturer's personal computers and
desktops. All Apple and Macintosh computers come equipped with the latest version of macOS, previously
known as OS X systems. The ability to prevent bugs and fend off hackers make Apple operating systems
popular with their users.
NAME: KOMOLAFE JOSEPH OLUWATOYIN
MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK TWO


1. What are the advantages and disadvantages of Linux operating system?
a. Cost
Linux operating system comes with General Public License (GPL). Different from windows it does not
require any licenses. So the OS is free to use. Even some of the software’s are entirely free on Linux. This
makes Linux highly cost effective. You can find good windows alternative programs in the software
manager.

b. Security
On default, Linux is designed to be secure. Unlike Windows, Linux is not much exposed to viruses. On
very rare occasions, Linux is virus affected. That is the reason why Linux users do not normally install an
Antivirus software. And also hackers are not very interested in Linux due to its low market share. Even if it
is, they cannot easily hijack the system since there are locks on each layers.

c. Source Code
Linux is an operating system which is of open source base. Which means that the code is free to
modify. Users can easily change the code based on their needs. Thus, you can customize your own
personal operating system. However, you will need to have the appropriate programming knowledge.

d. System Requirements
Linux OS can even run on systems with low specifications. It is not very resource intensive like windows
operating system. All the components like memory, diskspace and CPU are lower in this OS. So you do not
need to upgrade your existing hardware for existing hardware for installing this OS. This is a fact that
makes Linux a greater choice for all systems.

Disadvantages of Linux Operating System


a. Adaptation
For people who are less expertise in computers it can be hard to understand Linux. Most users find it
difficult to adopt to Linux due to the terminals used. Terminals are command line interface where you
need to enter specific command in order to complete tasks. Furthermore, the level of difficulty varies
according to the distribution used. For distributions like Arch, learning to use Linux becomes even more
difficult.

b. Software Compatibility
Popular applications which are made for Windows and Mac are not available for Linux. Many
developers are not interested in making softwares for Linux due to its small market value. Some of such
softwares are MS Office, iTunes and Photoshop. Even though there are alternatives to these softwares,
they cannot match up to the original level.

c. Gaming
Similar to sofwares, games too doesn't natively support Linux. Because Linux is not a platform which is
not widely used, gaming developers are not much interested in Linux. So you cannot expect your favorite
game to run on Linux. However, the number of games developed for Linux is on a rise in the recent years.
Al though you can use third party softwares like Steam to download any gaming title, still the game will not
run smoothly as it does on native operating system.
d. Hardware Compatibility
Almost all the hardware’s can be connected to a Linux operating system. But the problem comes with the
drivers. The concept of drivers in Linux is very different from other operating system. The drivers here are
inbuilt inside the Kernel. Since the drivers are already preinstalled, the newly connected hardware device
may not have the proper drivers. This makes the connected hardware device to be incompatible.

2. What kinds of Linux are there and how do you choose the one that fits the you?
a. Debian
Debian is renowned for being a mother to popular Linux distributions such as Deepin, Ubuntu, and
Mint which have provided solid performance, stability, and unparalleled user experience. The latest stable
release is Debian 10.5, an update of Debian 10 colloquially known as Debian Buster.
b. Gentoo
Gentoo is a distro built for professional use and experts who take into consideration what packages
they are working with from the word go. This category includes developers, system & network
administrators. As such, it’s not ideal for beginners in Linux. Gentoo comes recommended for those who
want to have a deeper understanding of the ins and outs of the Linux operating system.
c. Ubuntu
Created and maintained by Canonical, Ubuntu is one of the most popular Linux distros enjoyed across
the globe by beginners, intermediate users, and professionals alike. Ubuntu was specifically designed for
beginners in Linux or those transitioning from mac and Windows.

Choosing the linux os that suits you, you should take into consideration how strong your pc is. Its also
advisable to pick the most user friendly linux os for easy understanding.

3. What are the open source and GNU movements?


Open source is a term that originally referred to open source software (OSS). Open source software is
code that is designed to be publicly accessible—anyone can see, modify, and distribute the code as they see
fit.
Open source software is developed in a decentralized and collaborative way, relying on peer review
and community production. Open source software is often cheaper, more flexible, and has more longevity
than its proprietary peers because it is developed by communities rather than a single author or company.
Open source has become a movement and a way of working that reaches beyond software production. The
open source movement uses the values and decentralized production model of open source software to find
new ways to solve problems in their communities and industries.

GNU movements?
GNU is a Unix-like operating system. That means it is a collection of many programs: applications,
libraries, developer tools, even games. The development of GNU, started in January 1984, is known as the
GNU Project. Many of the programs in GNU are released under the auspices of the GNU Project; those we
call GNU packages.

The name “GNU” is a recursive acronym for “GNU's Not Unix.” “GNU” is pronounced g'noo, as one syllable,
like saying “grew” but replacing the r with n.
The program in a Unix-like system that allocates machine resources and talks to the hardware is called the
“kernel”. GNU is typically used with a kernel called Linux. This combination is the GNU/Linux operating
system. GNU/Linux is used by millions, though many call it “Linux” by mistake.

GNU's own kernel, the GNU Hurd, was started in 1990 (before Linux was started). Volunteers continue
developing the Hurd because it is an interesting technical project.
NAME: KOMOLAFE JOSEPH OLUWATOYIN
MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK THREE

1. Explain how to connect and disconnect to the system

The following command lines can be used to connect and disconnect depending on the Wireless card, wireless
security and wireless router settings. Before proceeding, make sure the network service is enabled (For cases
where you might start Ubuntu using Recovery mode): Depending on your Ubuntu Version, you would need to
start it using one of the following way:

If using SystemD (since 14.10+):

sudo systemctl start networking


If using the Legacy init.d way: sudo /etc/init.d/networking restart
If using the Legacy Upstart way: sudo service network-manager restart

Part 1: Wireless Routers with no password or WEP Key


For cases where the wireless router has no password or WEP security, do the following:

1. Open the terminal and lookup for the wireless connection:

2. iwlist wlan0 s
(The s is for Scan. wlan0 is my wireless card but could be different for each user. Some have eth0, others
wlan2.. You need sudo to execute this option.To find out the name of your wireless card simply type iwlist
and press TAB. This should autocomplete the line with the network card's name. You can also
type iwconfig and find the name on the list that will show.)
If you do not know the name of your wireless devices type: iwconfig which will show you your
wired/wireless devices and their names. They might be something like wlan0, wlan1, eth1, eth2..
3. The lookup will show you all possible Access Points (AP) visible to you. After you see your router in the list
try to connect to it:

If it does not have a password do the following:

iwconfig wlan0 essid NAME_OF_ACCESS_POINT


For example

iwconfig wlan0 essid CYREX


after that, make sure to use dhclient so you can get a dynamic IP in case you don't get assigned one by the
router. That should leave you connected to the CYREX router.

If it has a password then do:


iwconfig wlan0 essid CYREX key PASSWORD
That should connect using the PASSWORD you gave there.

Again, do dhclient after connecting to make sure you get an IP assigned.


4. Making sure you are correctly connected is always good so execute iwconfig to make sure your wireless
card is connected to the SSID you mentioned above. It should show your device connected and the IP
assigned to you. If it does not and gives you an error like Interface doesn't support scanning try the
following 2 options:
 Test if your interface is UP: sudo ifconfig wlan0 up
 Try adding sudo when doing the scan: sudo iwlist wlan0 s
 Try bringing the device down and then back up:

 sudo ifconfig wlan0 down


 sudo ifconfig wlan0 up

Disconnecting from a Wireless Router


There are several ways of accomplishing this:

 Disconnect by "force": sudo ifconfig wlan0 down


This will turn your wireless card interface off (Driver turns off). To turn in on simply type ifconfig wlan0
up followed by a sudo dhclient wlan0. It will still show as connected if viewed by Network Manager but
there will actually be no connection to the router. Trying to ping will throw an connect: Network is
unreachable error.
 Release the DHCP IP: sudo dhclient -r wlan0
Remember to do sudo dhclient wlan0 to assign yourself an IP again.
 Disconnect using Network Manager: nmcli nm enable false
Where nm is the parameter of nmcli that manages and sets Network Manager's states. The
option enable can be true or false, meaning if set to false, all network connections managed by Network
Manager will be disconnected. note that nmcli does not need root permissions.
To see the status of Network Manager type nmcli nm, it should show something similar to this:
$ nmcli nm
RUNNING STATE WIFI-HARDWARE WIFI WWAN-HARDWARE WWAN
running connected enabled enabled enabled enabled
Another way of turning the Connection On or Off (Connecting/Disconnecting) is by doing the following:

nmcli c down id NAME` - Will disconnect the connection NAME

nmcli c up id NAME` - Will connect the connection NAME

2. Describe how to determine file type


In Linux, everything is considered as a file. In UNIX, seven standard file types are regular, directory, symbolic
link, FIFO special, block special, character special, and socket. In Linux/UNIX, we have to deal with different file
types to manage them efficiently.
In Linux/UNIX, Files are mainly categorized into 3 parts:
1. Regular Files
2. Directory Files
3. Special Files
The easiest way to find out file type in any operating system is by looking at its extension such as .txt, .sh, .py,
etc. If the file doesn’t have an extension then in Linux we can use file utility. In this article, we will
demonstrate file command examples to determine a file type in Linux.

Ways to Find Out File System Types in Linux


Linux has a useful utility called file which carry out some tests on a specified file and prints the file type once a
test is successful. In this short article, we will explain useful file command examples to determine a file type in
Linux.

$ file -v

file-5.33
magic file from /etc/magic:/usr/share/misc/magic

Linux file Command Examples

1. The simplest file command is as follows where you just provide a file whose type you want to find out.

$ file etc

Find File Type in Linux


2. You can also pass the names of the files to be examined from a file (one per line), which you can specify
using the -f flag as shown.

$ file -f files.list

Find Files Type in Filename List


3. To make file work faster you can exclude a test (valid tests include apptype, ascii, encoding, tokens, cdf,
compress, elf, soft and tar) from the list of tests made to determine the file type, use the -e flag as shown.

$ file -e ascii -e compress -e elf etc

4. The -s option causes file to also read block or character special files, for example.

$ file -s /dev/sda

/dev/sda: DOS/MBR boot sector, extended partition table (last)

5. Adding the -z options instructs file to look inside compressed files.

$ file -z backup

Determine
Compressed Files
3. Describe how to find help in Linux environment

Use the command options –h or –help


If you don’t know how to use a command i.e. you don’t know about its parameters and return type etc, then
you can make use of –h or –help command.

How to use –h or –help?


Launch the terminal by pressing Ctrl+ Alt+ T or just click on the terminal icon in the taskbar. Simply type your
command whose usage you to know in the terminal with –h or –help after a space and press enter. And you’ll
get the complete usage of that command as shown below.
NAME: KOMOLAFE JOSEPH OLUWATOYIN
MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK FOUR


1. Describe the most important files, including kernel and shell

What is a Shell?
It refers to a special user program or an environment that provides a user with an interface for using the
services of the operating system. A shell executes various programs on the basis of the input that a user
provides.

What is a Kernel?
A kernel is basically the core and the heart of an OS (Operating system). It functions to manage the operations
of the hardware and the computer. A kernel basically acts as a bridge between any user and the various
resources offered by a system by accessing the various resources of a computer, such as the I/O devices, CPU,
and various other resources.

Difference Between Shell and Kernel


Let us talk about the differences present between Shell and Kernel.

Parameters Shell

Basics A shell is basically an interface present between the kernel and the user.

Meaning A shell is a CLI (command-line interpreter).

Uses and A shell allows all of its users to establish communication with the kernel.
Purpose

Types Korn Shell, C Shell, Bourne Shell, etc., are types of shells.

Functions We can use shell commands such as mkdir, ls, and many more for requesting the completion of the
operating system (OS).

Management A shell performs memory management.

Layer of OS The shell forms the outer layer of the operating system.

2. Describe how to display contents of files


Cat
The simplest way to view text files in Linux is the cat command. It displays the complete contents in the
command line without using inputs to scroll through it.
Here is an example of using the cat command to view the Linux version by displaying the contents of
the /proc/version file.

Head
Sometimes the information needed is in the first lines of a file. In that case, use the head command to view
the first ten lines of a file in Linux. For example, users can display basic information about the CPU used by
viewing the beginning of the /proc/cpuinfo file.

Like the tail command, use the -n flag with the head command to display the desired number of lines, starting
from the beginning of a given file. For example, head -5 shows the first five lines of a given file.

Tail
While the cat command is helpful when dealing with a small file, it is not the best way to view large log files.
The tail command allows viewing the last ten lines of a file by default instead of filling your terminal window
with a wall of text, making it the perfect command to use if you want to check the last log entries.
Here is the output of the tail command.
3. What are the properties of file and describe how to change file permissions

View file permissions


To view the permissions for all files in a directory, use the ls command with the -la options. Add other options
as desired; for help, see List the files in a directory in Unix.

For example, if you enter:

ls -lah

You should see output similar to the following:

-rw-r--r-- 1 user1 group1 62 Jan 15 16:10 myfile.txt

drwxr-xr-x 2 user1 group1 2048 Jan 15 17:10 Example

In the output example above, the first character in each line indicates whether the listed object is a file or a
directory. Directories are indicated by a (d); the absence of a d at the beginning of the first line indicates
that myfile.txt is a regular file.

The letters rwx represent different permission levels:

Permission Files Directories

R can read the file can ls the directory

W can write the file can modify the directory's contents


Permission Files Directories

X can execute the file can cd to the directory

Note the multiple instances of r, w, and x. These are grouped into three sets that represent different levels of
ownership:

 Owner or user permissions: After the directory (d) slot, the first set of three characters indicate permission
settings for the owner (also known as the user).

In the example -rw-r--r--, the owner permissions are rw-, indicating that the owner can read and write to the
file but can't execute it as a program.

In the example drwxr-xr-x, the owner permissions are rwx, indicating that the owner can view, modify, and
enter the directory.

 Group permissions: The second rwx set indicates the group permissions. In the fourth column of the example
above, group1 is the group name.

In the example -rw-r--r--, group members can only read the file.

In the example drwxr-xr-x, group members can view as well as enter the directory.

 Other permissions: The final rwx set is for "other" (sometimes referred to as "world"). This is anyone outside
the group. In both examples above, these are set to the same permissions as the group.
Change file permissions
To change file and directory permissions, use the command chmod (change mode). The owner of a file can
change the permissions for user (u), group (g), or others (o) by adding (+) or subtracting (-) the read, write, and
execute permissions.

There are two basic ways of using chmod to change file permissions: The symbolic method and the absolute
form.

NAME: KOMOLAFE JOSEPH OLUWATOYIN


MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK FIVE


1. Differentiate between multi-user and multi-tasking processing in Linux

Multiuser
A multi-user operating system is an operating system that permits several users to access a single system
running to a single operating system. These systems are frequently quite complex, and they must manage the
tasks that the various users connected to them require. Users will usually sit at terminals or computers
connected to the system via a network and other system machines like printers. A multi-user operating system
varies from a connected single-user operating system in that each user accesses the same operating system
from different machines.

Multitasking in Linux
Today most major operating systems employ multitasking. Earlier versions of the Macintosh and Microsoft
Windows used cooperative multitasking. Preemptive multitasking operating systems include Linux and
other Unix-like systems, Microsoft Windows NT/2000/XP, Mac OS X and OS/2.
Unix-like operating systems were developed right from the start as preemptive multitasking and multi-user
systems. These are among the features that have helped make them an extremely efficient and robust (as well
as highly successful and long-lived) family of operating systems. (They are also multiprocessor operating
systems, which means that they can make effective use of computers that have more than a single CPU.)

2. Describe how to control processes with different signals

A signal is one of the basic things you would have frequently encountered once you start getting familiar with a
Linux system. Getting to know about how they work is important since signals play a big role in processes.As
usual, we will start off with some basics and then move on to some advanced topics.A signal is a notification to
a process that an event has occurred. Signals are sometimes described as software interrupts, because in most
cases, they interrupt the normal flow of execution of a program and their arrival is unpredictable.A signal can
be sent by Kernel or a Process.
Different ways for the reception of a signal

For the rest of the article, we will focus on signals sent by the Kernel and not by processes.

A Kernel may send a signal to a process in the following scenarios:

1. When a hardware exception has occurred and that exception needs to be notified to the process. For eg.
Attempting division by zero, or referencing the part of memory that is inaccessible.

2. Some software event occurred outside the process’s control but effects the process. For instance, input
became available on a file descriptor, the terminal window got resized, process’s CPU time limit exceeded,
etc.

3. User typed some terminal special characters like interrupt(Ctrl+C) or suspend character(Ctrl+Z).

The signals sent by the Kernel to notify processes about events are called traditional signals.

3. Explain the process of system startup and shutdown in Linux operating system

Starting the System

To start up a system, follow these steps:

1. Make sure all cables (such as power, display monitor cable, and keyboard) are properly connected. See
your owner's guide and hardware guide for complete information about cabling your particular
workstation or server.

2. Turn on the power switches on the display monitor (or console terminal) and the computer.

The computer runs power-on diagnostics and displays some copyright messages and some system
startup information. These messages appear on the console screen or on the screen of a diagnostics
terminal (an ASCII terminal connected to the first serial port) of a server. A copy of these messages is
also written to the /var/adm/SYSLOG file in case you miss them.

Shutting Down the System

This section describes how to turn off a workstation or server from multiuser or single-user mode.

Shutting Down from Multiuser Mode

To shut down the system from multiuser mode:

1. Use the who(1) command to determine which users are logged in to the operating system, if any:

Notify any users that the system is shutting down. Issue the /etc/wall(1M) command:

wall

Enter your message. For example, you might enter:

There is a problem with the building's power system.


I will be shutting down the system in 10 minutes.
Please clean up and log off.
Sorry for the inconvenience,
norton

2. When you finish entering your message, type <Ctrl-D>. The message is sent to all users on the system.
They see something like this:

Broadcast Message from root Tue Oct 17 17:02:27...


There is a problem with the building's power system.
I will be shutting down the system in 10 minutes.
Please clean up and log off.
Sorry for the inconvenience,
norton

3. Issue the /etc/shutdown command:

/etc/shutdown -y -i0 -g600

The above command specifies a 10 minute (600 second) grace period to allow users to clean up and log
off. The other flags indicate that the system is to be completely shut down (-i0) and that the system
can assume that all answers to any prompts regarding the shutdown are ``yes.'' You see the following
message:

Shutdown started. Fri Aug 28 17:10:57...


Broadcast Message from root (console) Fri Aug 28 17:10:59
The system will be shut down in 600 seconds.
Please log off now.

After ten minutes, you see this message:

INIT: New run level: 0


The stem is coming down. Please wait.

The Command Monitor prompt or System Maintenance menu appears. Wait for a Command Monitor
prompt or System Maintenance menu to appear before turning off power to the workstation or you
may damage your hard disk.

4. You can now turn off the power.

For more information on shutting down the system, see the halt(1M) and shutdown(1M) reference pages.
Remember that you should shut down the system only when something is wrong or if modifications to the
software or hardware are necessary.

NAME: KOMOLAFE JOSEPH OLUWATOYIN


MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK SIX


1. Explain how to use output of one command as input for another
BASH
BASH defines three configurations files: .bash_profile, .bashrc, and
.bash_logout. .bash_profile contains initialization commands that set
environment variables, a shell's prompt and so on. The .bashrc contains
commands that configure the shell, define command aliases and set
command shell options. .bash_profile is executed automatically when a
user logs into a shell, along with .bashrc. The .bash_logout file is
executed when the user logs out of a shell. .bash_logout contains
cleanup operations and other commands that you want the shell to execute
whenever a user logs out of a shell. For example, it can include
commands that clear the screen and print a farewell message. Unlike the
.bash_profile file, which is created automatically when you open a new
account, you have to create the .bash_logout by yourself using a text
editor such as vi, emacs, etc.
In the following example, the .bash_logout file contains commands that
clear the screen and print a reminder to the user to take her diskette
from the disk drive:
clear
echo "don't forget to remove your homework exercises diskette from the
diskette drive!"
Other Shells
Other shells have similar configuration files, albeit with different
names. Thus, instead of the BASH .bash_profile, .bashrc, and
.bash_logout configuration files, TCSH uses the .login, .tcshrc and
.logout configuration files, respectively. Likewise, Z-shell uses the
files .zshenv, .zprofile, and .zlogin for initialization, .zshrc as a
configuration file equivalent to .bashrc, and .zlogout as the equivalent
of .bash_logout. The PDKSH shell uses the .profile and .kshrc files for
initialization and shell configuration, respectively.
A correction
In last week's newsletter, the meaning of the arguments +o and -o got
inverted. The +o argument actually turns a feature off whereas -o turns
it on. Thanks to all the readers who have drawn my attention to this
typo.
2 Explain how to put output of a command in a file for later reference

Use redirection to save command output to file in Linux


You can use redirection in Linux for this purpose. With redirection operator, instead of showing the output on
the screen, it goes to the provided file.
 The > redirects the command output to a file replacing any existing content on the file.
 The >> redirects adds the command output at the end of the existing content (if any) of the file.

Use the STDOUT redirection operator > for redirecting the output to a file like this:

command > file.txt


If the file.txt doesn’t exist, it will be created automatically. If you use the > redirect again with the same file,
the file content is replaced by the new output.

The example below demonstrates it better. It first saves the output of ls -l command. And then later, it
replaces the content of the file with the output of ls *.c command.

Redirecting command output to file


If you don’t want to lose the content of the existing file while saving the output of a script or command, use
the redirection operation in append mode with >>.

command >> file.txt


This example demonstrates it better:
Redirecting command output to file in append mode
Even here if the file doesn’t exist, it is created automatically.

Bonus Tip: Save Linux command output as well as error to a file


If your Linux command returns an error, it doesn’t get saved in the file. You can save both the command
output and command error in the same file using 2>&1 like this:

command > file.txt 2>&1

Basically, 0 stands for standard input, 1 for standard output and 2 for standard error. Here, you are redirecting
(>) standard error (2) to same address (&) as standard output (1).

3. Explain how to append output of multiple commands to a file


Using echo & Printf
The simplest way to append multiple lines to a file is to use the echo and printf command.

0 seconds of 30 secondsVolume 0%
Let us start with echo.
Echo is a command used to output a string or multiple strings as arguments. Echo is available n all Linux
distributions, making it a good tool for redirecting output to a file.
Let us start by verifying the file is not empty.

cat multiple.tx
As shown in the output above, the file is not empty; it contains lines of text.

To add multiple lines to a file with echo, use the -e option and separate each line with \n.

When you use the -e option, it tells echo to evaluate backslash characters such as \n for new line.

echo -e "Hello, world\nBash scripting is awesome\nThis is a new line" >> multiple.txt


If you cat the file, you will realize that each entry is added on a new line immediately after the existing
content.

cat multiple.txt
The printf
Let us now look at printf. Using the printf command is very similar to the echo command. To append multiple
lines with printf command:

printf "Learn Bash scripting basics here\


nhttps://linuxhint.com/bash_scripting_tutorial_beginners/" >> multiple.txt
Similarly, cating the command provides a similar output as:

cat multiple.txt
NAME: KOMOLAFE JOSEPH OLUWATOYIN
MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK SEVEN


1. Start the Vim tutor by entering vimtutor in a terminal session
2. Start emacs and type Ctrl+H and then T to invoke the self-paced Emacs tutorial
NAME: KOMOLAFE JOSEPH OLUWATOYIN
MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK EIGHT


1. Describe the common shell setup files
BASH

BASH defines three configurations files: .bash_profile, .bashrc, and

.bash_logout. .bash_profile contains initialization commands that set

environment variables, a shell's prompt and so on. The .bashrc contains

commands that configure the shell, define command aliases and set

command shell options. .bash_profile is executed automatically when a

user logs into a shell, along with .bashrc. The .bash_logout file is

executed when the user logs out of a shell. .bash_logout contains

cleanup operations and other commands that you want the shell to execute

whenever a user logs out of a shell. For example, it can include

commands that clear the screen and print a farewell message. Unlike the

.bash_profile file, which is created automatically when you open a new

account, you have to create the .bash_logout by yourself using a text

editor such as vi, emacs, etc.

In the following example, the .bash_logout file contains commands that

clear the screen and print a reminder to the user to take her diskette

from the disk drive:

clear

echo "don't forget to remove your homework exercises diskette from the

diskette drive!"

OTHER SHELLS

Other shells have similar configuration files, albeit with different


names. Thus, instead of the BASH .bash_profile, .bashrc, and

.bash_logout configuration files, TCSH uses the .login, .tcshrc and

.logout configuration files, respectively. Likewise, Z-shell uses the

files .zshenv, .zprofile, and .zlogin for initialization, .zshrc as a

configuration file equivalent to .bashrc, and .zlogout as the equivalent

of .bash_logout. The PDKSH shell uses the .profile and .kshrc files for

initialization and shell configuration, respectively.

2. Explain how to install a new sound and video applications

AppImage portable apps


The AppImage format is relatively new to Linux, although its concept is based on both NeXT and Rox. The idea
is simple: everything required to run an application is placed into one directory, and then that directory is
treated as an "app." To run the application, you just double-click the icon, and it runs. There's no need or
expectation that the application is installed in the traditional sense; it just runs from wherever you have it
lying around on your hard drive.

Despite its ability to run as a self-contained app, an AppImage usually offers to do some soft system
integration.

If you accept this offer, a local .desktop file is installed to your home directory. A .desktop file is a small
configuration file used by the Applications menu and mimetype system of a Linux desktop. Essentially, placing
the desktop config file in your home directory's application list "installs" the application without actually
installing it. You get all the benefits of having installed something, and the benefits of being able to run
something locally, as a "portable app."
Application directory
Sometimes, a developer just compiles an application and posts the result as a download, with no install script
and no packaging. Usually, this means that you download a TAR file, extract it, and then double-click the
executable file (it's usually the one with the name of the software you downloaded)

When presented with this style of software delivery, you can either leave it where you downloaded it and
launch it manually when you need it, or you can do a quick and dirty install yourself. This involves two simple
steps:

1. Save the directory to a standard location and launch it manually when you need it.
2. Save the directory to a standard location and create a .desktop file to integrate it into your system.

If you're just installing applications for yourself, it's traditional to keep a bin directory (short for "binary") in
your home directory as a storage location for locally installed applications and scripts. If you have other users
on your system who need access to the applications, it's traditional to place the binaries in /opt. Ultimately,
it's up to you where you store the application.

Downloads often come in directories with versioned names, such as twine_2.13 or pcgen-v6.07.04. Since it's
reasonable to assume you'll update the application at some point, it's a good idea to either remove the
version number or to create a symlink to the directory. This way, the launcher that you create for the
application can remain the same, even though you update the application itself.

To create a .desktop launcher file, open a text editor and create a file called twine.desktop. The Desktop Entry
Specification is defined by FreeDesktop.org. Here is a simple launcher for a game development IDE called
Twine, installed to the system-wide /opt directory:

[Desktop Entry]
Encoding=UTF-8
Name=Twine
GenericName=Twine
Comment=Twine
Exec=/opt/twine/Twine
Icon=/usr/share/icons/oxygen/64x64/categories/applications-games.png
Terminal=false
Type=Application
Categories=Development;IDE;

The tricky line is the Exec line. It must contain a valid command to start the application. Usually, it's just the
full path to the thing you downloaded, but in some cases, it's something more complex. For example, a Java
application might need to be launched as an argument to Java itself:

Exec=java -jar /path/to/foo.jar

Sometimes, a project includes a wrapper script that you can run so you don't have to figure out the right
command:
Exec=/opt/foo/foo-launcher.sh

In the Twine example, there's no icon bundled with the download, so the example .desktop file assigns a
generic gaming icon that shipped with the KDE desktop. You can use workarounds like that, but if you're more
artistic, you can just create your own icon, or you can search the Internet for a good icon. As long as
the Icon line points to a valid PNG or SVG file, your application will inherit the icon.

The example script also sets the application category primarily to Development, so in KDE, GNOME, and most
other Application menus, Twine appears under the Development category.

To get this example to appear in an Application menu, place the twine.desktop file into one of two places:

 Place it in ~/.local/share/applications if you're storing the application in your own home directory.
 Place it in /usr/share/applications if you're storing the application in /opt or another system-wide location
and want it to appear in all your users' Application menus.

And now the application is installed as it needs to be and integrated with the rest of your system.

Compiling from source

Finally, there's the truly universal install format: source code. Compiling an application from source code is a
great way to learn how applications are structured, how they interact with your system, and how they can be
customized. It's by no means a push-button process, though. It requires a build environment, it usually
involves installing dependency libraries and header files, and sometimes a little bit of debugging.

3. Describe language and font settings


Fontconfig is a library designed to provide a list of available fonts to applications, and also for configuration
for how fonts get rendered. The FreeType library renders the fonts, based on this configuration.
The freetype2 font rendering packages on Arch Linux include the bytecode interpreter (BCI) enabled for better
font rendering especially with an LCD monitor. See #Fontconfig configuration and Font
configuration/Examples.
Though Fontconfig is used often in modern Unix and Unix-like operating systems, some applications rely on
the original method of font selection and display, the X Logical Font Description.Font pathsFor fonts to be
known to applications, they must be cataloged for easy and quick access.
The font paths initially known to Fontconfig are: /usr/share/fonts/, ~/.local/share/fonts (and ~/.fonts/, now
deprecated). Fontconfig will scan these directories recursively. For ease of organization and installation, it is
recommended to use these font paths when adding fonts.
To see a list of known Fontconfig fonts:

$ fc-list : file

See fc-list(1) for more output formats.


Check for Xorg's known font paths by reviewing its log:
$ grep /fonts ~/.local/share/xorg/Xorg.0.log

Tip:

 You can also check the list of Xorg's known font paths using the command xset q.
 Use /var/log/Xorg.0.log if Xorg is run with root privileges.
Keep in mind that Xorg does not search recursively through the /usr/share/fonts/ directory like Fontconfig
does. To add a path, the full path must be used:

Section "Files"
FontPath "/usr/share/fonts/local/"
EndSection
NAME: KOMOLAFE JOSEPH OLUWATOYIN
MATRIC NO: F/ND/22/3210026
COURSE: INTRODUCTION TO LINUX OPERATING SYSTEM (PRACTICAL)
COURSE CODE: COM 111

PRACTICAL EXERCISE - WEEK NINE

1. Describe how to format a document


Sometimes our text files are not well format to represent. This work can be done manually for small file, but if
the file is too large then manually formatting is so tough work. In such a case to format the contents of a text
file in the Linux operating system, we use the fmt command.
The fmt command is used to format, simplifying, and optimizing text files in the Linux system. If the file is not
specified then the fmt command reads input from standard input. By default, the fmt command creates text
to a width of 75 characters wide.

Syntax

The general syntax of the fmt command is as follows −


fmt [-WIDTH] [OPTION]... [FILE]...
Brief description of options available in the fmt command.

Sr.No. Option & Description

1 -c, --crown-marginPreserve the indentation of the first two lines

2 -p, --prefix=STRINGReformat beginning lines with specified STRING, reattaching the prefix
to reformatted lines.

3 -s, --split-onlySplit only long lines, but don’t refill

4 -t, --tagged-paragraph Indentation of first-line different from second

5 -u, --uniform-spacingOne space between words, two after sentences

6 -w, --width=WIDTH Maximum line width (default of 75 columns)

7 -g, --goal=WIDTH Goal width (default of 93% of width)

8 --helpDisplays a help message and then exits.

9 --versionIt gives info about the version and then exits.


Here, we will format text from standard input instead of a file in the Linux system using the fmt command as
shown below.
$ fmt
Hey,
welcome
to
Tutorialspoint...
Hey, welcome to Tutorialspoint...
Here, we will format text from a file in the Linux system using the fmt command. First, we need to create a file
with unformatted text then we will format it using the fmt command. To create a file, we have to use the cat
command as shown below.
$ cat >text.txt
Hey,
welcome
to
Tutorialspoint...
^C
Then after, we will format the contents of the file using the fmt command as shown below.
$ fmt text.txt
Hey, welcome to Tutorialspoint...
To check more information about the fmt command, we use the --help option with the fmt command in the
Linux operating system as shown below.
$ fmt --help
To check version information of the fmt command, we use the --help option with the fmt command in the
Linux operating system as shown below.
$ fmt --help

2. Describe how to print file and check printer status

How to Check the Status of Printers

1. Log in to any system on the network.


2. Check the status of printers.

Only the most commonly used options are shown here. For other options, see thelpstat(1) man page.

$ lpstat [-d] [-p] printer-name [-D] [-l] [-t]


-d

Shows the system's default printer.

-p printer-name

Shows if a printer is active or idle, when the printer was enabled or disabled, and whether the printer is
accepting print requests.
You can specify multiple printer names with this command. Use a space or a comma to separate
printer names. If you use spaces, enclose the list of printer names in quotation marks. If you don't
specify printer-name, the status of all printers is displayed.

-D

Shows the description of the specified printer-name.

-l

Shows the characteristics of the specified printer-name.

-t

Shows status information about the LP print service, including the status of all printers, such as
whether they are active and whether they are accepting print requests.

Example 5–2 Checking the Status of Printers

The following example shows how to display the system's default printer.

$ lpstat -d
system default destination: luna

The following example shows how to display the status of the printer luna.

$ lpstat -p luna
printer luna is idle. enabled since Jul 12 11:17 2001. available.

The following example shows how to display the description of the printers asteroid and luna.

$ lpstat -p "asteroid luna" -D


printer asteroid faulted. enabled since Jan 5 11:35 2004. available.
unable to print: paper misfeed jam

Description: Printer by break room


printer luna is idle. enabled since Jan 5 11:36 2004. available.
Description: Printer by server room.

The following example shows how to display the characteristics of the printer luna.
$ lpstat -p luna -l
printer luna is idle. enabled since Thu Jul 12 15:02:32 PM PDT
Form mounted:
Content types: postscript
Printer types: PS
Description:
Connection: direct
Interface: /usr/lib/lp/model/standard
PPD: none
After fault: continue
Users allowed:
(all)
Forms allowed:
(none)
Banner not required
Character sets:
(none)
Default pitch:
Default page size: 80 wide 66 long
Default port settings:

3. What are the steps involve in troubleshooting printing problems

Usb Printer

1. Make sure that the printer is connected to your system and powered on.
2. Open a terminal/console and check if the usb kernel modules are loaded:
$ lsmod | grep usb
3. Unplug the USB printer cable from your computer and enter this command:
$ tail -f /var/log/syslog
4. Reconnect the USB printer cable, you should see some messages appearing.
5. Press Ctrl-C to stop the logging.
6. Check whether the printer gets correctly detected by the USB subsystem and determine its USB
vendor/product IDs and the USB bus and device addresses:
$ lsusb
Note: The USB bus and device addresses change if you turn off or unplug the printer. Please re-run this
command if needed.
7. Check whether the device files for the printer get created and the ownerships ("root lp") and
permissions (non-HP: "crw-rw-r--", HP: "crw-rw-r--+") correctly set:
$ ls -l /dev/usb/lp* /dev/bus/usb/*/*
8. Determine the printer's device ID strings:
$ sudo usb_printerid /dev/usb/lp0
$ sudo usb_printerid /dev/usb/lp1
...
For HP printers also use
$ hp-info -i
and choose the printer with the problem from the text menu, then copy the "deviceid" entry from the
output (can be several lines).
9. For HP printers: Check that you have the latest version of HPLIP and whether HPLIP connects to them:
$ hp-makeuri <Bus>:<Device>
Replace "<Bus>" and "<Device>" by the bus and device numbers from the "lsusb" output (not vendor
and product ID). The numbers must be supplied with three digits, zero-padded from the left, like
"008:015". (More information from http://hplipopensource.com/.)
10. Find out if your printer gets detected by CUPS:
$ lpinfo -v
11. Attach the output of the above commands to the bug report.

Note that problems cannot only caused by CUPS but also by the kernel (package "linux"), libusb, HPLIP
(package "hplip"), and several third-party printer drivers.

Parallel port printer

1. Make sure that the printer is connected to your system and powered on.
2. Open a terminal/console and check if the lp, ppdev, and parport_pc kernel modules are loaded:
$ lsmod | grep lp
$ lsmod | grep ppdev
$ lsmod | grep parport_pc
3. Check if the kernel detected the parallel port during bootup:
$ dmesg | grep par
4. Check if the device files of the parallel port(s) are created and have the correct permissions and
ownerships:
$ ls -l /dev/lp* /dev/parport*
5. Check if the printer auto-detection result appears in the kernel's virtual file system:
$ ls -l /proc/sys/dev/parport/parport*/autoprobe*
$ sudo cat /proc/sys/dev/parport/parport*/autoprobe*
6. Find out if your printer gets detected by CUPS:
$ lpinfo -v
7. Run the parallel port CUPS backend separately, once with standard user privileges and once as root:
$ /usr/lib/cups/backend/parallel
$ sudo /usr/lib/cups/backend/parallel
8. Attach the output of the above commands to the bug report.

Note that problems can be caused not only by CUPS, but also by the kernel (package "linux"), HPLIP (package
"hplip"), and several third-party printer drivers.

You might also like