0% found this document useful (0 votes)
62 views129 pages

(M8-MAIN) - Operating Systems v1

1) The document discusses operating systems and introduces Linux, defining it as a free, open-source operating system developed by Linus Torvalds in 1991 as an alternative to Minix. 2) It explains how Linux can be used as both a server operating system, providing services to clients, and as a standalone operating system with bundled applications like OpenOffice, Gimp, and development tools. 3) The document also outlines basic Linux commands that will be covered, including understanding Linux file systems and performing directory operations, file manipulation, and other commands.

Uploaded by

williemcgillie32
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)
62 views129 pages

(M8-MAIN) - Operating Systems v1

1) The document discusses operating systems and introduces Linux, defining it as a free, open-source operating system developed by Linus Torvalds in 1991 as an alternative to Minix. 2) It explains how Linux can be used as both a server operating system, providing services to clients, and as a standalone operating system with bundled applications like OpenOffice, Gimp, and development tools. 3) The document also outlines basic Linux commands that will be covered, including understanding Linux file systems and performing directory operations, file manipulation, and other commands.

Uploaded by

williemcgillie32
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/ 129

COMPUTER SYSTEMS AND

PLATFORM TECHNOLOGIES
IT0047
MODULE 8

Operating System
SUBTOPIC 1

Introduction to Operating System


Upon completion of this module, the student will be able to:
• Define the operating system (OS), its goals and services
• Demonstrate the abstract view of the components of a
computer system;
• Enumerate the types of OS and the services provided by the operating systems
• Understand Basic Linux Commands, LINUX file system/structure, partition, filename format, absolute
and relative paths
• Perform directory creation
• Display directory content using wildcards in LINUX commands
• Perform copy, rename and move files in linux
• Create text files using cat command and vi editor in linux
• Utilize different file operation, data refinement commands, and redirectors in
file manipulation.
• Perform other Linux commands
• An Operating System (OS) is a
program or system software that acts
as an interface between the user and
the computer hardware and controls
the execution of all kinds of
programs.
• It is not possible for the user to use
any computer or mobile device
without having an operating system.
1. Execute user programs and make solving user problems
easier.
2. Make the computer system convenient to use.
3. Use the computer hardware in an efficient manner.
• Computer hardware – CPU, memory and I/O
devices, provides the basic computing
resources.
• Application programs – are used to solve the
computing problems of the users such as word
processors, games and business programs .
• Users – who utilize a computer or network
service trying to solve different problems.
• Operating System – controls and coordinates
the use of the hardware among the various
application programs for the various users.
Kernel is the central part of an OS which
manages system resources and is always
resident in memory. It also acts like a bridge
between application and hardware of the
computer. It is also the first program that
loads after the bootloader.

Bootloader is a program that loads and starts


the boot time tasks and processes of an OS.
It also places the OS of a computer into
memory.
1. User Interface
2. Program Execution
3. File system manipulation
4. Input / Output Operations
5. Communication
6. Resource Allocation
7. Error Detection
8. Job Accounting
9. Security and protection
1. User Interface (UI).
Refers to the part of an CLI
OS, or device that allows
user to enter and receive
information.

Types of UI: GUI


• Command line interface (CLI)
• Graphical User Interface (GUI)
2. Program Execution. The OS must have the capability to load a
program into memory and execute that program.
3. File system manipulation. Program requires to read a file and
write a file. File handling portion of OS allows users to create
and delete files and directories.
4. Input / Output Operations. A program which is currently
executing may require I/O, which may involve file or other I/O
device. The OS is responsible for reading and/or writing data
from I/O devices such as disks, tapes, printers, keyboards, etc.
5. Communication. Process needs to swap over information with
other process. Processes executing on same computer system
or on different computer systems can communicate using
operating system support.
6. Resource Allocation The OS manages the different computer
resources such as CPU time, memory space, file storage space,
I/O devices, etc. and allocates them to different application
programs and users.
7. Error Detection The operating system should be able to detect
errors within the computer system (CPU, memory, I/O, or user
program) and take the appropriate action.
8. Job Accounting. OS 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 user.
9. Security and Protection. Protection is any mechanism for
controlling access of processes or users to resources defined by
the OS. Security is a defense of the system against internal and
external attacks (denial-of-service, worms, viruses, identity theft,
theft of service)
Operating systems are there from the very first computer
generation and they keep evolving with time.

Some of the widely used operating systems are as follows:


1. Batch operating system
2. Time-sharing operating systems
3. Distributed operating system
4. Network operating system
5. Real-time operating system
6. Handheld operating system
1. Batch Operating System (BOS)
• The user of a BOS never directly interacts
with the computer.
• Every user prepares his or her job on an
offline device like a punch card and submit
it to the computer operator.
• To speed up processing, jobs with similar
needs are batched together and run as a
group.
• The programmers leave their programs with
the operator then operator sorts the programs
with similar requirements into batches.
2. Time-sharing Operating System
• Time-sharing or multitasking is logical extension in which CPU
switches jobs so frequently that users can interact with each job while
it is running, creating interactive computing.
• Multiple jobs are executed by the CPU by switching between them,
but the switches occur so frequently. Thus, the user can receive an
immediate response. Response time should be < 1 second
• Each user has at least one program executing in memory
• If several jobs ready to run at the same time 🢡 CPU scheduling
• If processes don’t fit in memory, swapping will take place
• Examples: Unix, Linux, Multics and Windows
3. Distributed Operating System
• Distributed systems use multiple central processors to serve
multiple real-time applications and multiple users. Data processing
jobs are distributed among the processors accordingly.
• The processors communicate with one another through various
communication lines (such as high-speed buses or telephone lines).
These are referred as loosely coupled systems or distributed
systems. Processors in a distributed system may vary in size and
function. These processors are referred as sites, nodes, computers,
and so on.
• Examples: Telecom Network, WWW, Cloud Computing, etc.
4. Network Operating System (NOS)
• A NOS runs on a server and provides the server the capability to
manage data, users, groups, security, applications, and other
networking functions.
• The primary purpose of the network operating system is to allow
shared file and printer access among multiple computers in a
network, typically a local area network (LAN), a private network or
to other networks.
• Examples: Microsoft Windows Server 2003, Microsoft Windows
Server 2008, UNIX, Linux, Mac OS X Server, Novell NetWare, and
BSD/OS (Berkeley Software Design).
5. Real-time Operating System (RTOS)
• RTOS is an operating system intended to serve real-time
systems/applications that process data as it comes in, mostly
without buffer delay.
• It is a software component that rapidly switches between tasks,
giving the impression that multiple programs are being executed at
the same time on a single processing core.
• Real-time systems are used when there are time requirements
like missile systems, air traffic control systems, robots, etc.
• Examples: LynxOS, OSE, QNX, RTLinux, VxWorks, Windows CE
6. Handheld Operating System
• It is also known as Mobile OS which is built exclusively for a
mobile device, such as a smartphone, personal digital assistant
(PDA), tablet, wearable devices or other embedded mobile OS.
• Examples: Android, Symbian, iOS, BlackBerry OS and Windows
Mobile.
SUBTOPIC 2

Basic Linux Commands

Upon completion of this module, the student will be able to:


• Understand the history and concepts of Linux
• Install LINUX operating systems in the virtual machine and familiarize
with the platform in terms of hardware requirements, bundled
application software, user interface and security features
What is
• Unix-like
• Free
Linux?
• Open Source
• Network operating system
• Developed under the GNU General Public License (GPL), the source
code for Linux is freely available to everyone.
Who developed Linux?
• Linus Torvalds
• University of Helsinki in Finland
• 1991
• He used special educational experimental purpose
operating system called Minix (small version of Unix and
used in Academic environment). But due to Minix limitations.
Linus felt he could do better than the Minix. So he
developed his own version of Minix, which is now known as
Linux.
How to
• Download over the net
• Order CD from Linux distributions
get
• Versions/types of Linux operating
system are called Distributions.
• CentOS is one of the most used
Linux?
Linux Distribution for enterprise and
web servers. It is a free enterprise
class Operating system and is based
heavily on Red Hat enterprise Distro.
• Other Linux Distros are as follows:
Where can I
• Server OS
• Stand-alone OS
use Linux?
As a server OS, it provides different services/network resources to
client. Server OS must be:
• Stable
• Robust
• Secure
• High Performance
Linux as
Server
OS
(A) Linux Server with different Client OS (B) Linux Server can act as
Proxy/Mail/WWW/Router Server etc.
Linux as Stand-alone OS
Linux offers bundled
applications such as
follows:
• Open Office (Writer, Impress, Calc)
• Graphics/image-editing software (Gimp)
• Software development (Phyton)
• Internet, e-mail, chatting
• Small personal database management system, etc.
Major
• Kernel
• Shell
Components
• File System
• Communication/Networking
• Text Processing
of Linux
• Programming
• System Management
• Online Documentation
• Graphical Environment
Step 1:
Double-click the
Public OVAs
folder on your
Desktop
Step 2:
Double-click
Centos7
Step 3:
Click Import button then wait until it is completed
Step 4:
After the import,
double click the
Centos 7 or click
Start to initialize your
Centos 7 (Linux OS)
Step 5: Step 6:
During the initialization, select Wait for the loading of OS to
the first option. finish.
Step 7: Step 8:
Once the OS is loaded, Select Student account and type
press ENTER key, to log-in. “password” in the Password textbox.
Step 9:
Select English as the language
and input source then click Start
using CentOS Linux button.
By default, the Host key is the
Right Ctrl key on the keyboard.
Step 10:
To access installed
applications, click
Applications.
Terminal is also
known as shell or
console which is the
command line
interface in Linux.
Terminal
environme
nt
gedit is a powerful general purpose text editor in Linux. It is the default text
editor of the GNOME desktop environment.
This is how a typical LINUX login screen
looks like. There will be a log-in prompt
where the user will enter his account
name or user name.

With using codio for linux operating system,


no user name and password needed. The
default current working directory is
codio~/workspace $
CREATING A NEW LOGIN
#adduser name

LOGGING-OUT OF A LINUX SYSTEM


 To quit the session, a user logs out by simply pressing <Ctrl-
D> The Control key and the D key together - <^D>.
 The user may also type either exit or logout at the $ prompt.
 Each user should always log-out before leaving the computer terminal.
Turning off the terminal does not always mean the user is automatically
logged-off the system.
 Leaving the terminal without logging out may result in unauthorized access of
an account.
• For security purposes, each account will have a password that the operating system
asks everytime a user wants to log-in. As the user enters the password, LINUX will
not print or echo the characters typed on the screen.
• If a user has a valid account name and he types in the correct password, LINUX will
display its prompt (usually the dollar sign, $) to indicate that it is ready to receive
commands/instructions. The prompt will vary from one version of LINUX to another.
Other possible prompts are % and #.
• A user may opt to change his password. The passwd command allows the user to do
so.
$ passwd 
Changing password for “opeslab”
opeslab’s Old password: 
opeslab’s New password: 
Enter the new password again: 
• Users should change their passwords from time to time. Also note that LINUX is case
sensitive. An uppercase letter is different from its lowercase equivalent. Therefore,
passwd is different from passwd.

Why You Shouldn’t use the root Login?


You will have to use the root login from time to time. Some things simply cannot be
done on the LINUX system without Logging in as a root. You should not use the root
login as your regular login. This is specially true if you are exploring the system, poking
around, and trying out new commands that may not do what you thought they would.
When you log in as a root, you become the system. The root login is also sometimes
called the superuser login, and with good reasons.
System Administrator is another term you will see often. A System Administrator is
the actual person who sets up and maintains the LINUX system.
System Administrator, because it deals with sensitive matters such as creating or
deleting log-ins, requires superuser privileges. The privileges are provided by root login.
So, the system administrator is an actual person wielding superuser powers gained by
logging in a s root.

NOTE: LINUX is case sensitive (as are all LINUX versions). A capital R is completely
different letter from lowercase r. When you type LINUX commands, you must see the
proper case or LINUX will not understand them. The majority of LINUX commands are
type in lowercase. This includes the login root; if you type Root or rOot, LINUX will
reject the login.
Most LINUX command are very flexible. When you enter a LINUX command, there
are several ways to tailor the basic command to your specific needs. We will look at the
two main ways used to modify the effect of the command.
• Specifying or redirecting command’s input and output.
• Using command options

NOTE : Pressing CTRL + U at any point, right up to before you press the ENTER key,
lets you clear everything you’ve typed on the command line. Perhaps the most powerful
keys to use at the command prompt are the arrow keys. The left and right arrows move
the cursor non-destructively. If you make a typo early in the LINUX, you can left
arrow your way to the character and type in the correction. Additionally, the up and
down arrow keys enables you to jump through a list of the last several commands used
(similar to DOS’s DosKey utility).
LINUX COMMAND FORMAT
 Most LINUX commands have the following format:
commandname [options] [arguments]
 A user types in the name of the command he wants to execute followed by options
(options are generally preceded by a dash or minus "-" sign) and then by the
arguments. Options determine LINUX how the command will be executed while
arguments are the data to be processed by the command.
 Some commands do not require the use of options and/or arguments. Examples of
such are the passwd and clear commands.
National Conventions Used to Describe LINUX Commands
If you remember the ff. basic rules, you may be able to understand the syntax of any
LINUX or Linux command.
1. Any text standing by itself and not within [ ] or { } must be typed only as shown.
2. Any text within [ optional ]
3. Angle brackets (< >) and the text within them must be replaced by appropriate text.
4. Curly braces ( { } ) indicates that you must choose on the values given within the
braces.
5. Ellipses ( … ) means and so on.
6. The fifth basic rule states that the brackets can be confirmed as necessary.
LINUX has help facilities available on line. If you forget the exact use of a command,
you’re looking for the right command to use, the answer might be available straight from
LINUX. The two help facilities we will try out are the bash shell’s help command, and
the man command, which available on most LINUX system, including LINUX.

THE LINUX MAN PAGES


The “man” in “man pages” stands for manual. Typing man <command> lets you
view the manual pages dealing with a particular command.
To execute a LINUX command, simply type the name of the command at the LINUX
prompt (much like in DOS) followed by the Enter or Return key ().
1. date
The date command gives the user the current date and time. Only the system
administrator (or the superuser) can change the system date and time.
Example : $ date 
Mon Oct 25 19:24:50 PST 1993
2. clear
The clear command will simply clear the screen and move the $ prompt to the
upper left-hand corner of the screen. This is similar to the cls command in DOS.
3. who
The who command gives a list of users currently logged in the system. The
output will give the user name or account name together with the TTY or
terminal number (the exact terminal being used by the user).
Example : $ who 
root tty0
user1 tty17
user5 tty6
opeslabtty8
4. whoami
The whoami command gives the account name of the user currently logged in
at a particular terminal. For example, if someone happens to see a terminal
left on with someone logged in, typing whoami at the prompt will give the
account name of that user.
Example : $ whoami 
opeslab
5. cal or cal year or cal month year
The cal command gives the user the calendar for the current month and year.
The cal year command will give the user the whole calendar for the year
specified. The cal month year command will give the calendar for the
specified month and year.

Example : $ cal 
July
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 126 27 28 29 30
31
6. touch
The touch command lets you create an ordinary file.
Example: $ touch text1
7. ls
The ls (list) command lists the name of files in a given directory. Typing ls
without any option and argument at the prompt gives the user a listing of the files
in columns and in alphabetical order.
Example: $ ls 
arithmetic chapter1.doc eric.let
figures memo.to.henry report.1
sample.c test.program.c
• listing or displaying files in alphabetical order.
Command Options :
-a – list all files including hidden files that begins with a period.
-d – list of directory names only.
-g – group of information with listing.
-l – show listing with extended information.
-r – list in reverse order.
-s – list in order of increasing size.
-t – list in order of time, from the most recent.
ls / <directory – displays the content of a directory.
ls –l/<directory> |more – pause screen
*b – back
*q – quit
ls –l / bin – test copies content of bin to file test.
more test – to display content of test
− duplicate
Syntax : ls < options >
• The l option gives a long listing of the files that includes information such as the size
of the file, the owner of the file, the date and time the file was last modified, etc.
Example:
$ ls -l 
-r-xr-xr-x 1 opeslab staff 4222 Jan 13 11:10 arithmetic
-rw-r----- 1 opeslab staff 512 Dec 1 8:00 chapter1.doc
-rw-rw-r-- 1 opeslab staff 1020 Feb 9 10:15 eric.let
drwx------ 2 opeslab staff 2023 Jun 4 9:31 figures
. . . . .
• The a option gives a listing of all the files including hidden files (those which start
with a ".")
Example:
$ ls -a 
. .. .profile
.sh_history arithmetic chapter1.doc
eric.let figures memo.to.henry
report.1 sample.c test.program.c
In some LINUX versions, the ls command will list the files one line per file.
Use the C option to list the files by columns.
. . . . .
• The ls command can also have arguments.
Example: $ ls arithmetic 
arithmetic
$ ls *.c 
sample.c test.p1rogram.c
• The ls command can also have a combination of arguments and options.
Example: $ ls -l sample.c 
-rw-r--r-- 2 opeslab staff 20432 Oct 25 10:30 sample.c.
• Separation of Components
A space should separate each component of a LINUX command.
Example: $ ls -l sample.c
• Ordering of Components
Do not interchange the position of the components of a LINUX command. The
order should always be:
commandname [options] [arguments]
Example: $ ls -l eric.let
• Multiple Options
The rule of separation can be applied in case of multiple options. A dash "-"
symbol should precede an option and a space should separate each option.

Example: $ ls -a -l
This will give you a long listing of all the files.
A user may also combine multiple options in a single dash symbol.
Example: $ ls -al
Take note that there should be no space between the a and the l.
Also, the ordering of the options is not important. Therefore, ls -l -a and ls
-la will also work.
• Multiple Arguments
The rule of separation is also applicable in case of multiple arguments. A space
separates one argument from another.
Example: $ ls -l arithmetic eric.let sample.c
• Multiple Commands
A user may enter several commands at a single LINUX prompt. In such a case, a
semi-colon (;) delimits each command unit. The commands will then be
executed consecutively.
Example: $ ls; ls -a; ls -l
Like in DOS, LINUX also uses wild cards in selecting certain files to be
operated on.
The LINUX wild cards are:
1. The Asterisk "*"
The asterisk wild card will match any number of characters that occur at the
designated position in the pattern.
Examples:
• ch* represents all filenames that start with ch followed by any number of
characters.
$ ls ch* 
chapter1 change.doc cherry_text
• *er represents all filenames that start with any number of characters and end with
an er.
$ ls *er 
files.october system.ver
• *itch* represents all filenames that start with any number of characters, followed
by the string itch and then followed by any number of characters again.
$ ls *itch* 
ritchie.doc itchy.let mitch.let
In DOS, *.* represents all files (any name and any extension). This is not
applicable in LINUX since there are no such things as file extensions. Instead, *.*
will be interpreted by LINUX as any file with a period in its filename. To represent all
files in LINUX, just simply type *.
2. The Question Mark "?“
Like in DOS, the question mark will match any single character.
Examples:
• ?ark represents all filenames that start with any single character followed by the
string ark.
$ ls ?ark 
mark lark 5ark ark
• henry? represents all filenames that start with the string henry and ends with
any single character.
$ ls henry? 
henry1 henry2 henryx henry
• letter?.doc represents all filenames that start with the string letter, followed by
any single character, and then followed by the string doc.
$ ls letter?.doc 
letter1.doc letters.doc letter.doc
3. The Square Brackets "[ ]"
The square brackets are similar to the question mark in the sense that it will
match any single character. However, square brackets provide the user with options
in choosing the character.
Examples:
• letter[246].doc represents all filenames that start with the string letter, followed by
either a 2, 4, or 6, and then followed by the string.doc.
$ ls letter[246].doc 
letter2.doc letter4.doc letter6.doc
• memo_[a-c] represents all filenames that start with the string memo_ followed by
any letter from a to c.
$ ls memo_[a-c].doc 
memo_a.doc memo_b.doc memo_c.doc
• letter[3-5] represents all filenames that start with the string letter followed by any
number from 3 to 5.
$ ls letter[3-5] 
letter3 letter4 letter5
• message[4-6m-o] represents all filenames that start with the string message
followed by any number from 4 to 6 or any letter from m to o.
$ ls message[4-6m-o] 
message4 message5 message6
messagem messagen messageo
• notice[1-2][b-d] represents all filenames that start with the string notice followed by
any number from 1 to 2 and then by any letter from b to d.
$ ls notice[1-2][b-d] 
notice1b notice1c notice1d
• element[!5-9] represents all filenames that start with the string element and NOT
follow
TYPES OF FILES
1. USER DATA – information that create and update. The very simplest user data
is plain text or numbers.
2. SYSTEM DATA – information, a plain text, that is read and used by the LINUX
system to keep track of which users are allowed on the system.
3. EXECUTABLE FILES – these files contains instructions that your computer
can perform.

FILENAMES – In LINUX, it can be up to 256 characters long. These characters


can be lower & uppercase letters and other characters usually the dash ( - ),
underscore ( _ ) and dot ( . ) . They can’t include match characters like *, ?, \,
space because these have all meaning to shell.
PARENT DIRECTORY AND SUBDIRECTORY
LINUX operating system has a hierarchy or tree-line
directory structure.
• bin – list of commands used in LINUX operating
system.
• dev – devices that LINUX operating system can use
(printers, modems, etc.)
• lib – libraries of commands.
• Usr – directory of users who are logged in the system,

THE ROOT DIRECTORY


In LINUX, the directory that holds all the other
directories is called the root directory. This is the ultimate
parent directory, every other directory is some level of
subdirectory.
HOW DIRECTORIES ARE NAMED
Directories are named just like files, and they can contain upper- and
lowercase letters, numbers and characters such as -, ., and _.
The slash ( / ) character is used to show files or directories within other
directories. For instance, usr/bin means that bin is found in the usr directory.
Note that you can’t tell whether bin is a file or a directory, although you know that
usr must be a directory because it holds another item – namely the bin.
/ - represents the root directory
SAMPLE DIRECTORY STRUCTURE

THE HOME
users can store their own files and b in d ev u sr
create subdirectories.
In this DIRECTORY
directory structure, the
subdirectories bin, dev, usr, lib, and etc
m itc h

LINUX provides
are under the root directory. Under usr,
there are two subdirectories called mitch d ocs

and cynthia. Under mitch, there are two


each user with his
subdirectories called docs and letters.
There are two files in subdirectory
m

letters namely letter1 and letter2. The


or her own directory,
file mydoc is in subdirectory docs.
PATHS
•A file could be in any directory and its location is called its
path.

a chain of directory names that tell LINUX how to find a particular file

• An Absolute Path traces the location of the file from the root directory
Examples: /usr/mitch/docs/mydoc
/usr/mitch/letters/letter1

• A Relative Path traces the location of the file starting at the current working
directory
Examples: Assuming that the current working directory is docs:
../letters/letter1
../letters/letter2
• pwd (print working directory) command
Everytime a user logs-in into an LINUX system, he is automatically taken to
his home directory (/usr/mitch). However, a user can move to any directory
in the file system as long as he has access to it. In order for the user to
determine which directory he is currently in, the command to use is pwd.

Format: pwd
Where: pwd is the name of the print working directory command
Example:
$ pwd
/usr/mitch
• pwd (print working directory) command
Everytime a user logs-in into an LINUX system, he is automatically taken to
his home directory (/usr/mitch). However, a user can move to any directory
in the file system as long as he has access to it. In order for the user to
determine which directory he is currently in, the command to use is pwd.

Format: pwd
Where: pwd is the name of the print working directory command
Example:
$ pwd
/usr/mitch
• mkdir (make directory) command
The mkdir command is for creating new directories or subdirectories within
the user’s home directory (or in any directory to which he is authorized to do
so) and for creating subdirectories within subdirectories.
Format: mkdir directory_name(s)
Where:
mkdir is the name of the make directory command
directory_name is the name of the directory the user wants to create.
Absolute and relative path names may be used.
Examples:
1. If the user is currently in /usr/mitch and wants to create a subdirectory
called memos in /usr/mitch, then
$ mkdir memos
2. If the user is currently in /usr/mitch and wants to create a subdirectory
michelle under the subdirectory memos, then
$ cd memos or $mkdir memos/michelle
$ mkdir michelle
3. If the user is currently in /usr/mitch and wants to create the
subdirectories temp1, temp2 and temp3, then
$ mkdir temp1
$ mkdir temp2 or $ mkdir temp1 temp2 temp3
$ mkdir temp3
• cd (change directory) command
If a user wants to move from one directory to another, he should use the cd
command.
Format: cd directory_name
Where:
cd is the name of the change directory command
directory_name is the name of the directory the user
wants to move into. Absolute and relative path names may
be used.
Note: Typing cd alone will always take the user to his home directory
Examples:
1. If the user is currently in /usr/rikki and wants to go to the root directory (/),
then
$ cd / or $ cd ../..
2. If the user is currently at /usr/mitch and wants to move to /usr, then
$ cd /usr or $ cd ..
3. If the user is currently in /usr/mitch and wants to move to /usr/rikki, then
$ cd /usr/rikki or $ cd ../rikki
4. If the user is currently at /usr/mitch and wants to go to /usr/mitch/letters,
then
$ cd /usr/mitch/letters or $ cd letters
5. If the user is currently in /usr/mitch and wants to go to /bin, then
$ cd /bin or $ cd ../../bin
• rmdir (remove directory) command
The rmdir command is for removing or deleting directories. The command
can remove a directory or subdirectory only if there are no files in it.
However, this command is only possible if the user is authorized to do so.

Format: rmdir directory_name(s)


Where:
rmdir is the name of the remove directory command
directory_name is the name of the directory the user wants to remove.
Absolute and relative path names may be used.
Examples:
1. If the user is currently in /usr/mitch/memos and wants to delete the
subdirectory nico which is under memos, then
$ rmdir nico
2. If the user is currently in /usr/mitch and wants to delete the
subdirectories temp1, temp2 and temp3, then
$ rmdir temp1
$ rmdir temp2 or $ rmdir temp1 temp2 temp3
$ rmdir temp3
3. If the user is currently in /usr/mitch and wants to delete the
subdirectory called michelle which is under /usr/mitch/memos, then
$ cd memos
$ rmdir michelle or $ rmdir memos/michelle
1. cp (copy) command
The cp command is for copying files within the same directory or to other
directories. However, this command is only possible if the user is authorized
to do so.
Format: cp source_name destination_name
Where:
cp is the name of the copy command
source_name is the name of the file to be copied. Absolute and relative
path names may be used.
destination_name is the name of the destination file. Absolute and
relative path names may be used. If destination_name
already exists, it will be deleted and replaced with the new
copy.
Examples:
• If the user is currently in /usr/mitch and wants to copy the file
michelle.let and call the new copy cynthia.let, then
$ cp michelle.let cynthia.let
• If the user is currently in /usr/mitch and wants to copy the file rikki.let
to subdirectory memos and call the new copy lito.let, then
$ cd memos
$ cp ../rikki.let lito.let
or
$ cp rikki.let memos/lito.let
• If the user is currently in /usr/mitch and wants to copy the file rico.let
to subdirectory memos and call the new copy rico.let, then
$ cd memos or $ cp rico.let memos/.
$ cp ../rico.let .
2. mv (move) command
The move command is for renaming files or moving files from one directory
to another. However, this command is only possible if the user is authorized
to do so.
Format: mv source_name destination_name
Where:
mv is the name of move command
source_name I s the name of the file to be renamed/moved.
Absolute and relative path names may be used.
destination_name is the name of the destination file/new file. If
destination_name already exists, it will be deleted and
replaced with the new copy.
Examples:
1. If the user is currently in /usr/mitch and wants to rename the file denise.let
and call the new copy clarence.let, then
$ mv denise.let clarence.let
2.If the user is currently in /usr/mitch and wants to move the file olive.let to
subdirectory memos (which is under /usr/mitch) and call the new copy
minette.let, then
$ cd memos
$ mv ../olive.let minette.let
or
$ mv olive.let memos/minette.let
3.If the user is currently in /usr/mitch and wants to move the file michelle.let to
the root directory and call the new copy nico.doc, then
$ mv michelle.let /nico.let
3. rm (remove) command
The rm command is for removing or deleting files. However, this command is
only possible if the user is authorized to do so.
Format: rm filename(s)
Where:
rm is the name of the remove command
filename(s) is(are) the name(s) of the file(s) to be removed/deleted.
Absolute and relative path names may be used.
Note : The rm command does not ask for any confirmation. Users should
be careful in the use of this command. As an alternative, a user
may use the del command. It is very much the same as rm except
that there is confirmation.
Examples:
• If the user is currently in /usr/mitch and wants to remove the file
cynthia.let, then
$ rm cynthia.let
• If the user is currently in /usr/mitch and wants to remove the file
love.let in subdirectory memos, then
$ cd memos or $ rm memos/love.let
$ rm love.let
• If the user is currently in /usr/mitch/memos and wants to remove the
file nico.let in /usr/mitch, then
$ cd .. or $ rm ../nico.let
$ rm nico.let
• A text file consists of almost exclusively of printable characters (letters,
digits, and punctuation). It contains lines of legible data, such as English
text. Each line in a text ends with a special nonprintable (invisible) character
called a newline, which LINUX uses to determine whether one line ends and
the next begins.
• A text file differs from an executable file in that the latter mostly consists of
nonprintable characters and “strange” characters such as , , ☺, and many
others.
THE file COMMAND
• The file command determines the type and organization of a particular file. It
examines a few hundred bytes at the beginning of the file for hints about the kind
of data the file contains.
• Some of the possible conclusions the file command may report include the
following:
1. If the file command notes that the file consists almost entirely of printable
characters, it may identify that file as ascii text.
2. If the file consists of printable characters, many of which happen form
words that file finds in the dictionary, it may report the file as English
text.
3. If the file consists almost entirely of nonprintable characters, it may report
the file as executable.
4. If the file contains what seems to be programming constructs from C or
FORTRAN, the file is identified as source code for those languages,
reporting c program text or fortran program text.

• The format of the file command is:


file filename
Example: $ file mitch.let
mitch.let: English text
$_
VIEWING TEXT FILES
• There are three different commands in viewing the contents of text files in
LINUX:
1.cat command - takes all input and output it. It is also used to display
the content of a text file and to create a text file. cat stands for concatenate.
Command Options : > - redirection output. Used to create a text file
>> - used to add a text at the end of each line.
Syntax : cat [ > ] [ >> ][filename]
The cat command is for displaying the contents of a text file on-screen. It is
very much similar to the type command of DOS. However, cat will
continuously display the contents of the file without regard to whether the user
is finish reading the contents or not. In order for the user to catch up, he can
freeze the screen by pressing <Ctrl-S>. To unfreeze the screen, simply type
<Ctrl-Q>.
The cat command is ideal for viewing short files.
Example: $ cat mitch.let
2. pg command
Format: pg filename
The pg command is more appropriate for viewing large files since it displays
the contents of text files one screen at a time. To view the next screen, the user
simply presses the Enter key and it displays the next screen of data. pg repeats
this process until it reaches the end of the file.
Example: $ pg mitch.let
In this example, the pg command will display the first 23 lines of the file mitch.let
and then pauses. Pressing the Enter key will cause the next 23 lines to be
displayed. The user may also press q instead of Enter to quit pg.
3. more command
Format: more filename
The more command is very much similar to the pg command in the
sense that it also displays the contents of a text file one screenful at a
time. However, in order to view the next screen, the user presses the
spacebar key instead of Enter key . Furthermore, more updates the
user on the percentage of the file that was viewed already. The user
may also use the ENTER key if he wants to scroll-up the screen one
line at a time.
Example: $ more mitch.let
4. echo – allows the terminal whatever else you have typed on the line
Syntax : echo [ text ]
The vi (visual) text editor of LINUX is for creating and editing text files such as letters,
memos, reports, correspondences, and the like. vi is a screen-oriented text editor.
There are two modes of operations in vi.
1. The text-edit mode is where the user can enter or edit text. When in the text-edit
mode, each the user types a letter, that letter will enter the document the user is
editing.
2. The command mode is where the user issues commands to the editor. In this
mode, a letter corresponds to a command and not a character to be entered in the
text file.
For example, in the command mode, the letter h is for moving the cursor one position
to the left. When the user types the letter h while in the text-edit mode, it enters the
file. Therefore, the user has to be in the command mode in order to perform functions
such as moving the cursor (moving around the document), deleting characters, words,
or lines, and saving the document.
Format: vi: vi filename(s)
Example: $ vi sample.text
If the file exists, then the following screen will appear:
25 October 2020
Mrs. Maribel A. Misola
President
I am happy to report the successful completion of the LINUX Training
Project.
Thank you very much.
Sincerely yours,
Mitch A. Santos
~
~
sample.text” 12 lines, 203 characters
If the file does not exist, then LINUX will create a new file and the following screen will
appear.
~
~
~
~
~
“sample.text” [new file]

• In both cases, the tilde “~” character indicates unused lines. The last line on the
screen is used by the editor for communicating information to the user.
• Upon entering the vi editor, the user is automatically taken into the command
mode. At this point, the keys on the keyboard represent commands, that is, any
character the user types will not enter the file as text but will cause the execution of
a certain action.
• The cursor in vi is represented by an underscore (underline). In some LINUX
versions, the cursor is seen as a box. Once LINUX starts the vi text editor, it places
the cursor at the start of the first character of the document.
• As the user starts editing the file, the changes are not actually made on the file
itself. Everytime vi starts, it copies the file from the disk and into main memory
(edit buffer). All editing changes will be made in the edit buffer. The file on the
disk remains intact. Changes on the actual document will be made once the user
saves the document. In this way, the user may choose to abandon the changes
and leave the document as it was.
EXITING vi
To exit the vi editor, just simple type a colon ‘:’ (the user should be in the command
mode). A colon will appear at the bottom of the screen. At this point, the user can
type any of the following (followed by the Enter key):

Command Action
q quit vi
q! quit vi without saving changes
wq save changes and then quit vi
x same as wq
Command Action
MOVING IN vi h or <BACKSPACE> move 1 position to the left
l or <SPACEBAR> move 1 position to the right
In the command j move one line down
mode, the user may k move one line up
move the cursor w move one word to the right
anywhere in the b move one word to the left
^ move at the beginning of a line
document by $ move at the end of the line
pressing any of the # Shift + g move to line #
following keys (no Ctrl-F move forward 1 full page
Ctrl-B move backward 1 full page
need to press the
Shift + g move to last line of the document
Enter key): Ctrl-D move forward 1/2 page
Ctrl-U move backward 1/2 page
- move to the first character of the preceding line
Shift + h move to top of the screen
Shift + m move to the middle of screen
Shift + l move to bottom of the screen
If the user types a number before certain commands, it will cause the cursor to
move several units. Examples are:
1. Pressing 5h will cause the cursor to move 5 options to the left.
2. Pressing 10k will cause the cursor to move 10 lines up.
3. Pressing 3w will cause the cursor to move 3 words to the right.
DELETING TEXT IN vi
While in the command mode, the user may also delete characters, words, or lines.
Just move the cursor to the character, word, or line to be deleted and then press the
corresponding keys:
Command Action
x delete one character
dw delete a word
dd delete a line
D delete from the current cursor position to the end of line
If the user types a number before any of these commands, it will cause the
deletion of several units. Examples are:
1. Pressing 12x will delete the next 12 characters.
2. Pressing 7dw will delete the next 7 words.
3. Pressing 6dd will delete the next 6 lines.
Command Action
I insert new text before the cursor position
Shift + I insert new text at start of the current line
A EDITINGTEXT IN vi
Shift + a
append new text after the cursor position
append new text at end of current line
o open a new line after the current line
Shift + o open a new line before the cursor position
r change a character (no need to press <ESCAPE> key afterwards)
Shift + r overwrite everything until the <ESCAPE> key is pressed
cw change word
Shift + c change all text from current cursor position
~ convert from upper to lower case and vice versa
u undo the last editing change
Shift + u undo changes in a line
. repeat the last editing change
Shift + j join t wo lines
OTHER FEATURES OF vi
Pattern Searching
A user may search for any word or string in the file while inside vi. The user should
first be in the command mode. Typing a slash “/” will cause the cursor to go to the
bottom of the screen. The user may then type in a word or phrase he wants to
locate. Pressing the Enter key will cause vi to start searching. If the word or
phrase exists, then the cursor will jump to its next occurrence. If the pattern does
not exist, then vi will inform the user by showing a message at the bottom of the
screen.
Search and Replace
To search for a particular word, phrase, or pattern and replace it with another one,
type a colon “:” and the cursor will move to the bottom of the screen. Then type
%s/old_pattern/new_pattern where old_pattern is the pattern to be replaced
while new_pattern is the pattern that will replace old_pattern.
Block Copy
To copy a block of text in vi, first place the cursor at the start of the block (the
user should be in the command mode). Then type #yy where # is the number of
lines of the block to be copied. Then move the cursor to the position where the
block is to be copied and then press p.

Block Move
The procedure for moving blocks of text in vi is the same as with the block copy
except that the user should type the command #dd instead of #yy.
THE grep COMMAND
• The grep command is primarily for pattern searching. Users can use this
command to search a set of files for one or more phrases or patterns. If the
pattern exists, then grep will print all the lines that contain the said pattern.
• The general format of the grep command is: grep pattern filename
where: pattern is the phrase or pattern the user wants to find.
filename is the name of the target file.
Example:
Assume that the file horror.story contains:
And he slowly entered the cell and went to the
sink. He reached out trembling and touched the
lather on a brush. It was real. It felt warm.
It smelled of soap. The water dripped into
$ grep the horror.story
And he slowly entered the cell and went to the
sink. He reached out trembling and touched the
lather on a brush. It was real. It felt warm.
$_
If the pattern does not exist, then LINUX will simply display the $ prompt again.
Notice that the third line matched since the is part of lather.
• If the pattern consists of more than one word, then the user must enclose the
pattern in double quotes.
Example:
$ grep “of soap” horror.story
It smelled of soap. The water dripped into
Some of the options available for the grep command are:
1. The -v Option
The -v option will display all lines except those containing the pattern.
Example:
$ grep -v “of soap” horror.story
And he slowly entered the cell and went to the
sink. He reached out trembling and touched the
lather on a brush. It was real. It felt warm.
2. The -n Option
The -n option will display the lines together with their line number.
Example:
$ grep -n “of soap” horror.story
4: It smelled of soap. The water dripped into
3. The -c Option
The -c option will simply give the number of lines that contain the pattern.
Example:
$ grep -c the horror.story
3
$_
4. The -y Option
The -y option causes LINUX to ignore the difference between uppercase
and lowercase letters.
Example:
$ grep -y the horror.story
And he slowly entered the cell and went to the
sink. He reached out trembling and touched the
lather on a brush. It was real. It felt warm.
It smelled of soap. The water dripped into
5.
5. The -l Option
The -l option is a special option of grep that causes LINUX to print or
display the filenames of all files the contain the pattern of interest.
The command:
grep -l pattern *
searches all files in the current working directory that contain pattern and
prints the filenames of these files.
Example:
$ grep -l OPESYS1 *
grades.this.term
subjects.last.term
$_
• The sort command prints the contents of Then executing the command:
a file in alphabetical or numerical order. $ sort numbers
• The general format of the sort command
is: sort filename
Example:
If the file numbers originally contains:

Take note that the sort command


does not change the contents
of the file.
• The head and tail commands are similar to the cat command except that a user
can specify the number of lines to be displayed.The head command can display
the first 10 lines of a file while the tail command can display the last 10 lines of a
file.
Examples: Assume that the file numbers contains:
$ tail numbers $ tail numbers
• The user can also specify the number of lines he or she wants to view. To view
the first 5 lines of numbers, simply type the command:
$ head -5 numbers

• To view the last 3 lines of numbers:


$ tail -3 numbers
The find command is a powerful file searching tool that enables you to locate all
files that meet a certain set of criteria.
• The find command is useful in:
1. Locating lost files
2. Locating related files
3. Locating recently modified files
4. Locating files not recently modified
5. Checking file organization and security
• The general format of the find command is: find directories criteria action
where: directories specify a list one or more directories the user wants the
find command to search. find will search these directories and all of its
subdirectories.
criteria specify the characteristics of the files that are of
interest.
action specifies what the user wants the file command to do
with the files it finds.
Examples:

This command will search for all files with filename numbers starting from your
current working directory. When the find command locates the files of interest, it will
print the pathnames of the files on the screen.

The find command can also accept wildcards in a filename provided that the user
encloses it in double quotes:
Example:
• This command will search for all files with filenames beginning with andaya
starting at the current directory (and its subdirectories). When the find command
locates the files of interest, it will print them on the screen.
• Other uses of the file command are:
1. $ find -user user2 -print
This command will search for all files owned by user2 from your current
working directory.
2. $ find -group user2 -print
This command will search for all files owned by any member of the group
user2 from your current working directory.
3. $ find -mtime -2 -print
This command will search for all files that have been modified within the
past seven days starting at the root directory.
4. $ find -mtime +30 -print
This command will search for all files that have not been modified within
the past thirty days.
5. $ find -atime -7 -print
This command will search for all files that have been accessed within the
past seven days.
• The wc (word count) command counts the number of characters, words, and lines
in one or more files. If the user specifies multiple files, wc provides an individual
count for each file and totals for the group.
• The general format of the wc command is: wc filename(s)
Examples: $ wc numbers
13 13 46 numbers
This means that the file numbers has 13 lines, 13 words, and 46 characters.
$ wc numbers horror. story

This means that the file numbers has 13 lines, 13 words, and 46
characters while the file horror.story has 4 lines, 36 words, and 181
characters.
• The wc command has several options:
1. The -l Option
The -l option causes the wc command to display only the number of lines in the
file.
Example: $ wc -l numbers
13 numbers
$_
2. The -w Option
The -w option causes the wc command to display only the number of words in
the file.
Example: $ wc -w numbers
13 numbers
$_
The -c option causes the wc command to display only the number of characters
in the file.
Example: $ wc -c numebrs
46 letter.doc
$_
As in other commands, a user may combine several options in one
command line.

Example: $ wc -lc numbers


13 46 letter.doc
$_
• Any file ending in .gz – for example, squashed.gz – is a compressed file.

1. gunzip command – to uncompressed a file


Syntax : gunzip <file>
Ex. $ gunzip numbers.gz
$ ls
numbers

2. gzip command – compress a file.


Syntax : gzip <file>
Ex. $ gzip numebrs
$ ls
numbers.gz
Redirection
Most LINUX commands require input or produce output or both. The shell plays an
important part in setting up a command’s input and output.
Before it starts a command, the shell sets up three default paths that the command
can use for receiving input or sending output:
Standard input - is the default source of the input. By default, the standard input is
the keyboard.
1. Standard output - is the default destination for output. By default, the standard
output is the screen.
2. Standard error – is the default destination for error messages. By default, the
standard error is the screen.
Redirection allows LINUX users to change the default standard input, standard
output, and standard error.
The Output Redirection symbol (>) tells the shell to redefine the standard output.
Examples
1. The command:
2. The
command:
3. The command:

$ cat > one


1
^d (to save)
$ cat > two
2
$

$ cat one two > onetwo (press enter key)


$ cat onetwo(press enter key)
1
2
$
4. The command:
$ cat letter.doc (press enter key)
Dear Sir,
I hope that everything are ok!
$
$ cat letter.doc > /dev/lpt0 (press enter key)
will send the contents of letter.doc to printer lpt0.
> - a. if file does exist over write/erases old contents and replace with new one
- b. if file does not exist, it creates a new one
a)
$ cat file1
1
2
$ cat file2
3
4
$ cat file3 $ cat file2
5 3
6 4
$ cat file1 file2 > file3 $ cat file1 file2 > file3
$ cat file3 $ cat file3
1 1
2 2
3 3
4 4
$ $

b)
$ cat file1
1
2
>> - add the contents at the end of the file. $ cat file3
$ cat file1 5
1 6
2 $ cat file1 file2 >> file3
$ cat file2 $ cat file3
3 5
4 6
1
2
3
The Input Redirection symbol (<) tells the shell to redefine the standard input.
Input and output redirection get input and send output to another file. Pipes
allow users to send input and output to another command.

The LINUX pipe symbol is the vertical bar ( | ) which users type between
commands. The general usage of pipes is:

command1 | command2

LINUX will execute both commands simultaneously and redirects the standard
output from command1 directly into the standard input of command2. In other
words, the output of command1 becomes the input of command2.
Examples
1. The command:
$ who | sort(press enter key)

will give a sorted list of all users currently logged-in. The who command
produces the list of the users, which is piped directly into the sort command,
which in turn arranges the list in alphabetical order.

2. The command:
$ ls -l | grep numbers (press enter key)

will give a long listing of the files in the current directory. The ls -l produces a
long listing of the files while the grep jan command selects the lines containing
the phrase Jan.
• Siberschatz, A. (2018). Operating System Concepts, Wiley.
• Tomsho, G. (2019). Guide to Operating Systems,
Cengage Learning.
• Sobell, M., etal. (2017). A Practical Guide
to Linux Commands, Editors, and Shell
Programming, 4th Ed. Addison-Wesley Professional
• Cobbaut, P. (2016). Mastering Linux- Networking
• Blum, R., (2015). Linux Command Line and Shell Scripting
Bible
ASK ANY QUESTION RELATED TO OUR TOPIC FOR TODAY.

You might also like