Here are the solutions to the exercises:
1. ls > new.txt
2. ls /etc/passwd >> new.txt
3. sort < new.txt
4. sort < new.txt > new.sequence.txt
5. mkdir latihan2; mkdir latihan2 2> rmdirerror.txt
6. sort <<@@@
Lampung
Bandung
Palembang
Aceh
Jambi
@@@
7. wc -l new.sequence.txt
2. https://github.com/syaifulahdan/ospractice|Operating System Practice |2 to 45
A. Objectives
1. Understanding the concept of process I / O and redirection.
2. Understanding standard input, output and error.
3. Using output notation, append and here document.
4. Understanding the concept of PIPE and filter.
4. https://github.com/syaifulahdan/ospractice|Operating System Practice |4 to 45
1. Proses I/O
A process requires Input and Output
The instructions given to Linux via Shell are called
program executions which are called processes.
Each time the instruction is given, the Linux kernel
creates a process by assigning a PID number
(Process Identity).
The process in Linux always requires Input and
generates an Output.
6. https://github.com/syaifulahdan/ospractice|Operating System Practice |6 to 45
2. File Descriptor
Linux communicates with files through a file
descriptor that is represented by numbers
starting from 0, 1, 2 and so on.
The three default file descriptor created by
the process are:
0 : keyboard (standar input)
1 : Display (standar output)
2 : Display (standar error)
8. https://github.com/syaifulahdan/ospractice|Operating System Practice |8 to 45
3. Redirection
Redirection is done for standard input, output
and error.
To redirect the file descriptor from 0, 1 and 2.
The symbol for the redirection is:
0< or < : keyboard (standar input)
1> or > : Display (standar output)
2> :
9. https://github.com/syaifulahdan/ospractice|Operating System Practice |9 to 45
3. Pipeline
The pipeline mechanism is used as a communication
tool between processes.
Input → Proses1 →Output → = Input →Proses2 → Output
Proses1 | Proses2
Process 1 produces output which is then used as input
by Process 2.
This input output relationship is called a pipe, which
connects Process 1 to Process2 and is represented by
the symbol "|".
10. https://github.com/syaifulahdan/ospractice|Operating System Practice |10 to 45
4. Filter
Filter is a Linux utility that can process
standard input (from keyboard) and display
the result on standard output (screen).
Cat, sort, grep, pr, head, tail, paste.
and others
Filter example is
11. https://github.com/syaifulahdan/ospractice|Operating System Practice |11 to 45
on a series of pipes:
P1 | P2 | P3 | . . . . . . .| Pn-1 | Pn
Then P2 through Pn-1 absolutely must be a
Linux utility that functions as a filter.
P1 (beginning) and Pn (last) may not filter.
Utilities are not a filter for example who, ls,
ps,lp,lpr,mail and more.
12. https://github.com/syaifulahdan/ospractice|Operating System Practice |12 to 45
Some of the Linux commands used for the
filtering process include:
Used to filter inputs and display rows containing only the specified
patterns. This pattern is called regular regular expression
Used to count the number of lines, words and characters from the
input lines given to it.
To find out how many rows use the l option, to find out how many
words, use the w option and to find out how many characters, use
the c option.
If one option is not used, then the appearance is the number of
lines, the number of words and the number of characters.
Grep command
wc command
13. https://github.com/syaifulahdan/ospractice|Operating System Practice |13 to 45
sort command
Used to sort the input based on ASCII number sequence of characters.
Used to extract specific columns from its input lines, specified in
the c option.
Used to remove duplicate sequential lines, usually combined in a
pipeline with sort.
cut command
uniq command
15. https://github.com/syaifulahdan/ospractice|Operating System Practice |15 to 45
1 Login as user.
2 Open the Console Terminal and do the experiments
below. Note the results of each experiment
3 Open the Console Terminal and do the experiments
below. Note the results of each experiment
17. https://github.com/syaifulahdan/ospractice|Operating System Practice |17 to 45
Output to screen (output standard), input from
system (kernel)
$ ps
$ cat
hallo, apa khabar
hallo, apa khabar
exit dengan ^d
exit dengan ^d
[Ctrl-d]
Output to screen (output standard), input from
Experiment 1 : File Descriptor
18. https://github.com/syaifulahdan/ospractice|Operating System Practice |18 to 45
Input from keyboard and output to internet
address
$ mail syaifulahdan@teknokrat.ac.id
contoh surat yang langsung
dibuat pada standard input (keyboard)
[Ctrl-d]
$ mkdir mydir
$ mkdir mydir (there is an error message)
Input the directory name, no output (create a new
directory), in case of error then display error on the
screen (standard error)
19. https://github.com/syaifulahdan/ospractice|Operating System Practice |19 to 45
Experiment 2 : Redirection
1. Redirection of output standard
$ cat 1> myfile.txt
$ cat 0< myfile.txt
$ cat myfile.txt
$ mkdir mydir (there is an error message)
$ mkdir mydir 2> myerror.txt
$ cat myerror.txt
2. Redirection of input standard, ie input is
deflected from the keyboard to be from file.
3. Default error redirection to be stored in file
20. https://github.com/syaifulahdan/ospractice|Operating System Practice |20 to 45
4. Notation 2> & 1: standard redirection error
(2>) is identical to the file descriptor 1.
$ ls newfile (there is an error message)
$ ls newfile 2> out.txt
$ cat out.txt
$ ls newfile 2> out.txt 2>&1
$ cat out.txt
23. https://github.com/syaifulahdan/ospractice|Operating System Practice |23 to 45
7. Notation here document (<< ++ .... ++) is
used as the input barrier of keyboard. Note that
the divider marks can be replaced by what sign
only, but must be the same and the closing
mark should be given at the beginning of the
line
$ echo cat <<++
Hello, how are you ?
Alright ?
Ok!
++
25. https://github.com/syaifulahdan/ospractice|Operating System Practice |25 to 45
●
8. Notation - (keyboard input) is the input
representation of the keyboard. It means showing
file 1, then displaying input from keyboard and
displaying file 2. Note that the notation "-"
means to insert input from the keyboard
$ cat myfile.txt – letter
28. https://github.com/syaifulahdan/ospractice|Operating System Practice |28 to 45
12. Redirection of standard input and output
standards can be combined but should not use the
same filename as the standard input and output.
$ cat < output > out
$ cat out
$ cat < output >> out
$ cat out
$ cat < output > out
$ cat out
$ cat < out >> out
[Ctrl-c]
$ cat out
29. https://github.com/syaifulahdan/ospractice|Operating System Practice |29 to 45
Experiment 3: Pipa (pipeline)
The pipeline operator (|) is used to make
process execution by passing direct data to
other data.
$ who
$ who |sort
$ who |sort -r
$ who > tmp
$ sort tmp
$ rm tmp
$ ls –l /etc | more
$ ls –l /etc | sort | More
30. https://github.com/syaifulahdan/ospractice|Operating System Practice |30 to 45
Experiment 4: Filter
Pipeline are also used to combine system
utilities to form more complex functions.
$ w –h | grep <user>
$ grep <user> /etc/passwd
$ ls /etc | wc
$ ls /etc | wc –l
$ cat > kelas1.txt
Badu
Zulkifli
Yudi
Ade
[Ctrl-d]
$ cat kelas1.txt kelas2.txt | sort
$ cat kelas1.txt kelas2.txt > kelas.txt
$ cat kelas.txt | sort | uniq
32. https://github.com/syaifulahdan/ospractice|Operating System Practice |32 to 45
Exercise : Practice 2
1
See the full list in the current directory, do deflect the standard output
view to file new.txt
2
See the full list in the /etc/passwd directory, do redirection the
standard output view to a new.txt file without deleting the previous file.
3 Sort new.txt files by redirection standard input.
4
Sort new.txt file by redirection standard input and output standard to
file new.sequence.txt
5
Create two latihan2 directories, and turn standard error into
rmdirerror.txt file.
6
Sort the following sentence
Lampung
Bandung
Palembang
Aceh
Jambi
Using the notation here document (<@@@ ... @@@)
33. https://github.com/syaifulahdan/ospractice|Operating System Practice |33 to 45
7 Calculate the number of lines, words and characters from the
newfile.txt By using filter and add the data to the new.txt file.
8 Calculate the number of lines, words and characters from the
new.sequence.txt file using a filter and add the data to the new.txt
file.
9 Use the command below and note the results
$ cat > hello.txt
dog cat
cat duck
dog chicken
chicken duck
chicken cat
dog duck
[Ctrld]
$ cat hello.txt | sort | uniq
$ cat hello.txt | grep “dog” | grep –v “cat”
34. https://github.com/syaifulahdan/ospractice|Operating System Practice |34 to 45
Practice Report : Practice 1
Command Description Format
cat
echo
sort
uniq
grep
2.Analyze the exercises that have been done.
1.Summarize Experiments 1 through experiment 4 in table
form as below:
3.Give a conclusion from this lab.
35. https://github.com/syaifulahdan/ospractice|Operating System Practice |35 to 45
“Pleasure in a job makes perfection on the results
achieved”. Aristoteles
“Believe you can. You're halfway”. Theodore Roosevelt
“You might be able to delay, but time will not wait”.
Benjamin Franklin
“The effort will work if someone does not give up”.
Napoleon Hill
“Opportunity to find a better strength in us arises
when life seems to be very challenging”. Joseph
Campbell