(M8-MAIN) - Operating Systems v1
(M8-MAIN) - Operating Systems v1
PLATFORM TECHNOLOGIES
IT0047
MODULE 8
Operating System
SUBTOPIC 1
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.
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.
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
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.
• 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:
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.
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.