SlideShare a Scribd company logo
1 of 83
Download to read offline
Laboratory Activity 1
Name: __________________________________ Date: _____________
Unix Basic Commands
1.0 Unix / Linux Command Line Interface (CLI) Basics – Basic Commands
This section of the course provides a discussion and hands-on guide on the basic CLI commands in Unix/Linux. The
basic CLI commands are: how to log-in, log-out, interpreting the command prompt, how to enter commands, basic file
commands and management, and simple file permission. The objectives of this section are:
• Familiarize the students on how to gain access to a Unix/Linux server.
• Familiarize the students on what is the prompt and how to enter commands.
• Familiarize the students on file identifiers and, relative and absolute file names.
• Familiarize the students on basic file commands and management.
1.1. Logging In
To access a Unix/Linux server, a Telnet or SSH client software can be used to connect to the server. Most operating
system today has some form of this software like “putty.exe”. A login prompt for a Unix server can look like:
Login: <username>
Password:
Before you try to log-in to a Unix server, ask your instructor for a user account, and the IP address or server name
where your account is valid. After acquiring the user account and the server you are assigned to, accomplish the
following:
Step 1 On your Windows operating system, use an ssh client program to connect to the Unix server. Using the
“putty” client program, enter the IP address or name of the Linux server in the “Host Name” text box and
click the “Open” button.
1
Step 2 At the login prompt, type your assigned username and password.
2a. Were you able to login? How were you able to login?
_________________________________________________________________________
_________________________________________________________________________
2b. Did you have a user account when you logged-in?
_________________________________________________________________________
_________________________________________________________________________
2c. What is the IP address or server name of the Unix server you logged into?
_________________________________________________________________________
_________________________________________________________________________
1.2. The Command Prompt
After you have logged-in, notice that a prompt will appear on the screen. A prompt is an interface that allows user to
input commands. Different shells use different faces of prompts (shells will be tackled later in the course). In this
server, you will be greeted with:
Notice the different parts of your prompt. For the example prompt, it has displayed the username, current directory you
are in, the computer name and the prompt sign.
Step 3 Write down the prompt on your screen.
_________________________________________________________________________
_________________________________________________________________________
3a. Is your username displayed on the prompt? What is your username?
_________________________________________________________________________
_________________________________________________________________________
3b. Is a computer name displayed on the prompt? What is the computer name?
_________________________________________________________________________
_________________________________________________________________________
2
3c. What is the prompt sign on your screen?
_________________________________________________________________________
_________________________________________________________________________
1.3. Entering Commands
Commands can be entered to the Unix server via the command prompt. This is usually done by typing a series of
characters after the prompt sign. A usual format in entering commands is:
[dwight@netopsy1 greg]$ command <options> <argument>
Options for the command are switches that tell a command to do something differently. Arguments are information
sometimes needed by the command to be able to execute properly. Most of the time, options and arguments are not
needed in a command.
There are also commands wherein you do not need to type anything. These commands are: ctrl-c, ctrl-d, ctrl-s, and
ctrl-d. The table below gives a short description.
Step 4 On the command prompt, type “man –S 1 pwd” and press enter. This command will be tackled later in the
course, for now just accept it.
4a. What is the option in the command?
_________________________________________________________________________
_________________________________________________________________________
4b. What is the argument in the command?
_________________________________________________________________________
_________________________________________________________________________
4c. Press “q” to exit the command.
_________________________________________________________________________
_________________________________________________________________________
Step 5 On the command prompt, type “top” and press enter.
5a. Press the control and “c” key at the same time. What happened? Did it have the same effect as pressing “q”?
Why”
_________________________________________________________________________
_________________________________________________________________________
3
Step 6 On the command prompt, type ”man chmod” and press enter.
6a. Press the spacebar. Did the screen scroll up?
_________________________________________________________________________
_________________________________________________________________________
6b. Press the control and “s” key at the same time and then press the spacebar. Did the screen scroll up? Why?
_________________________________________________________________________
_________________________________________________________________________
6c. This time press the control and “q” key at the same time. What happened?
________________________________________________________________________
_________________________________________________________________________
6d. What does the command “ctrl-s” and “ctrl-q” do?
________________________________________________________________________
_________________________________________________________________________
1.4. Changing Password
One of the first things you must do on your user account is to change your password. Password ensures that no one
will have unauthorized access to your user account. A user must have to be authenticated using a password before
access to server will be given. To change your password, use the command: passwd.
You will be prompted by the server of your old password and then will be prompted to input a new password. You will
have to re-type your new password for verification. You can change your password anytime. Password must have at
least six characters with any alphanumeric combination (at least for Linux) but is case sensitive.
Step 7 At the command prompt, type “passwd”.
7a. Enter your current password when prompted for the old password.
7b. Enter the password “h3ll0”, when prompted for the new password.
7c. Was the password rejected? Why was it rejected?
________________________________________________________________________
_________________________________________________________________________
7d. Enter the password “r3ch3tt” when prompted for the new password.
7e. Was the password was accepted? Why was it accepted?
________________________________________________________________________
_________________________________________________________________________
7f. What is the message when the password was successfully changed?
________________________________________________________________________
_________________________________________________________________________
4
Step 8 At the command prompt, type “passwd“ again. Type the current password as “R4ch3tt”.
8a. Was the password rejected? Why was it rejected?
________________________________________________________________________
_________________________________________________________________________
8b. What is the message when the password was not successfully changed?
________________________________________________________________________
_________________________________________________________________________
Step 9 At the command prompt, type “passwd“ again. Enter the current password. Use your desired password when
prompted for a new password. Remember your new password.
9a. Were you able to give a new password on your first try? What were the messages from the server?
________________________________________________________________________
_________________________________________________________________________
1.5. Basic File Management
Unix file system, like other file systems of other operating systems, consists of files and each file has a file name.
There are three kinds of files on your Unix system: ordinary, special and directories.
The Unix file system is organized as a hierarchy of directories where each directory can contain files or subdirectories.
This hierarchy is called a tree where the root (/) is the top of the tree.
Each file in a directory has a file identifier (this is not synonymous to file name), which is a sequence of characters that
uniquely identifies a file or directory. A file identifier can have at most 255 characters (this includes extension); any
printable character can be used as to name a file but cannot contain “/”. Although the characters “*”, “?”, “>”, “>” or “|”,
it is not recommended because it has special meaning. Remember that filenames in Unix are case sensitive.
File names in Unix, contains a sequence of file identifiers that designates a file. Slashes “/” are used to separate the
sequence of file identifiers. There are two kinds of file name: absolute and relative file name. Absolute file name
specifies the sequence of directories starting from the root (it actually starts with a “/”) and can be used to refer to a file
anywhere in the tree. Relative file name’s starting point is the current directory or working directory. Relative file name
can use symbols “.” and “..” which represents the current directory and parent directory respectively. Another symbol
“~”, represents the home directory. Home directory is the personal directory of a user where your files can be stored.
In order to do basic file management, there are several basic commands that can be used. Usual commands needed
are to list files in a directory, change to another directory, create a new directory, move a file or directory, copy a file or
directory, and remove a file or directory. Most of the commands can use absolute or relative filenames. The commands
are presented in a table below.
5
1.5.1. Changing to different directories
The “cd” command is used to change the working directory. Every time you log in via Telnet, you will be in your home
directory. Most of the time, your directory is located in the “/home” parent directory. The hierarchy can be shown as:
The hierarchy shown is very simple. This is not the whole hierarchy for the Unix system. Also, not all hierarchy is the
same for all Unix versions.
Step 10 While you are in the home directory, type the command “pwd”.
10a. What was the message on the screen?
________________________________________________________________________
_________________________________________________________________________
10b. What does the “pwd” command do?
________________________________________________________________________
_________________________________________________________________________
Step 11 Type the command “cd /etc” and press enter.
11a. Did the prompt display differently? Write down the display.
________________________________________________________________________
_________________________________________________________________________
11b. Type the command “pwd”. What is your current working directory?
________________________________________________________________________
_________________________________________________________________________
6
Step 12 From the “/etc” directory, type the command “cd /home/<username>”.
12a. Did you go to your “home” directory? How were you able to determine?
________________________________________________________________________
_________________________________________________________________________
12b. What was the file name used (absolute or relative file name)? Why?
________________________________________________________________________
_________________________________________________________________________
12c. On the command prompt, type “cd ../../etc” and press enter. Were you able to go to the “/etc” directory?
What was the file name used (absolute or relative file name)? Why?
________________________________________________________________________
_________________________________________________________________________
12d. From the “/etc” directory, type the command “cd ~”. Were you able to go to the “home” directory? Which “cd”
command is this similar to?
________________________________________________________________________
_________________________________________________________________________
1.5.2. Listing Directories
The “ls” command is used to list directories. There are a lot of options you can do with the command. It is able to
display all files, directories only and other more options.
Step 13 On the command prompt, type the command “cd ..” and press enter.
13a. Enter the “ls” command. What did you see?
________________________________________________________________________
_________________________________________________________________________
13b. Enter the “ls -A” command. What is the option? Was it different from last time?
________________________________________________________________________
_________________________________________________________________________
13c. Enter the “ls -a” command. What is the option? Was it different from last time? What does it do?
________________________________________________________________________
_________________________________________________________________________
The “ls” command with option “A”, shows all files in the directory including hidden files. Hidden files are files that
start with “.”. The “a” option has the same function as “A” option except that it also displays the “.” (current) and “..”
(parent) directories.
7
13d. Enter the “ls -l” command. What is the option? Was it different from last time? What does it do?
________________________________________________________________________
_________________________________________________________________________
The first column on the “ls -l” shows the file permission of the file or directory (again, will be discussed later).
Notice that a “d” as the first character shows which are the directories.
13e. Enter “cd /etc” and then the “ls -d rc0.d” command. What is the option? What does it do? Is it different from the “ls
rc0.d” command?
________________________________________________________________________
_________________________________________________________________________
The “d” displays if the “rc0.d” directory is there or not. While the “ls” command without the “d” option will display
the contents of the directory “rc0.d”.
13f. Enter the “ls -R” command. What is the option? What does it do? How is it different from “ls”.
________________________________________________________________________
_________________________________________________________________________
The “R” option displays the directories recursively.
Step 14 Metacharacters are characters with special meaning in Unix. One of the metacharacters is “*”.
14a. Go to the “/home/dir1” directory, type the command “ls f*”. What files were listed?
________________________________________________________________________
_________________________________________________________________________
14b. Enter the command “ls p*”. What files were listed?
________________________________________________________________________
_________________________________________________________________________
14c. Enter the command “ls file?”. What files were listed?
________________________________________________________________________
_________________________________________________________________________
14d. What is the difference between the commands “ls f*” and “ls file?”?
________________________________________________________________________
_________________________________________________________________________
14e. Enter the command “ls [f..p]ile1”. What files were listed?
________________________________________________________________________
_________________________________________________________________________
8
14f. Enter the command “ls [f..p]ile2”. What files were listed?
________________________________________________________________________
_________________________________________________________________________
14g. Enter the command “ls [f..p]ile?”. What files were listed?
________________________________________________________________________
_________________________________________________________________________
14h. What does the metacharacter “[..]” do?
________________________________________________________________________
_________________________________________________________________________
The metacharacter “*” is a wildcard for multiple characters while “?” is wildcard for a single character. The
metacharacter “[..]” is used to specify a range of characters.
1.5.3. Creating Directories
Directories in the Unix operating system can be created using the “mkdir” command. Naming directories has the same
rules as naming files. Exercises on filenames will be tackled later.
Step 15 Go to your home directory by entering the command “cd ~”. Then create a directory “coffees” using the
command “mkdir coffees”.
15a. Was the directory created?
________________________________________________________________________
_________________________________________________________________________
15b. Enter the command “cd coffees” and press enter. Next, enter the command “mkdir beans/robusta”. Were
you able to create the directory?
________________________________________________________________________
_________________________________________________________________________
15c. Enter the command “mkdir -p beans/robusta”. Were you able to create the directory? Why do you think so?
What is the “p” option for?
________________________________________________________________________
___________________________________________________________________________________________
The “p” option allows creation of directories with its parent directory.
1.5.4. Filenames
Empty files are files with a size of zero bytes. The “touch” command can be used to create empty files. The “touch”
command will be used to practice creating files with different filenames.
In Unix, filenames can have up to 255 printable characters except for the “/” character. Although “*” and “?” can be
used, these characters have special meaning.
9
Step 16 While in the directory “coffees/beans/robusta”, enter the command “touch robusta.txt”.
16a. Were you able to create the file? What is the size of the file? How were you able to determine the file size?
________________________________________________________________________
___________________________________________________________________________________________
16b. Enter the command “touch robusta/txt“. Were you able to create the file? Why? What was the message?
________________________________________________________________________
___________________________________________________________________________________________
16c. Enter the command “touch robusta1“. Were you able to create the file? Why?
________________________________________________________________________
___________________________________________________________________________________________
16d. Enter the command “mkdir robusta.doc“. Were you able to create the directory? Why?
________________________________________________________________________
___________________________________________________________________________________________
16e. Enter the command “ls“. Can you tell which one is a directory? What command should be used to be able to
determine which one is a directory?
________________________________________________________________________
___________________________________________________________________________________________
16f. Enter the command “ls robusta*“. Is there a difference from the earlier command? Can you tell which one is
the directory? Why?
________________________________________________________________________
___________________________________________________________________________________________
1.5.5. Copying Files
The cp command is used to copy files. The command can be used to copy one source to a destination or multiple
sources to a directory.
Step 17 Enter the command “cp robusta.txt robusta.html”.
17a. What happened after entering the command? Did you see the file “robusta.html”?
________________________________________________________________________
___________________________________________________________________________________________
17b. Enter the command “cp robusta.txt robusta.doc”. What happened after entering the command? Did you
see the file “robusta.doc“? Why?
________________________________________________________________________
___________________________________________________________________________________________
10
17c. Enter the command “cp robusta.txt robusta.html”. Were you prompted if the file was to be overwritten?
Why?
________________________________________________________________________
___________________________________________________________________________________________
17d. Enter the command “cp –i robusta.txt robusta.html”. Were you prompted if the file was to be
overwritten? Why?
________________________________________________________________________
___________________________________________________________________________________________
1.5.6. Moving Files
In the Unix operating system, moving of files can be done by using the command “mv”. The command can also be
used to rename files.
Step 18 Enter the command “mkdir -p ../arabica” and press enter. Next, enter the command “touch
arabica.txt”. Use the command “ls” to verify the file is existent.
18a. Enter the command “mv arabica.txt ../arabica”. Is the file “arabica.txt” still there? Where is it located now?
What did the command “mv” do?
________________________________________________________________________
____________________________________________________________________________________
18b. Enter the command “touch arabica.txt” under the directory “<home
directory>/coffees/beans/robusta”. Next, type the command “mv arabica.txt ../arabica”. What happened?
Were you prompted that you will be overwriting a file?
________________________________________________________________________
_____________________________________________________________________________________
18c. Enter the command “touch arabica.txt” under the directory “<home
directory>/coffees/beans/robusta”. Next, type the command “mv –i arabica.txt ../arabica”. What
happened? Were you prompted that you will be overwriting a file?
________________________________________________________________________
_____________________________________________________________________________________
Answer no to the prompt.
18d. Enter the command “mv arabica.txt arabica.doc”. What happened? Is the file still there? Why?
________________________________________________________________________
_____________________________________________________________________________________
11
The command can be used to rename files.
18e. What is the difference between the command “cp arabica.txt ../arabica” and “mv arabica.txt
../arabica”. Explain.
________________________________________________________________________
_____________________________________________________________________________________
1.5.7. Removing Files
Removing or deleting files can be accomplished by using the command “rm”. Be careful in using this command since
deleted file are unrecoverable.
Step 19 Go to the “<home directory>/coffees/beans/robusta” directory. Type the command “rm arabica.doc”.
19a. Was the file still there? Can it be found in another directory? Why?
________________________________________________________________________
_____________________________________________________________________________________
Step 20 Enter the command “rm *”.
20a. What happened? Which file or directory was retained?
________________________________________________________________________
_____________________________________________________________________________________
20b. Why was it retained?
________________________________________________________________________
_____________________________________________________________________________________
Step 21 Go to the “robusta.doc” directory. Create the following directory “bean_quality” and
“bean_quality/perfect_cup”.
21a. Go to the “<home directory>/coffees/beans/robusta”. Enter the command “rm robusta.doc”. Were you
able to remove the directory? Why?
________________________________________________________________________
_____________________________________________________________________________________
21b. Enter the command “rm -r robusta.doc”. Were you able to remove the directory? Why? What is the option “r” for?
________________________________________________________________________
_____________________________________________________________________________________
Step 22 Go to the “arabica” directory. Enter the command “rm –i arabica.txt”.
22a. Was the file erased immediately? What was the message?
________________________________________________________________________
_____________________________________________________________________________________
12
22b. Answer “y” to the prompt. Was the file removed? What is the option “i” for?
________________________________________________________________________
_____________________________________________________________________________________
22c. Go to the “<home directory>/coffees” directory and enter the command
“rm -ir robusta.doc”. Were prompted before removal? What was the message?
________________________________________________________________________
_____________________________________________________________________________________
Answer “n” to the prompt.
1.6. Logging Out
The “exit” command can be used to log out of the Unix server.
Step 23 At the prompt type the command “exit”.
23a. What happened? Were you able to log out? Is there an alternative command? (You may research this on books
or in the Internet)
________________________________________________________________________
_____________________________________________________________________________________
13
Laboratory Activity 2
Name: __________________________________ Date: _____________
Utilities, Redirection and Pipes
2.0 Unix / Linux Command Line Interface (CLI) Basics – Utilities, Redirection and Pipes, vi Text Editor and
Advanced File Commands
The Unix system provides a lot of utilities that one can use. Aside from utilities, the Unix system also provides facilities
for redirection, pipes and file ownership, and file permissions. The Unix system also has a built-in editor called vi.
Although vi may look ugly, vi is the standard text editor you can find in any Unix version and at the same time has
useful features at your fingertips. No need to use the mouse. The objectives of this section are:
1. To familiarize the student in using Unix file and disk utilities.
2. To familiarize the student in using the vi text editor.
3. To familiarize the student on file links.
4. To familiarize the student on file ownership and permissions.
2.1. Utilities
2.1.1. On-line Help
The Unix environment provides a simple on-line help system. The command “man” is used to browse the help pages.
This help system is sometimes referred to as “man pages”. Typing “man ls” at the command prompt will show you
something like:
The man page most of the time will contain the following sections (different Unix versions or authors of man pages
sometimes add sections): name, synopsis, description, and see also. The name section shows the name of the
command and alternative commands that does the same thing. The synopsis section shows the syntax of the
command while the description gives a short text on what the command does and the options that can be used. The
see also section gives other related commands.
Man pages also provide help on programming libraries, utilities, file formats and other topics on the Unix environment.
14
Step 1 On the command prompt, type the command “man ls”.
1a. What does the command do?
_________________________________________________________________________
_________________________________________________________________________
1b. Press the spacebar key. What does it do?
_________________________________________________________________________
_________________________________________________________________________
1c. Press the “f” key. What does it do? Is it the same as the space bar key?
_________________________________________________________________________
_________________________________________________________________________
1d. Press the “b” key. What does it do?
_________________________________________________________________________
____________________________________________________________________________________________
1e. Type the following “/format”. What does it do?
_________________________________________________________________________
____________________________________________________________________________________________
1f. Press the “q” key. What does it do?
_________________________________________________________________________
____________________________________________________________________________________________
Step 2 On the command prompt, type the command “man ls”. Scroll the pages and check the sections of the
man page.
2a. Can you identify the sections mentioned? What are these sections?
_________________________________________________________________________
____________________________________________________________________________________________
2b. Write down the description of the “ls” command.
_________________________________________________________________________
____________________________________________________________________________________________
15
2c. Write down an alternative command that you can use to view a help file on ls.
_________________________________________________________________________
____________________________________________________________________________________________
Step 3 On the command prompt, type the command “man -k dns”.
3a. What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
3b. What is the “k” option for?
_________________________________________________________________________
____________________________________________________________________________________________
The “k” option is for searching man pages given a keyword. The argument in the command is the keyword.
In this case, the command looks for man pages that have the word “dns” in it. As a bit information, dns
stands for “Domain Name Server”. Domain name server is a service that allows mapping of Internet names into its IP
address (There will be a section for DNS, please do not worry about it yet. ).
Step 4 On the command prompt, type the command “man -S1 chmod”.
4a. What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
If you look carefully at the upper right corner of the man page, there is a “( )” after the command. This
indicates in what section of the command are you viewing. Using the “s” option allows you to specify which
section would you want to view. The man utility displays the lowest numbered section by default when no
section number is provided from the command.
2.1.2. The “file” and “wc” Commands
The “file” command allows the user to determine the file type. This is useful if you cannot remember what the file is
for. The “wc” command prints the number of line, words and bytes in a file.
Step 5 At the command prompt, enter the command “cp /home/files/rfc2186.txt rfc2186.txt” and the
command
“cp /home/files/rf2186.pdf rf2186.pdf”.
After copying the files, verify if the files were copied.
5a. At the command prompt, enter the command “file rfc2186.txt”. What type of file is it?
_________________________________________________________________________
____________________________________________________________________________________________
5b. At the command prompt, enter the command “file NETOPSY_Lab_Manual.pdf”. What type of file is it?
_________________________________________________________________________
____________________________________________________________________________________________
16
5c. At the command prompt, enter the command “mv rfc2186.txt rfc2186”. After renaming the file, enter
the command “file rfc2186”. Was it still able to determine the file type?
_________________________________________________________________________
____________________________________________________________________________________________
Step 6 At the command prompt, enter the command “wc rfc2186”.
6a. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
6b. How many bytes, words and lines does the file have?
_________________________________________________________________________
____________________________________________________________________________________________
6c. At the command prompt, enter the command “wc -c rfc2186”. How many bytes does the file have? Is it
the same as its file size?
_________________________________________________________________________
____________________________________________________________________________________________
6d. At command prompt, enter the command “wc NETSOPY_Lab_Manual.pdf”. How many bytes, words and
lines does the file have?
_________________________________________________________________________
____________________________________________________________________________________________
2.1.3. The “more” and “cat” Commands
The “cat” command can concatenate files and print on standard output (which is usually the screen). This is useful
for checking the contents of short file, especially script files (again, will be tackled later). The command can accept
more than one filenames as an argument that can be printed on the standard output.
The problem with the “cat” command is that if the file is too long, the displaying of the file will just flash by. An
alternative command is the “more” command. This command displays the file on the standard output and provides
scrolling capability. Commands for scrolling are the same in the “man” utility.
Step 7 At the command prompt, enter the command “cp /home/files/fruits fruits” and press enter.
After copying the file, enter the command “cp /home/files/vegetables vegetables” and press
enter. Verify if you have copied the file using the “ls” command.
7a. After verifying the files were copied, enter the command “cat fruits”. What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
17
7b. Enter the command “cat vegetables”. What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
7c. Enter the command “cat fruits vegetables”. What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
7d. Enter the command “cat vegetables fruits”. What did the command do? Is it different from the
previous command? What can you generalize?
_________________________________________________________________________
____________________________________________________________________________________________
7e. Enter the command “cp /home/files/rfc2186.txt rfc2186.txt”. Verify if the file was copied
using the “ls” command.
7f. Enter the command “cat rfc2186.txt”. What did the command do? Were you able to see anything?
_________________________________________________________________________
____________________________________________________________________________________________
Step 8 At the command prompt, enter the command “more rfc2186” and press enter.
8a. Are you able to view the file?
_________________________________________________________________________
____________________________________________________________________________________________
8b. Press the spacebar key. What does it do?
_________________________________________________________________________
____________________________________________________________________________________________
8c. Press the “f” key. What does it do? Is it the same as the space bar key?
_________________________________________________________________________
____________________________________________________________________________________________
8d. Press the “b” key. What does it do?
_________________________________________________________________________
____________________________________________________________________________________________
18
8e. Press the “q” key. What does it do?
_________________________________________________________________________
____________________________________________________________________________________________
There are still other commands to scroll the screen in the “more” command. Use the man pages for the
“more” command to check the scroll commands and other options.
2.1.4. The “head” and “tail” Commands
The “head” command outputs the first few lines of a few on the screen while the “tail” command outputs the last few
lines of a file on the screen. The default number of line output is ten (10). These commands useful for checking log
files, especially to network administrators.
Step 9 At the command prompt, type the command “head rfc2186”.
9a. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
9b. At the command prompt, type the command “head -c20 rfc2186”. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
9c. At the command prompt, type the command “head -n20 rfc2186”. What was the output? How was it
different from last time?
_________________________________________________________________________
____________________________________________________________________________________________
9d. At the command prompt, type the command “tail rfc2186”. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
9e. At the command prompt, type the command “tail -c20 rfc2186”. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
9f. At the command prompt, type the command “tail -n20 rfc2186”. What was the output? How was it
different from last time?
_________________________________________________________________________
____________________________________________________________________________________________
19
9g. What is the difference between options “c” and “n”?
_________________________________________________________________________
____________________________________________________________________________________________
2.1.5. The “grep” Command
The “grep” command searches prints the lines in a file with a matching pattern. This is useful for searching patterns
in a text or binary file. Most of the time, network administrators uses this to search if a certain process is running (to
be discussed later) or searching for keywords in a configuration file (again, to e discussed later).
Step 10 At the command prompt, enter the command “grep apple fruits”.
10a. What was the output? Why?
_________________________________________________________________________
____________________________________________________________________________________________
10b. At the command prompt, enter the command “grep broccoli fruits”. Was there an output? Why?
_________________________________________________________________________
____________________________________________________________________________________________
10c. At the command prompt, enter the command “grep broccoli vegetables”. Was there an output?
Why?
_________________________________________________________________________
____________________________________________________________________________________________
2.1.6. The “sort” Command
The “sort” command allows a user to sort alphanumeric text in a file. If the text file has columns, the “sort” command
is able to sort by column. This is useful if you have a spreadsheet like text file.
Step 11 At the prompt, enter the command “cat fruits”. Observe the output of the command.
11a. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
11b. At the prompt, enter the command “sort fruits”. Observe the output of the command. What was the
output?
_________________________________________________________________________
____________________________________________________________________________________________
Step 12 At the prompt, enter the command “cp /home/files/fruits2 fruits2”.
12a. After copying the file, enter the command “cat fruits2”. Observe the output of the command. What was
the output?
_________________________________________________________________________
____________________________________________________________________________________________
20
12b. At the prompt, enter the command “sort fruits2”. Observe the output of the command. What was the
output?
_________________________________________________________________________
____________________________________________________________________________________________
12c. At the prompt, enter the command “sort -r fruits2”. Observe the output of the command. What was
the output? How is different from the previous command?
_________________________________________________________________________
____________________________________________________________________________________________
12d. At the prompt, enter the command “sort -k1 fruits2”. Observe the output of the command. What was
the output? How is it different from the command in step 2b?
_________________________________________________________________________
____________________________________________________________________________________________
12e. At the prompt, enter the command “sort -r -k1 fruits2”. Observe the output of the command. What
was the output? How is it different from the command in the previous step?
_________________________________________________________________________
____________________________________________________________________________________________
2.2. Redirection and Pipes
Redirectors “redirect” the standard output of a command to a file or device file. This is useful for saving a long list of
directories and files in text file for example. A redirection command looks like:
command > file or command > file_device
The “>” is the redirection symbol. Redirection symbols are:
Pipes are the same as redirection but use the output of a command as input to another command. The pipe symbol is
“|”.
Step 13 At the command prompt, enter the command “ls -l > list”.
13a. Was the text file list created?
_________________________________________________________________________
____________________________________________________________________________________________
13b. Use the “cat” or “more” command to view the “list” text file. What does the text file contain?
_________________________________________________________________________
____________________________________________________________________________________________
21
13c. At the command prompt, enter the command “ls -l > list”. Was a new text file list created? What
does the text file contain? Was it the same as before?
_________________________________________________________________________
____________________________________________________________________________________________
13d. At the command prompt, enter the command “ls -l >> list”. Was a new text file list created? What
does the text file contain? Was it the same as before?
_________________________________________________________________________
____________________________________________________________________________________________
13e. What is the difference between the “>“ and the “>>” redirection symbol?
_________________________________________________________________________
____________________________________________________________________________________________
Step 14 At the command prompt, enter the command “cd /etc/”. After changing to the “/etc” directory, enter the
command “ls -l”.
14a. Were you able to see all the file names? Did just scrolled by?
_________________________________________________________________________
____________________________________________________________________________________________
14b. At the command prompt, enter the command “ls -l |more”. Were you able to see the directory listing
properly?
_________________________________________________________________________
____________________________________________________________________________________________
14c. Which are the commands in the previous command? Which is the pipe symbol?
_________________________________________________________________________
____________________________________________________________________________________________
Remember that the “more” in the command is neither an option nor an argument. “more” is a command
utility that is used to view a file.
Step 15 At the prompt, enter the command “cd ~” and “mkdir dir1 dir2”.
15a. At the prompt, enter the command “ls -l”. Observe the output. What was the output of the command?
_________________________________________________________________________
____________________________________________________________________________________________
15b. At the prompt, enter the command “ls -l |sort -k1”. Observe the output. How is different from the
previous command?
_________________________________________________________________________
____________________________________________________________________________________________
22
15c. At the prompt, enter the command “ls -l |sort -r -k1”. Observe the output. How is different from
the previous command?
_________________________________________________________________________
____________________________________________________________________________________________
15d. At the prompt, enter the command “ls -l |sort -k8”. Observe the output. How is different from the
command in step 3b?
_________________________________________________________________________
____________________________________________________________________________________________
15e. At the prompt, enter the command “ls -l |sort -r -k8”. Observe the output. How is different from
the previous command?
_________________________________________________________________________
____________________________________________________________________________________________
Remember that the “sort” in the command is neither an option nor an argument. “sort” is a command
utility that is used to sort text in a file.
2.3. The vi Text Editor
The vi text editor is a built-in in the Unix operating system. This text editor is a standard on all Unix versions. Most
people would say that vi is not user-friendly, which is very true but vi very powerful. Only the most basic command set
will be tackled in this section. If you need or want to learn more, you can use the man page for vi for further reference
or the suggested reference books in this course.
Vi has three modes of operation: command, entry mode and last-line mode. In the command mode, accepts
command for cursor positioning, going into other modes, deleting characters or lines and searching for string patterns.
The entry mode allows editing of text while the last-line mode allows saving and exiting from vi. Upon starting of vi,
the program goes into the command mode. The following is a summary of the commands:
23
Step 16 At the command prompt, enter the command “vi rfc2186”.
16a. In which mode are in right now?
_________________________________________________________________________
____________________________________________________________________________________________
16b. In the command mode of vi, type “:22”. In which line of test are you in now? (Write down the first few
words of the line)
_________________________________________________________________________
____________________________________________________________________________________________
16c. Go to the word “describes”. Use the cursor keys or (h, j, k, l). Type the “a” command. In which mode are
you in now?
_________________________________________________________________________
____________________________________________________________________________________________
16d. Type the word “cat” and press the escape key. Where did the cursor allowed you to enter text? Before or
after the cursor? In which mode are you in now?
_________________________________________________________________________
____________________________________________________________________________________________
16e. Type the “i” command. In which mode are you in now?
_________________________________________________________________________
____________________________________________________________________________________________
16f. Type the word “hello” and press the escape key. Where did the cursor allowed you to enter text? Before or
after the cursor? In which mode are you in now?
_________________________________________________________________________
____________________________________________________________________________________________
16g. Press the escape the key. In which mode are you in now?
_________________________________________________________________________
____________________________________________________________________________________________
16h. Type the command “x”. What happened? What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16i. Type the command “2dd”. What happened? What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
24
16j. Type the command “yy”. What happened? What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16k. Type the “p”. What happened? What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16l. Type the command “:wq”. What happened? What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16m. Enter the command “vi rfc2186”. Go to line 21. Did vi saved your edited file?
_________________________________________________________________________
____________________________________________________________________________________________
16n. Type the command “yy”. What happened? What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16o. Type the “p”. What happened? What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16p. Type the command “:q!”. What happened? What did the command do?
_________________________________________________________________________
____________________________________________________________________________________________
16q. Enter the command “vi rfc2186”. Go to line 21. Did vi saved your edited file?
_________________________________________________________________________
____________________________________________________________________________________________
There are other text editors in the Unix system. There is the Emacs text editor and pico. Emacs is
standard in the Unix system while pico is not. The pico text editor is only found in the Linux version of Unix.
You may refer to man pages for pico and Emacs or the suggested references in this course.
25
2.4. Advanced File Commands
2.4.1. Disk Usage and Disk Free
The Unix environment allows the user to check his disk usage and the available disk space in the file system. The
commands are “du” and “df” respectively.
The “du” command allows a user to his/her disk usage including usage in subdirectories. By default, the disk usage is
presented in 1024 bytes per block. If a user sees that his/her disk usage is 108 blocks, this means that it is really
110592 bytes total (108*1024 bytes per block).
The “df” command shows the disk statistics of a file system. Typing “df” on the command prompt will produce an
output on the screen:
Looking at the sample output above, the filesystem column shows the partition/s on the server. The next column,
1kblocks, shows the capacity (total size) of the partition. The Used column shows how much is already used on the
partition, while Available shows how much can still be used. The Use% shows how much percentage is used on the
partition. The Mounted on column shows what is the directory name of the partition.
In the example above, partition /dev/sda2 shows that it has a capacity of around 3.6Gbyte. On the same partition,
around 359Mbyte is already used with still 3.1Gbyte available. Data on the partition occupies only 11% of the disk
space. This partition is mounted as the root (the meaning of mounted will be discussed later in the course). Before
starting the exercise, delete all files in your home directory by entering the command “rm *”.
Step 17 At the command prompt, type the command “cp /home/files/rfc2186.txt rfc2186.txt” and
press enter. This command should be done at your home directory. After the copying the file, type the
command “du” at the command prompt. Observe the numbers.
17a. How many directories do you have? How many blocks are you using in your directory?
_________________________________________________________________________
____________________________________________________________________________________________
17b. At the command prompt, type the command “du -k”. The switch used in the command defines that each
block is 1024 bytes. How many bytes are you using in your home directory?
_________________________________________________________________________
____________________________________________________________________________________________
17c. At the command prompt, type the command “du -ck”. How is this different from the previous command?
_________________________________________________________________________
____________________________________________________________________________________________
Step 18 At the command prompt, type the command “cp /home/files/OPERSYS_Lab_Manual.pdf
OPERSYS_Lab_Manual.pdf” and press enter.
18a. Type the command “du -ck” on the command prompt and press enter. Did the total number of blocks used
increase?
_________________________________________________________________________
____________________________________________________________________________________________
26
18b. How many bytes are you using?
_________________________________________________________________________
____________________________________________________________________________________________
Step 19 At the command prompt, type the command “df”.
19a. How many bytes is one block in the command?
_________________________________________________________________________
____________________________________________________________________________________________
19b. How many bytes is the capacity of /dev/sda1?
_________________________________________________________________________
____________________________________________________________________________________________
19c. How many bytes are used on /dev/sda1?
_________________________________________________________________________
____________________________________________________________________________________________
19d. How many bytes are available on /dev/sda1?
_________________________________________________________________________
____________________________________________________________________________________________
19e. What is the percentage of data used in /dev/sda1?
_________________________________________________________________________
____________________________________________________________________________________________
19f. At the command prompt type the command “df -m”. What is the size of each block in this command?
_________________________________________________________________________
____________________________________________________________________________________________
2.4.2. Hard Links and Soft Links
A file link is a directory entry for a file. Each file has a file name entry with a corresponding information entry that
allows access to the file. A file can have two types of links: hard link and soft link (also sometimes called symbolic
link). A hard link creates a new file name entry for a file but does not create another copy of the file (this is
synonymous to having two pointers point to a file) while a symbolic link creates a new file entry pointing to the original
file entry. Most of the time, symbolic links are more useful since you can use it to create “short cuts” to a directory.
Step 20 At the command prompt, type the command “du -ck”.
20a. What is your total disk usage?
_________________________________________________________________________
____________________________________________________________________________________________
27
20b. At the command prompt, type the command “cp rfc2186.txt rfc_2186.txt”. This will create a copy
the text file “rfc2186.txt”. Verify of the file was created using the “ls -l” command. Was the file
created?
_________________________________________________________________________
____________________________________________________________________________________________
20c. At the command prompt, type the command “du -ck”. What is your total disk usage? Did your disk usage
increased? Why?
_________________________________________________________________________
____________________________________________________________________________________________
20d. View the contents file “rfc2186.txt” by typing the command “more rfc2186.txt”, to exit type “q”.
Also view the contents of the file “rfc_2186.txt” using the command “more rfc_2186.txt”, to exit type
“q”. Were you able to view both files?
_________________________________________________________________________
____________________________________________________________________________________________
20e. Delete the file “rfc_2186.txt” and check your disk usage using the command “du -ck”. What is your
disk usage?
_________________________________________________________________________
____________________________________________________________________________________________
20f. At the command prompt, type the command “ln rfc2186.txt rfc_2186.txt”. This command creates
a hard link for the file “rfc2186.txt” text file. Verify if the hard link was created using the command “ls -
l”. Was the hard link created?
_________________________________________________________________________
____________________________________________________________________________________________
20g. At the command prompt, type the command “du -ck”. What is your total disk usage? Did your disk usage
increased? Why?
_________________________________________________________________________
____________________________________________________________________________________________
20h. View the contents file “rfc2186.txt” by typing the command “more rfc2186.txt”, to exit type “q”. Also
view the contents of the file “rfc_2186.txt” using the command “more rfc_2186.txt”, to exit type “q”.
Were you able to view both files?
_________________________________________________________________________
____________________________________________________________________________________________
28
20i. Delete the file “rfc2186.txt” and try to view the file “rfc_2186.txt” using the more command. Were you
still able to view the file? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
20j. Delete the file “rfc_2186.txt” and copy the file “rfc2186.txt” using the command “cp
/home/files/rfc2186.txt rfc2186.txt”. Verify if the file was copied using the “ls -l” command.
_________________________________________________________________________
____________________________________________________________________________________________
20k. At the command prompt, type the command “ln -s rfc2186.txt rfc_2186.txt”. This command
creates a soft link (symbolic link) for the file “rfc2186.txt” text file. Verify if the hard link was created
using the command “ls -l”. Was the soft link created? How would you know if it were a soft link (do not
use the color of the text to know the difference)?
_________________________________________________________________________
____________________________________________________________________________________________
20l. View the contents file “rfc2186.txt” by typing the command “more rfc2186.txt”, to exit type “q”.
Also view the contents of the file “rfc_2186.txt” using the command “more rfc_2186.txt”, to exit type
“q”. Were you able to view both files?
_________________________________________________________________________
____________________________________________________________________________________________
20m. Delete the file “rfc2186.txt” and try to view the file “rfc_2186.txt” using the more command. Were
you still able to view the file? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
Delete the soft link created for the file “rfc2186.txt”.
Step 21 At the command prompt, type the command “ln -s /home/dir1 test_dir”.
21a. Was the soft link for the directory created?
_________________________________________________________________________
____________________________________________________________________________________________
21b. How do you know if it is a soft link by using the “ls -l” command?
_________________________________________________________________________
____________________________________________________________________________________________
Step 22 On the command prompt type the command “ls /home/dir1” and then type the command “ls
test_dir”.
22a. Were the contents of the directories the same? Why?
_________________________________________________________________________
____________________________________________________________________________________________
29
22b. Use the command “rmdir test_dir” to delete “test_dir”. Were you successful? What was the
message on the screen?
_________________________________________________________________________
____________________________________________________________________________________________
22c. Use the command “rm test_dir” to delete “test_dir”. Were you successful?
_________________________________________________________________________
____________________________________________________________________________________________
2.4.3. File Ownership, File Permissions and Groups
Each file in the Unix system has an owner and permission. Each file is associated to an owner using its user ID. The
username is just a way for us to remember than just a bunch of numbers. A group is a logical grouping of users.
Each group name in the Unix system has a group ID. A group may also have ownership of a file. Most of the time,
the owner has access to the file and modifies the permission of a file.
File permission is way to provide file security in the Unix system. When you enter the command “ls –l”, notice the first
column. The first column in the output of the command shows the file permission of a file. The column is composed
of 10 characters. The first character indicates whether the file is a directory, the next nine characters show the
permission of the file that can be grouped into three columns where each column is composed of three characters.
Each three-character column shows the file permission for the owner, group, and world. Each character in the column
indicates a read, write or execute permission.
The third column in the output of the “ls –l” command shows the owner of the file, while the next column shows which
group can have access to the file or which groups the user belongs to. File permissions are also applicable to
directories.
File permissions can be changed using the “chmod” command. The command uses integers to change the
permission of a file. The command “chmod” is used in the form:
chmod vyz [file_name]
Where vyz is the permission integer to be put into the file. The v is actually a binary representation for rwx. Which “r”
is read, “w” is write and “x” is executable. If a “r” is a logic 1, then the file has read permission, if the “r” is logic 0 then
the file has no read permission. The same rule applies to w and x. For y and z, the rwx rule applies. Example:
chmod 744 rfc2186.txt
This command sets the file permission of the text file “rfc2186.txt” as read, write and executable for owner, read for
group and last, read for world.
Step 23 At the command prompt, enter the command “cp /home/files/rfc2186.txt rfc2186.txt”.
23a. What is the file permission of the owner for the file “rfc2186.txt”? Who is the owner? Which group does
it belong to? What is the group’s file permission?
_________________________________________________________________________
____________________________________________________________________________________________
23b. Enter the command “chmod 444 rfc2186.txt”. Use the vi text editor and try to edit and save the file.
Were you successful? Why?
_________________________________________________________________________
____________________________________________________________________________________________
30
23c. Enter the command “chmod 644 rfc2186.txt”. Use the vi text editor and try to edit and save the file.
Were you successful? Why?
_________________________________________________________________________
____________________________________________________________________________________________
23d. Enter the command “cp /home/files/long_list long_list”. View the file using vi text editor, more
or cat command. What does the file contain? Is it a command? What is the file permission for the owner?
_________________________________________________________________________
____________________________________________________________________________________________
23e. Enter the command “./long_list” at the prompt. What happened? What was the message?
_________________________________________________________________________
____________________________________________________________________________________________
23f. Enter the command “chmod 766 long_list” at the prompt. What is the file permission for the owner
after the command was executed?
_________________________________________________________________________
____________________________________________________________________________________________
23g. Enter the command “./long_list” at the prompt. What happened? What is the command similar to?
_________________________________________________________________________
____________________________________________________________________________________________
Step 24 At the prompt, enter the command “ls -ld /home/student_files”.
24a. Who is the owner of the file? What is the file permission of the owner? Which group does the directory
belong to? What is the group permission? What is the world permission?
_________________________________________________________________________
____________________________________________________________________________________________
24b. At the prompt, enter the command “groups”. To which group do you belong?
_________________________________________________________________________
____________________________________________________________________________________________
24c. At the prompt, enter the command “cd /home/student_files”. In the directory, enter the command
“touch <username>”. Were you successful? Why?
_________________________________________________________________________
____________________________________________________________________________________________
24d. At the prompt, enter the command “cd /home” and also enter the command “ls -ld faculty_files”.
Who is the owner of the file? What is the file permission of the owner? Which group does the directory
belong to? What is the group permission? What is the world permission?
_________________________________________________________________________
____________________________________________________________________________________________
31
24e. At the prompt, enter the command “cd /home/faculty_files”. In the directory, enter the command
“touch <username>”. Were you successful? Why?
_________________________________________________________________________
____________________________________________________________________________________________
32
Laboratory Activity 3
Name: __________________________________ Date: _____________
Processes, Unix Shells, and Shell Scripts
3.0 Unix / Linux Command Line Interface (CLI) Basics – Processes, Unix Shells and Shell Scripts
The Unix system allows job control because each command or program executed in the Unix system is a considered
a process. Job control allows running of processes, killing processes or creating background processes. The “ps”
command shows which processes are running on the system. This like the “ls” command for processes. Running
processes can also be terminated using the “kill” command. Job control will be discussed more in the course.
The Unix shell is a program that allows interactive use of the Unix operating system and the computer hardware.
There are different shells created for the Unix system. The first shell was the Bourne shell. After the Bourne shell,
the Korn and C shell was later created. The Korn shell is a superset of the Bourne shell while the C shell was “C” like
(“C” as in the C programming language). Although there are several shells available, the shells have the same set of
features with only subtle differences. For example, the “history” command is not available in the Bourne shell but is
available in the Korn and C shells. The prompts of different shells also look different.
Today, the Linux system uses the Bourne Again shell. This “new” shell has the useful features of Korn and C shells.
You could say that it is the hybrid of the Korn and C shell. Do remember that the Bourne Again shell is only in Linux
versions of Unix systems.
As mentioned earlier, these shells have same set features. These features are aliasing, environment setting,
variables and shell programming or also known as shell scripts. These features will be discussed in better detail in
this section.
Shell scripts allow a user to make useful utilities using Unix commands or other utilities. Shell scripts also have
constructs like programming languages that allow flexibility.
With a minimum background of shells, scripts and job control, the objectives of this section are:
1. Familiarization with Unix shells, it features and how to use it.
2. Familiarization with Unix shell scripts and how create and use shell scripts.
3. Familiarization with controlling jobs on the Unix system.
3.1. Processes
One of the ability of the Unix system is run several programs at a time. This is called multi-tasking. The Unix system
is the first system to provide this feature. Each process running on the Unix system has a process ID. Since there are
several programs running at the same time, there must be a way to control these programs or processes. There are
several types of processes on the Unix system. Two basic types of processes is the parent and child process. As the
name implies, the parent spawns a child process. If the parent process terminates before the child process returns, the
child process will become an orphan. If the child process does not return, it is a zombie or defunct process. Also, the
“daemon” process has the process ID of 1 which is the “main” parent of the processes in the Unix system.
Users can control the process using the “ps” and “kill” command; that allow a user to control processes. When the
“ps” command is executed, the following will be seen on the screen.
The first column shows the process id. The second column shows which terminal is running it while the third column
shows how much processing time is being used by the process. Fourth column shows the name or the command
name.
33
The “kill” command can be used to terminate a process. When the “kill” command is used, make sure you know
the process ID. There are two ways to kill a process, soft kill and hard kill. With the soft kill, processes are terminated
properly while the hard kill terminates a process abruptly.
Step 25 On the prompt, type the command “ps”.
25a. How many processes are running? Are the processes running only yours?
_________________________________________________________________________
____________________________________________________________________________________________
25b. On the prompt type the command “ps -e”. Are all the processes displayed yours? If not, some of the
processes belong to whom?
_________________________________________________________________________
____________________________________________________________________________________________
25c. On the prompt type the command “ps -f”. Is the number or columns different from last time? What is the
“f” option for?
_________________________________________________________________________
____________________________________________________________________________________________
25d. On the prompt type the command “ps -e |more”. What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
25e. On the prompt type the command “ps -e |grep min”. What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
Step 26 On the prompt enter the command “sleep 1000” and open another remote session to same server. Do
not exit your first remote session.
26a. Using the new remote session, at the prompt, enter the command “ps -u <user name>”. Were you able
to see the “sleep” program? What is the process ID of the “sleep” program?
_________________________________________________________________________
____________________________________________________________________________________________
26b. At the prompt, kill the “sleep” program using the “kill <pid>” command. Was the “sleep” program
terminated?
_________________________________________________________________________
____________________________________________________________________________________________
26c. Log-out of the new remote session. If ever the process cannot be killed using the soft kill command, use
the command “kill -9 <pid>” (hard kill). Before using the command, use the soft kill first because it
terminates a process properly than the hard kill command.
Step 27 At the prompt, enter the command “sleep 1000 &”.
34
27a. Was this command different from last time? Why?
_________________________________________________________________________
____________________________________________________________________________________________
The “&” at the end of the command tells the shell to make it a background process.
27b. At the prompt, enter the command “ps -f”. Looking at the “PPID” column, what is the parent ID of the
process of the “sleep” process? Why was it the parent?
_________________________________________________________________________
____________________________________________________________________________________________
27c. Kill the sleep program.
Step 28 At the prompt, enter the command “ps -f”. Record the process ID of the current shell.
28a. At the prompt, open a new shell using the command “bash” and then enter the command “sleep 1000
&”. Use the command “ps -f” to check the processes. What is the parent ID of the “sleep” program?
_________________________________________________________________________
____________________________________________________________________________________________
28b. Exit the new shell by using the command “exit”. Enter the command “ps -f”. What is the parent id of
the “sleep” process? Which is this process? Why did it changed?
_________________________________________________________________________
____________________________________________________________________________________________
Since the process that spawned the sleep program was terminated before the sleep program ended, the
sleep program is now called an orphan. Notice that the daemon process adopted the sleep program.
28c. Kill the “sleep” process that was orphaned. Were you able to kill it?
_________________________________________________________________________
____________________________________________________________________________________________
3.2. The Unix Shell
As mentioned earlier, the shell allows an interactive use of the Unix system and the computer hardware. Without it, it
will be hard to use the Unix system and computer. There are different shells available in the Unix system. These
shells have same set of features with only little differences. Most of the time, their differences are how the commands
are entered.
3.2.1. Bourne Shell (bsh), Bourne Again Shell (bash) and C Shell (csh or tcsh)
The Bourne, Bourne Again and C shell are different shell available on the Linux version of the Unix system. These
three shells have differences that are only minor. The Bourne and C shell were already available on all Unix system
and were the original shells. When Linux came, the Bourne Again shell was developed by the Free Software
Foundation. The Bourne Again shell incorporates useful features of the Korn and C shells.
Step 29 On the prompt, enter the command “csh”. Observe what happens to the prompt. Always take note that
you are in the C shell.
35
29a. What is does your prompt your look like? Why do you think the prompt changed? (In this case, the usual
prompt for the C shell in most Unix systems is “%” but in Linux, it has different prompt.)
_________________________________________________________________________
____________________________________________________________________________________________
29b. On the prompt, enter the following commands: “ls -l”, “ls”. Try using the up and down cursor keys.
Were you able to call the previous commands? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
29c. Clear the command prompt and type the command “history”. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
29d. On the prompt, type the command “!!”. What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
29e. On the prompt, type the command “vi this_is_a_file_with_a_long_name.txt”. Type in the text
“The quick brown fox jumps over the lazy dog.” Save the text file. Try to display the file using the “cat this_”
then press the “tab” key. What happened? Did the shell complete the filename? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
Step 30 Type the command “exit” at the command prompt and enter the command “bsh”.
30a. Did the prompt changed? What does the prompt look like?
_________________________________________________________________________
____________________________________________________________________________________________
30b. On the prompt, enter the following commands: “ls -l”, “ls”. Try using the up and down cursor keys.
Were you able to call the previous commands? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
30c. On the prompt, type the command “history”. What was the output?
_________________________________________________________________________
____________________________________________________________________________________________
30d. On the prompt, type the command “cat this_“ then press the “tab” key. What happened? Did the shell
complete the filename? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
36
Step 31 Type the command “exit” at the command prompt.
31a. On the prompt, enter the following commands: “ls -l”, “ls”. Try using the up and down cursor keys.
Were you able to call the previous commands? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
31b. Clear the command prompt, and then enter the command “history”. What happened?
_________________________________________________________________________
____________________________________________________________________________________________
31c. On the prompt, type the command “touch testfile” and then enter the command “vi !*”. What
happened? What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
31d. On the prompt, type the command “cat this_” then press the “tab” key. What happened? Did the shell
complete the filename? Why do you think so?
_________________________________________________________________________
____________________________________________________________________________________________
3.2.2. Shell Features
“alias” Command
An alias allows a way to give a different name or shorter name for a command. This allows a user to “personalize”
some commands that are used often.
Step 32 On the prompt, enter the command “alias ll=“ls-l“”. Again on the prompt, enter the command “ll”.
32a. What is the output of the command? What is the equivalent of the command?
_________________________________________________________________________
____________________________________________________________________________________________
32b. What other command can you think of that you might need an alias? (Include the options for the command)
_________________________________________________________________________
____________________________________________________________________________________________
32c. On the prompt, type the command “unalias ll”. Enter the command “ll” at the prompt. What
happened? Where you able to show the listing of you directory? Why not?
_________________________________________________________________________
____________________________________________________________________________________________
32d. What does the alias and “unalias“ command do?
_________________________________________________________________________
____________________________________________________________________________________________
37
“set” Command
The set command allows setting and unsetting of flags that control shell-wide characteristics. There are a lot flags
available on the Unix system. What will be presented are the useful ones.
Step 33 At the prompt, enter the command “ls > list” and then enter the command “cat list”.
33a. At the prompt, enter the command “ls -l > list” and then enter the command “cat list”. Was the
text file overwritten? Why?
_________________________________________________________________________
____________________________________________________________________________________________
33b. At the prompt, enter the command “set -o noclobber” and then enter the command “ls > list”.
Were you allowed to overwrite the file? What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
33c. At the prompt, enter the command “set +o noclobber” and then enter the command “ls > list”.
Were you allowed to overwrite the file? What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
Step 34 At the prompt, enter the command “set -o verbose” and then enter the command “ls -l”.
34a. What does the command do?
_________________________________________________________________________
____________________________________________________________________________________________
34b. At the prompt, enter the command “set +o verbose” and then enter the command “ls -l”. Did it
turned off the verbose mode? Why?
_________________________________________________________________________
____________________________________________________________________________________________
Command Sequencing
Several commands can be executed in succession in the Unix system. By using the “;”, commands can be sequenced
together. The Unix system is also able to do conditional sequencing. With conditional sequencing, a command will only
be executed if the first one is successful or the next command will only be a executed if there was an error.
Step 35 At the prompt, type the command “date; ls -l |more”.
35a. What did the command do? Did it execute two commands in succession?
_________________________________________________________________________
____________________________________________________________________________________________
35b. At the command prompt, type the command “date; ls; pwd > out.txt”. View the text file using a
text editor or “cat” command. What was on the “out.txt” file? (Describe)
_________________________________________________________________________
____________________________________________________________________________________________
38
35c. At the command prompt, type the command “(date; ls; pwd) > out.txt”. View the text file using a
text editor or “cat” command. What was on the “out.txt” file? (Describe)
_________________________________________________________________________
____________________________________________________________________________________________
35d. Why were the output of the two previous command were different? What was the command?
_________________________________________________________________________
____________________________________________________________________________________________
Step 36 At the prompt, type the command “mkdir dir1” then enter the command “ls -d dir1 && echo
”Directory found” Notice that this is a conditional command. The “&&” specifies that the next
command will be executed when the first command is successful.
36a. Did it execute the second command?
_________________________________________________________________________
____________________________________________________________________________________________
36b. At the prompt, type the command “ls -ld dir3 && echo “Directory found“”. Did it execute the
second command? Why?
_________________________________________________________________________
____________________________________________________________________________________________
Shell Variables
Shell variables are store information required by processes so that processes can function properly. An example of a
variable is how your command prompt looks like. The variable is called PS1. There are two types of shell variables:
local and global (also known as environment variable). Local variables are variables that are available for the current
shell session only while global variables are variables that are available to the current and all child or sub-shells that
the user or the system might start
Step 37 At the prompt, enter the command “my_name=“<your first name>“” and then enter the command
“echo $my_name”.
37a. What was the output of the command? Were you able to create a variable?
_________________________________________________________________________
____________________________________________________________________________________________
37b. At the prompt, enter the command “echo my_name”. Was the output same as before? Is the “$” sign
needed to display the value of the variable? Why?
_________________________________________________________________________
____________________________________________________________________________________________
37c. What did you create? A local or global variable?
_________________________________________________________________________
____________________________________________________________________________________________
39
37d. At the prompt, enter the command “bsh” and then enter the command “echo $my_name”. Were you able
to see you name?
_________________________________________________________________________
____________________________________________________________________________________________
37e. Without exiting the shell yet, type the command “my_name=“<your first name> <your last
name>“” and enter the command “echo $my_name”. Were you able to see your name? Explain why you
were not able to see your name earlier?
_________________________________________________________________________
____________________________________________________________________________________________
37f. Exit the shell and enter the command “echo $my_name”. Was the output same as previous shell? Why?
_________________________________________________________________________
____________________________________________________________________________________________
37g. At the prompt, enter the command “export my_name” and then enter the command “bsh”. Display the
variable “$my_name” by using the command “echo $my_name”. Is the output the same with the previous
shell? Why?
_________________________________________________________________________
____________________________________________________________________________________________
37h. What did you create? Local or global variable?
_________________________________________________________________________
____________________________________________________________________________________________
Step 38 At the command prompt, enter the command “PS1=”%”.
38a. What happened to the prompt? Did it changed?
_________________________________________________________________________
____________________________________________________________________________________________
Notice that PS1 is a shell variable. It was created by the operating system. In this case, the variable PS1
holds the text or command what the prompt should look like.
38b. At the prompt, enter the command “set |more”. What did it displayed? Were able to find PS1?
_________________________________________________________________________
____________________________________________________________________________________________
38c. At the command prompt, enter the command “PS1=”[u@h W]$” ”. Did the command prompt
go back to original state?
_________________________________________________________________________
____________________________________________________________________________________________
40
There are special characters that the shell can accept for the prompt setting. These settings are:
38d. Using the command “set |more”, find the shell variable for your log-in name. Is there shell variable for it?
What is the name of the variable?
_________________________________________________________________________
____________________________________________________________________________________________
38e. Using the command “set |more”, find the shell variable for your home directory. Is there shell variable for
it? What is the name of the variable?
_________________________________________________________________________
____________________________________________________________________________________________
Initialization Files
Initialization files or scripts can contain series of commands, settings and variables. Initialization files allows a user to
personalize some settings. There are two types of initialization files: system wide and personal. The system wide
initialization is set by the administrator and is the default initialization file. The personal initialization file resides in the
user’s home directory and can be “personalized” by the user. In the bash shell, there are two initialization files, the
“.bash_profile” and the “.bashrc”. The first initialization file can contain shell variable settings while the second
initialization file contains alias settings. The “.bash_profile” can also contain other command that can be executed
during the logging in.
Step 39 At the prompt, enter the command “PS1=%”. Make sure that the prompt has changed and enter the “exit”
command.
39a. Login to the server and check the prompt. Were you able to change the prompt? Did it go back to its
original state?
_________________________________________________________________________
____________________________________________________________________________________________
39b. Edit the “.bash_profile” using the vi text editor. At the end of the file, enter the text “PS1=“[u@h
W]$“”. Save the text file and exit. Login to the server again and check the prompt. Did the prompt
changed permanently?
_________________________________________________________________________
____________________________________________________________________________________________
Step 40 At the prompt, enter the command “alias ll=“ls “l“”. Enter the command “ll”.
40a. Were you able to see the effect of the alias?
_________________________________________________________________________
____________________________________________________________________________________________
41
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual
Operating System Lab Manual

More Related Content

What's hot

Unix OS & Commands
Unix OS & CommandsUnix OS & Commands
Unix OS & CommandsMohit Belwal
 
Gnu study guide linux admin 1 (lab work lpi 101) v 0.2
 Gnu study guide linux admin 1 (lab work lpi 101) v 0.2 Gnu study guide linux admin 1 (lab work lpi 101) v 0.2
Gnu study guide linux admin 1 (lab work lpi 101) v 0.2Acácio Oliveira
 
SGN Introduction to UNIX Command-line 2015 part 2
SGN Introduction to UNIX Command-line 2015 part 2SGN Introduction to UNIX Command-line 2015 part 2
SGN Introduction to UNIX Command-line 2015 part 2solgenomics
 
Gnu study guide linux admin 1 (lab work lpi 102) v 0.2
 Gnu study guide linux admin 1 (lab work lpi 102) v 0.2 Gnu study guide linux admin 1 (lab work lpi 102) v 0.2
Gnu study guide linux admin 1 (lab work lpi 102) v 0.2Acácio Oliveira
 
Linux Practical Manual
Linux Practical ManualLinux Practical Manual
Linux Practical Manualjorge
 
POS 433 Effective Communication - tutorialrank.com
POS 433 Effective Communication - tutorialrank.comPOS 433 Effective Communication - tutorialrank.com
POS 433 Effective Communication - tutorialrank.comBartholomew59
 
Unix features, posix and single unix specification
Unix features, posix and single unix specificationUnix features, posix and single unix specification
Unix features, posix and single unix specificationsudha rani
 
Assignment unix & shell programming
Assignment  unix  & shell programmingAssignment  unix  & shell programming
Assignment unix & shell programmingMohit Aggarwal
 
Linux Interview Questions Quiz
Linux Interview Questions QuizLinux Interview Questions Quiz
Linux Interview Questions QuizUtkarsh Sengar
 
POS 433 Inspiring Innovation/tutorialrank.com
 POS 433 Inspiring Innovation/tutorialrank.com POS 433 Inspiring Innovation/tutorialrank.com
POS 433 Inspiring Innovation/tutorialrank.comjonhson152
 
Linux basics part 1
Linux basics part 1Linux basics part 1
Linux basics part 1Lilesh Pathe
 

What's hot (20)

Unix OS & Commands
Unix OS & CommandsUnix OS & Commands
Unix OS & Commands
 
Gnu study guide linux admin 1 (lab work lpi 101) v 0.2
 Gnu study guide linux admin 1 (lab work lpi 101) v 0.2 Gnu study guide linux admin 1 (lab work lpi 101) v 0.2
Gnu study guide linux admin 1 (lab work lpi 101) v 0.2
 
SGN Introduction to UNIX Command-line 2015 part 2
SGN Introduction to UNIX Command-line 2015 part 2SGN Introduction to UNIX Command-line 2015 part 2
SGN Introduction to UNIX Command-line 2015 part 2
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Introduction to unix
Introduction to unixIntroduction to unix
Introduction to unix
 
Gnu study guide linux admin 1 (lab work lpi 102) v 0.2
 Gnu study guide linux admin 1 (lab work lpi 102) v 0.2 Gnu study guide linux admin 1 (lab work lpi 102) v 0.2
Gnu study guide linux admin 1 (lab work lpi 102) v 0.2
 
Linux Practical Manual
Linux Practical ManualLinux Practical Manual
Linux Practical Manual
 
Unix notes
Unix notesUnix notes
Unix notes
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
 
POS 433 Effective Communication - tutorialrank.com
POS 433 Effective Communication - tutorialrank.comPOS 433 Effective Communication - tutorialrank.com
POS 433 Effective Communication - tutorialrank.com
 
Unix features, posix and single unix specification
Unix features, posix and single unix specificationUnix features, posix and single unix specification
Unix features, posix and single unix specification
 
Assignment unix & shell programming
Assignment  unix  & shell programmingAssignment  unix  & shell programming
Assignment unix & shell programming
 
Linux lecture6
Linux lecture6Linux lecture6
Linux lecture6
 
Comp practical
Comp practicalComp practical
Comp practical
 
File management
File managementFile management
File management
 
Linux Interview Questions Quiz
Linux Interview Questions QuizLinux Interview Questions Quiz
Linux Interview Questions Quiz
 
Putty
PuttyPutty
Putty
 
POS 433 Inspiring Innovation/tutorialrank.com
 POS 433 Inspiring Innovation/tutorialrank.com POS 433 Inspiring Innovation/tutorialrank.com
POS 433 Inspiring Innovation/tutorialrank.com
 
Unix ppt
Unix pptUnix ppt
Unix ppt
 
Linux basics part 1
Linux basics part 1Linux basics part 1
Linux basics part 1
 

Similar to Operating System Lab Manual

introduction to linux operating system basic information
introduction to linux operating system basic informationintroduction to linux operating system basic information
introduction to linux operating system basic informationDILEEPSADHANKAR
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usageShay Cohen
 
User and group administration in Linux
User and group administration in LinuxUser and group administration in Linux
User and group administration in LinuxMohammed Yazdani
 
With respect to the security aspects of Linux- answer the following qu.docx
With respect to the security aspects of Linux- answer the following qu.docxWith respect to the security aspects of Linux- answer the following qu.docx
With respect to the security aspects of Linux- answer the following qu.docxSUKHI5
 
Linux lesson
Linux lesson Linux lesson
Linux lesson mutharam
 
Shared Coursework in Cyber Security Instructions Manual .docx
Shared Coursework in Cyber Security Instructions Manual .docxShared Coursework in Cyber Security Instructions Manual .docx
Shared Coursework in Cyber Security Instructions Manual .docxedgar6wallace88877
 
Evaluate a Health WebsiteName Click here to enter text.Course Cli.docx
Evaluate a Health WebsiteName Click here to enter text.Course Cli.docxEvaluate a Health WebsiteName Click here to enter text.Course Cli.docx
Evaluate a Health WebsiteName Click here to enter text.Course Cli.docxSANSKAR20
 
basic linux command (questions)
basic linux command (questions)basic linux command (questions)
basic linux command (questions)Sukhraj Singh
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalationJameel Nabbo
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O YourHelper1
 
Assessment item 1 File Systems and Advanced Scripting .docx
Assessment item 1 File Systems and Advanced Scripting .docxAssessment item 1 File Systems and Advanced Scripting .docx
Assessment item 1 File Systems and Advanced Scripting .docxdavezstarr61655
 
Linux introductory-course-day-1
Linux introductory-course-day-1Linux introductory-course-day-1
Linux introductory-course-day-1Julio Pulido
 
Linux for beginners
Linux for beginnersLinux for beginners
Linux for beginnersNitesh Nayal
 
Different type of shells In Netapp Cluster mode 8.X and how to access them t...
Different type of shells In Netapp Cluster mode 8.X  and how to access them t...Different type of shells In Netapp Cluster mode 8.X  and how to access them t...
Different type of shells In Netapp Cluster mode 8.X and how to access them t...Saroj Sahu
 

Similar to Operating System Lab Manual (20)

introduction to linux operating system basic information
introduction to linux operating system basic informationintroduction to linux operating system basic information
introduction to linux operating system basic information
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usage
 
Linux privesc.pptx
Linux privesc.pptxLinux privesc.pptx
Linux privesc.pptx
 
User and group administration in Linux
User and group administration in LinuxUser and group administration in Linux
User and group administration in Linux
 
With respect to the security aspects of Linux- answer the following qu.docx
With respect to the security aspects of Linux- answer the following qu.docxWith respect to the security aspects of Linux- answer the following qu.docx
With respect to the security aspects of Linux- answer the following qu.docx
 
Linux lesson
Linux lesson Linux lesson
Linux lesson
 
Shared Coursework in Cyber Security Instructions Manual .docx
Shared Coursework in Cyber Security Instructions Manual .docxShared Coursework in Cyber Security Instructions Manual .docx
Shared Coursework in Cyber Security Instructions Manual .docx
 
Evaluate a Health WebsiteName Click here to enter text.Course Cli.docx
Evaluate a Health WebsiteName Click here to enter text.Course Cli.docxEvaluate a Health WebsiteName Click here to enter text.Course Cli.docx
Evaluate a Health WebsiteName Click here to enter text.Course Cli.docx
 
basic linux command (questions)
basic linux command (questions)basic linux command (questions)
basic linux command (questions)
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalation
 
60761 linux
60761 linux60761 linux
60761 linux
 
P3.docx
P3.docxP3.docx
P3.docx
 
Unix Work
Unix WorkUnix Work
Unix Work
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
PerlScripting
PerlScriptingPerlScripting
PerlScripting
 
Assessment item 1 File Systems and Advanced Scripting .docx
Assessment item 1 File Systems and Advanced Scripting .docxAssessment item 1 File Systems and Advanced Scripting .docx
Assessment item 1 File Systems and Advanced Scripting .docx
 
Linux introductory-course-day-1
Linux introductory-course-day-1Linux introductory-course-day-1
Linux introductory-course-day-1
 
Linux for beginners
Linux for beginnersLinux for beginners
Linux for beginners
 
Different type of shells In Netapp Cluster mode 8.X and how to access them t...
Different type of shells In Netapp Cluster mode 8.X  and how to access them t...Different type of shells In Netapp Cluster mode 8.X  and how to access them t...
Different type of shells In Netapp Cluster mode 8.X and how to access them t...
 

More from Dwight Sabio

Human Rights Observatory Description
Human Rights Observatory DescriptionHuman Rights Observatory Description
Human Rights Observatory DescriptionDwight Sabio
 
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORRIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORDwight Sabio
 
Report on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationReport on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationDwight Sabio
 
Gender ombud report 2016 final
Gender ombud report 2016 finalGender ombud report 2016 final
Gender ombud report 2016 finalDwight Sabio
 
Strengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderStrengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderDwight Sabio
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt fileDwight Sabio
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3Dwight Sabio
 
Programming Problem 3
Programming Problem 3Programming Problem 3
Programming Problem 3Dwight Sabio
 
Programming Problem 2
Programming Problem 2Programming Problem 2
Programming Problem 2Dwight Sabio
 
Midterm Project Specification
Midterm Project Specification Midterm Project Specification
Midterm Project Specification Dwight Sabio
 
Game Design Document
Game Design DocumentGame Design Document
Game Design DocumentDwight Sabio
 
ProgrammingProblem
ProgrammingProblemProgrammingProblem
ProgrammingProblemDwight Sabio
 

More from Dwight Sabio (20)

Human Rights Observatory Description
Human Rights Observatory DescriptionHuman Rights Observatory Description
Human Rights Observatory Description
 
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORRIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
 
Report on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationReport on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their Situation
 
Gender ombud report 2016 final
Gender ombud report 2016 finalGender ombud report 2016 final
Gender ombud report 2016 final
 
Strengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderStrengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of gender
 
IP Report
IP ReportIP Report
IP Report
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
ABC Supermarket
ABC SupermarketABC Supermarket
ABC Supermarket
 
Programming Problem 3
Programming Problem 3Programming Problem 3
Programming Problem 3
 
Lab Activity
Lab ActivityLab Activity
Lab Activity
 
Bluetooth
Bluetooth Bluetooth
Bluetooth
 
Programming Problem 2
Programming Problem 2Programming Problem 2
Programming Problem 2
 
Arduino e-book
Arduino e-bookArduino e-book
Arduino e-book
 
Midterm Project Specification
Midterm Project Specification Midterm Project Specification
Midterm Project Specification
 
Game Design Document
Game Design DocumentGame Design Document
Game Design Document
 
Class diagram
Class diagramClass diagram
Class diagram
 
Midterm Project
Midterm Project Midterm Project
Midterm Project
 
ProgrammingProblem
ProgrammingProblemProgrammingProblem
ProgrammingProblem
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 

Operating System Lab Manual

  • 1. Laboratory Activity 1 Name: __________________________________ Date: _____________ Unix Basic Commands 1.0 Unix / Linux Command Line Interface (CLI) Basics – Basic Commands This section of the course provides a discussion and hands-on guide on the basic CLI commands in Unix/Linux. The basic CLI commands are: how to log-in, log-out, interpreting the command prompt, how to enter commands, basic file commands and management, and simple file permission. The objectives of this section are: • Familiarize the students on how to gain access to a Unix/Linux server. • Familiarize the students on what is the prompt and how to enter commands. • Familiarize the students on file identifiers and, relative and absolute file names. • Familiarize the students on basic file commands and management. 1.1. Logging In To access a Unix/Linux server, a Telnet or SSH client software can be used to connect to the server. Most operating system today has some form of this software like “putty.exe”. A login prompt for a Unix server can look like: Login: <username> Password: Before you try to log-in to a Unix server, ask your instructor for a user account, and the IP address or server name where your account is valid. After acquiring the user account and the server you are assigned to, accomplish the following: Step 1 On your Windows operating system, use an ssh client program to connect to the Unix server. Using the “putty” client program, enter the IP address or name of the Linux server in the “Host Name” text box and click the “Open” button. 1
  • 2. Step 2 At the login prompt, type your assigned username and password. 2a. Were you able to login? How were you able to login? _________________________________________________________________________ _________________________________________________________________________ 2b. Did you have a user account when you logged-in? _________________________________________________________________________ _________________________________________________________________________ 2c. What is the IP address or server name of the Unix server you logged into? _________________________________________________________________________ _________________________________________________________________________ 1.2. The Command Prompt After you have logged-in, notice that a prompt will appear on the screen. A prompt is an interface that allows user to input commands. Different shells use different faces of prompts (shells will be tackled later in the course). In this server, you will be greeted with: Notice the different parts of your prompt. For the example prompt, it has displayed the username, current directory you are in, the computer name and the prompt sign. Step 3 Write down the prompt on your screen. _________________________________________________________________________ _________________________________________________________________________ 3a. Is your username displayed on the prompt? What is your username? _________________________________________________________________________ _________________________________________________________________________ 3b. Is a computer name displayed on the prompt? What is the computer name? _________________________________________________________________________ _________________________________________________________________________ 2
  • 3. 3c. What is the prompt sign on your screen? _________________________________________________________________________ _________________________________________________________________________ 1.3. Entering Commands Commands can be entered to the Unix server via the command prompt. This is usually done by typing a series of characters after the prompt sign. A usual format in entering commands is: [dwight@netopsy1 greg]$ command <options> <argument> Options for the command are switches that tell a command to do something differently. Arguments are information sometimes needed by the command to be able to execute properly. Most of the time, options and arguments are not needed in a command. There are also commands wherein you do not need to type anything. These commands are: ctrl-c, ctrl-d, ctrl-s, and ctrl-d. The table below gives a short description. Step 4 On the command prompt, type “man –S 1 pwd” and press enter. This command will be tackled later in the course, for now just accept it. 4a. What is the option in the command? _________________________________________________________________________ _________________________________________________________________________ 4b. What is the argument in the command? _________________________________________________________________________ _________________________________________________________________________ 4c. Press “q” to exit the command. _________________________________________________________________________ _________________________________________________________________________ Step 5 On the command prompt, type “top” and press enter. 5a. Press the control and “c” key at the same time. What happened? Did it have the same effect as pressing “q”? Why” _________________________________________________________________________ _________________________________________________________________________ 3
  • 4. Step 6 On the command prompt, type ”man chmod” and press enter. 6a. Press the spacebar. Did the screen scroll up? _________________________________________________________________________ _________________________________________________________________________ 6b. Press the control and “s” key at the same time and then press the spacebar. Did the screen scroll up? Why? _________________________________________________________________________ _________________________________________________________________________ 6c. This time press the control and “q” key at the same time. What happened? ________________________________________________________________________ _________________________________________________________________________ 6d. What does the command “ctrl-s” and “ctrl-q” do? ________________________________________________________________________ _________________________________________________________________________ 1.4. Changing Password One of the first things you must do on your user account is to change your password. Password ensures that no one will have unauthorized access to your user account. A user must have to be authenticated using a password before access to server will be given. To change your password, use the command: passwd. You will be prompted by the server of your old password and then will be prompted to input a new password. You will have to re-type your new password for verification. You can change your password anytime. Password must have at least six characters with any alphanumeric combination (at least for Linux) but is case sensitive. Step 7 At the command prompt, type “passwd”. 7a. Enter your current password when prompted for the old password. 7b. Enter the password “h3ll0”, when prompted for the new password. 7c. Was the password rejected? Why was it rejected? ________________________________________________________________________ _________________________________________________________________________ 7d. Enter the password “r3ch3tt” when prompted for the new password. 7e. Was the password was accepted? Why was it accepted? ________________________________________________________________________ _________________________________________________________________________ 7f. What is the message when the password was successfully changed? ________________________________________________________________________ _________________________________________________________________________ 4
  • 5. Step 8 At the command prompt, type “passwd“ again. Type the current password as “R4ch3tt”. 8a. Was the password rejected? Why was it rejected? ________________________________________________________________________ _________________________________________________________________________ 8b. What is the message when the password was not successfully changed? ________________________________________________________________________ _________________________________________________________________________ Step 9 At the command prompt, type “passwd“ again. Enter the current password. Use your desired password when prompted for a new password. Remember your new password. 9a. Were you able to give a new password on your first try? What were the messages from the server? ________________________________________________________________________ _________________________________________________________________________ 1.5. Basic File Management Unix file system, like other file systems of other operating systems, consists of files and each file has a file name. There are three kinds of files on your Unix system: ordinary, special and directories. The Unix file system is organized as a hierarchy of directories where each directory can contain files or subdirectories. This hierarchy is called a tree where the root (/) is the top of the tree. Each file in a directory has a file identifier (this is not synonymous to file name), which is a sequence of characters that uniquely identifies a file or directory. A file identifier can have at most 255 characters (this includes extension); any printable character can be used as to name a file but cannot contain “/”. Although the characters “*”, “?”, “>”, “>” or “|”, it is not recommended because it has special meaning. Remember that filenames in Unix are case sensitive. File names in Unix, contains a sequence of file identifiers that designates a file. Slashes “/” are used to separate the sequence of file identifiers. There are two kinds of file name: absolute and relative file name. Absolute file name specifies the sequence of directories starting from the root (it actually starts with a “/”) and can be used to refer to a file anywhere in the tree. Relative file name’s starting point is the current directory or working directory. Relative file name can use symbols “.” and “..” which represents the current directory and parent directory respectively. Another symbol “~”, represents the home directory. Home directory is the personal directory of a user where your files can be stored. In order to do basic file management, there are several basic commands that can be used. Usual commands needed are to list files in a directory, change to another directory, create a new directory, move a file or directory, copy a file or directory, and remove a file or directory. Most of the commands can use absolute or relative filenames. The commands are presented in a table below. 5
  • 6. 1.5.1. Changing to different directories The “cd” command is used to change the working directory. Every time you log in via Telnet, you will be in your home directory. Most of the time, your directory is located in the “/home” parent directory. The hierarchy can be shown as: The hierarchy shown is very simple. This is not the whole hierarchy for the Unix system. Also, not all hierarchy is the same for all Unix versions. Step 10 While you are in the home directory, type the command “pwd”. 10a. What was the message on the screen? ________________________________________________________________________ _________________________________________________________________________ 10b. What does the “pwd” command do? ________________________________________________________________________ _________________________________________________________________________ Step 11 Type the command “cd /etc” and press enter. 11a. Did the prompt display differently? Write down the display. ________________________________________________________________________ _________________________________________________________________________ 11b. Type the command “pwd”. What is your current working directory? ________________________________________________________________________ _________________________________________________________________________ 6
  • 7. Step 12 From the “/etc” directory, type the command “cd /home/<username>”. 12a. Did you go to your “home” directory? How were you able to determine? ________________________________________________________________________ _________________________________________________________________________ 12b. What was the file name used (absolute or relative file name)? Why? ________________________________________________________________________ _________________________________________________________________________ 12c. On the command prompt, type “cd ../../etc” and press enter. Were you able to go to the “/etc” directory? What was the file name used (absolute or relative file name)? Why? ________________________________________________________________________ _________________________________________________________________________ 12d. From the “/etc” directory, type the command “cd ~”. Were you able to go to the “home” directory? Which “cd” command is this similar to? ________________________________________________________________________ _________________________________________________________________________ 1.5.2. Listing Directories The “ls” command is used to list directories. There are a lot of options you can do with the command. It is able to display all files, directories only and other more options. Step 13 On the command prompt, type the command “cd ..” and press enter. 13a. Enter the “ls” command. What did you see? ________________________________________________________________________ _________________________________________________________________________ 13b. Enter the “ls -A” command. What is the option? Was it different from last time? ________________________________________________________________________ _________________________________________________________________________ 13c. Enter the “ls -a” command. What is the option? Was it different from last time? What does it do? ________________________________________________________________________ _________________________________________________________________________ The “ls” command with option “A”, shows all files in the directory including hidden files. Hidden files are files that start with “.”. The “a” option has the same function as “A” option except that it also displays the “.” (current) and “..” (parent) directories. 7
  • 8. 13d. Enter the “ls -l” command. What is the option? Was it different from last time? What does it do? ________________________________________________________________________ _________________________________________________________________________ The first column on the “ls -l” shows the file permission of the file or directory (again, will be discussed later). Notice that a “d” as the first character shows which are the directories. 13e. Enter “cd /etc” and then the “ls -d rc0.d” command. What is the option? What does it do? Is it different from the “ls rc0.d” command? ________________________________________________________________________ _________________________________________________________________________ The “d” displays if the “rc0.d” directory is there or not. While the “ls” command without the “d” option will display the contents of the directory “rc0.d”. 13f. Enter the “ls -R” command. What is the option? What does it do? How is it different from “ls”. ________________________________________________________________________ _________________________________________________________________________ The “R” option displays the directories recursively. Step 14 Metacharacters are characters with special meaning in Unix. One of the metacharacters is “*”. 14a. Go to the “/home/dir1” directory, type the command “ls f*”. What files were listed? ________________________________________________________________________ _________________________________________________________________________ 14b. Enter the command “ls p*”. What files were listed? ________________________________________________________________________ _________________________________________________________________________ 14c. Enter the command “ls file?”. What files were listed? ________________________________________________________________________ _________________________________________________________________________ 14d. What is the difference between the commands “ls f*” and “ls file?”? ________________________________________________________________________ _________________________________________________________________________ 14e. Enter the command “ls [f..p]ile1”. What files were listed? ________________________________________________________________________ _________________________________________________________________________ 8
  • 9. 14f. Enter the command “ls [f..p]ile2”. What files were listed? ________________________________________________________________________ _________________________________________________________________________ 14g. Enter the command “ls [f..p]ile?”. What files were listed? ________________________________________________________________________ _________________________________________________________________________ 14h. What does the metacharacter “[..]” do? ________________________________________________________________________ _________________________________________________________________________ The metacharacter “*” is a wildcard for multiple characters while “?” is wildcard for a single character. The metacharacter “[..]” is used to specify a range of characters. 1.5.3. Creating Directories Directories in the Unix operating system can be created using the “mkdir” command. Naming directories has the same rules as naming files. Exercises on filenames will be tackled later. Step 15 Go to your home directory by entering the command “cd ~”. Then create a directory “coffees” using the command “mkdir coffees”. 15a. Was the directory created? ________________________________________________________________________ _________________________________________________________________________ 15b. Enter the command “cd coffees” and press enter. Next, enter the command “mkdir beans/robusta”. Were you able to create the directory? ________________________________________________________________________ _________________________________________________________________________ 15c. Enter the command “mkdir -p beans/robusta”. Were you able to create the directory? Why do you think so? What is the “p” option for? ________________________________________________________________________ ___________________________________________________________________________________________ The “p” option allows creation of directories with its parent directory. 1.5.4. Filenames Empty files are files with a size of zero bytes. The “touch” command can be used to create empty files. The “touch” command will be used to practice creating files with different filenames. In Unix, filenames can have up to 255 printable characters except for the “/” character. Although “*” and “?” can be used, these characters have special meaning. 9
  • 10. Step 16 While in the directory “coffees/beans/robusta”, enter the command “touch robusta.txt”. 16a. Were you able to create the file? What is the size of the file? How were you able to determine the file size? ________________________________________________________________________ ___________________________________________________________________________________________ 16b. Enter the command “touch robusta/txt“. Were you able to create the file? Why? What was the message? ________________________________________________________________________ ___________________________________________________________________________________________ 16c. Enter the command “touch robusta1“. Were you able to create the file? Why? ________________________________________________________________________ ___________________________________________________________________________________________ 16d. Enter the command “mkdir robusta.doc“. Were you able to create the directory? Why? ________________________________________________________________________ ___________________________________________________________________________________________ 16e. Enter the command “ls“. Can you tell which one is a directory? What command should be used to be able to determine which one is a directory? ________________________________________________________________________ ___________________________________________________________________________________________ 16f. Enter the command “ls robusta*“. Is there a difference from the earlier command? Can you tell which one is the directory? Why? ________________________________________________________________________ ___________________________________________________________________________________________ 1.5.5. Copying Files The cp command is used to copy files. The command can be used to copy one source to a destination or multiple sources to a directory. Step 17 Enter the command “cp robusta.txt robusta.html”. 17a. What happened after entering the command? Did you see the file “robusta.html”? ________________________________________________________________________ ___________________________________________________________________________________________ 17b. Enter the command “cp robusta.txt robusta.doc”. What happened after entering the command? Did you see the file “robusta.doc“? Why? ________________________________________________________________________ ___________________________________________________________________________________________ 10
  • 11. 17c. Enter the command “cp robusta.txt robusta.html”. Were you prompted if the file was to be overwritten? Why? ________________________________________________________________________ ___________________________________________________________________________________________ 17d. Enter the command “cp –i robusta.txt robusta.html”. Were you prompted if the file was to be overwritten? Why? ________________________________________________________________________ ___________________________________________________________________________________________ 1.5.6. Moving Files In the Unix operating system, moving of files can be done by using the command “mv”. The command can also be used to rename files. Step 18 Enter the command “mkdir -p ../arabica” and press enter. Next, enter the command “touch arabica.txt”. Use the command “ls” to verify the file is existent. 18a. Enter the command “mv arabica.txt ../arabica”. Is the file “arabica.txt” still there? Where is it located now? What did the command “mv” do? ________________________________________________________________________ ____________________________________________________________________________________ 18b. Enter the command “touch arabica.txt” under the directory “<home directory>/coffees/beans/robusta”. Next, type the command “mv arabica.txt ../arabica”. What happened? Were you prompted that you will be overwriting a file? ________________________________________________________________________ _____________________________________________________________________________________ 18c. Enter the command “touch arabica.txt” under the directory “<home directory>/coffees/beans/robusta”. Next, type the command “mv –i arabica.txt ../arabica”. What happened? Were you prompted that you will be overwriting a file? ________________________________________________________________________ _____________________________________________________________________________________ Answer no to the prompt. 18d. Enter the command “mv arabica.txt arabica.doc”. What happened? Is the file still there? Why? ________________________________________________________________________ _____________________________________________________________________________________ 11
  • 12. The command can be used to rename files. 18e. What is the difference between the command “cp arabica.txt ../arabica” and “mv arabica.txt ../arabica”. Explain. ________________________________________________________________________ _____________________________________________________________________________________ 1.5.7. Removing Files Removing or deleting files can be accomplished by using the command “rm”. Be careful in using this command since deleted file are unrecoverable. Step 19 Go to the “<home directory>/coffees/beans/robusta” directory. Type the command “rm arabica.doc”. 19a. Was the file still there? Can it be found in another directory? Why? ________________________________________________________________________ _____________________________________________________________________________________ Step 20 Enter the command “rm *”. 20a. What happened? Which file or directory was retained? ________________________________________________________________________ _____________________________________________________________________________________ 20b. Why was it retained? ________________________________________________________________________ _____________________________________________________________________________________ Step 21 Go to the “robusta.doc” directory. Create the following directory “bean_quality” and “bean_quality/perfect_cup”. 21a. Go to the “<home directory>/coffees/beans/robusta”. Enter the command “rm robusta.doc”. Were you able to remove the directory? Why? ________________________________________________________________________ _____________________________________________________________________________________ 21b. Enter the command “rm -r robusta.doc”. Were you able to remove the directory? Why? What is the option “r” for? ________________________________________________________________________ _____________________________________________________________________________________ Step 22 Go to the “arabica” directory. Enter the command “rm –i arabica.txt”. 22a. Was the file erased immediately? What was the message? ________________________________________________________________________ _____________________________________________________________________________________ 12
  • 13. 22b. Answer “y” to the prompt. Was the file removed? What is the option “i” for? ________________________________________________________________________ _____________________________________________________________________________________ 22c. Go to the “<home directory>/coffees” directory and enter the command “rm -ir robusta.doc”. Were prompted before removal? What was the message? ________________________________________________________________________ _____________________________________________________________________________________ Answer “n” to the prompt. 1.6. Logging Out The “exit” command can be used to log out of the Unix server. Step 23 At the prompt type the command “exit”. 23a. What happened? Were you able to log out? Is there an alternative command? (You may research this on books or in the Internet) ________________________________________________________________________ _____________________________________________________________________________________ 13
  • 14. Laboratory Activity 2 Name: __________________________________ Date: _____________ Utilities, Redirection and Pipes 2.0 Unix / Linux Command Line Interface (CLI) Basics – Utilities, Redirection and Pipes, vi Text Editor and Advanced File Commands The Unix system provides a lot of utilities that one can use. Aside from utilities, the Unix system also provides facilities for redirection, pipes and file ownership, and file permissions. The Unix system also has a built-in editor called vi. Although vi may look ugly, vi is the standard text editor you can find in any Unix version and at the same time has useful features at your fingertips. No need to use the mouse. The objectives of this section are: 1. To familiarize the student in using Unix file and disk utilities. 2. To familiarize the student in using the vi text editor. 3. To familiarize the student on file links. 4. To familiarize the student on file ownership and permissions. 2.1. Utilities 2.1.1. On-line Help The Unix environment provides a simple on-line help system. The command “man” is used to browse the help pages. This help system is sometimes referred to as “man pages”. Typing “man ls” at the command prompt will show you something like: The man page most of the time will contain the following sections (different Unix versions or authors of man pages sometimes add sections): name, synopsis, description, and see also. The name section shows the name of the command and alternative commands that does the same thing. The synopsis section shows the syntax of the command while the description gives a short text on what the command does and the options that can be used. The see also section gives other related commands. Man pages also provide help on programming libraries, utilities, file formats and other topics on the Unix environment. 14
  • 15. Step 1 On the command prompt, type the command “man ls”. 1a. What does the command do? _________________________________________________________________________ _________________________________________________________________________ 1b. Press the spacebar key. What does it do? _________________________________________________________________________ _________________________________________________________________________ 1c. Press the “f” key. What does it do? Is it the same as the space bar key? _________________________________________________________________________ _________________________________________________________________________ 1d. Press the “b” key. What does it do? _________________________________________________________________________ ____________________________________________________________________________________________ 1e. Type the following “/format”. What does it do? _________________________________________________________________________ ____________________________________________________________________________________________ 1f. Press the “q” key. What does it do? _________________________________________________________________________ ____________________________________________________________________________________________ Step 2 On the command prompt, type the command “man ls”. Scroll the pages and check the sections of the man page. 2a. Can you identify the sections mentioned? What are these sections? _________________________________________________________________________ ____________________________________________________________________________________________ 2b. Write down the description of the “ls” command. _________________________________________________________________________ ____________________________________________________________________________________________ 15
  • 16. 2c. Write down an alternative command that you can use to view a help file on ls. _________________________________________________________________________ ____________________________________________________________________________________________ Step 3 On the command prompt, type the command “man -k dns”. 3a. What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 3b. What is the “k” option for? _________________________________________________________________________ ____________________________________________________________________________________________ The “k” option is for searching man pages given a keyword. The argument in the command is the keyword. In this case, the command looks for man pages that have the word “dns” in it. As a bit information, dns stands for “Domain Name Server”. Domain name server is a service that allows mapping of Internet names into its IP address (There will be a section for DNS, please do not worry about it yet. ). Step 4 On the command prompt, type the command “man -S1 chmod”. 4a. What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ If you look carefully at the upper right corner of the man page, there is a “( )” after the command. This indicates in what section of the command are you viewing. Using the “s” option allows you to specify which section would you want to view. The man utility displays the lowest numbered section by default when no section number is provided from the command. 2.1.2. The “file” and “wc” Commands The “file” command allows the user to determine the file type. This is useful if you cannot remember what the file is for. The “wc” command prints the number of line, words and bytes in a file. Step 5 At the command prompt, enter the command “cp /home/files/rfc2186.txt rfc2186.txt” and the command “cp /home/files/rf2186.pdf rf2186.pdf”. After copying the files, verify if the files were copied. 5a. At the command prompt, enter the command “file rfc2186.txt”. What type of file is it? _________________________________________________________________________ ____________________________________________________________________________________________ 5b. At the command prompt, enter the command “file NETOPSY_Lab_Manual.pdf”. What type of file is it? _________________________________________________________________________ ____________________________________________________________________________________________ 16
  • 17. 5c. At the command prompt, enter the command “mv rfc2186.txt rfc2186”. After renaming the file, enter the command “file rfc2186”. Was it still able to determine the file type? _________________________________________________________________________ ____________________________________________________________________________________________ Step 6 At the command prompt, enter the command “wc rfc2186”. 6a. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 6b. How many bytes, words and lines does the file have? _________________________________________________________________________ ____________________________________________________________________________________________ 6c. At the command prompt, enter the command “wc -c rfc2186”. How many bytes does the file have? Is it the same as its file size? _________________________________________________________________________ ____________________________________________________________________________________________ 6d. At command prompt, enter the command “wc NETSOPY_Lab_Manual.pdf”. How many bytes, words and lines does the file have? _________________________________________________________________________ ____________________________________________________________________________________________ 2.1.3. The “more” and “cat” Commands The “cat” command can concatenate files and print on standard output (which is usually the screen). This is useful for checking the contents of short file, especially script files (again, will be tackled later). The command can accept more than one filenames as an argument that can be printed on the standard output. The problem with the “cat” command is that if the file is too long, the displaying of the file will just flash by. An alternative command is the “more” command. This command displays the file on the standard output and provides scrolling capability. Commands for scrolling are the same in the “man” utility. Step 7 At the command prompt, enter the command “cp /home/files/fruits fruits” and press enter. After copying the file, enter the command “cp /home/files/vegetables vegetables” and press enter. Verify if you have copied the file using the “ls” command. 7a. After verifying the files were copied, enter the command “cat fruits”. What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 17
  • 18. 7b. Enter the command “cat vegetables”. What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 7c. Enter the command “cat fruits vegetables”. What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 7d. Enter the command “cat vegetables fruits”. What did the command do? Is it different from the previous command? What can you generalize? _________________________________________________________________________ ____________________________________________________________________________________________ 7e. Enter the command “cp /home/files/rfc2186.txt rfc2186.txt”. Verify if the file was copied using the “ls” command. 7f. Enter the command “cat rfc2186.txt”. What did the command do? Were you able to see anything? _________________________________________________________________________ ____________________________________________________________________________________________ Step 8 At the command prompt, enter the command “more rfc2186” and press enter. 8a. Are you able to view the file? _________________________________________________________________________ ____________________________________________________________________________________________ 8b. Press the spacebar key. What does it do? _________________________________________________________________________ ____________________________________________________________________________________________ 8c. Press the “f” key. What does it do? Is it the same as the space bar key? _________________________________________________________________________ ____________________________________________________________________________________________ 8d. Press the “b” key. What does it do? _________________________________________________________________________ ____________________________________________________________________________________________ 18
  • 19. 8e. Press the “q” key. What does it do? _________________________________________________________________________ ____________________________________________________________________________________________ There are still other commands to scroll the screen in the “more” command. Use the man pages for the “more” command to check the scroll commands and other options. 2.1.4. The “head” and “tail” Commands The “head” command outputs the first few lines of a few on the screen while the “tail” command outputs the last few lines of a file on the screen. The default number of line output is ten (10). These commands useful for checking log files, especially to network administrators. Step 9 At the command prompt, type the command “head rfc2186”. 9a. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 9b. At the command prompt, type the command “head -c20 rfc2186”. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 9c. At the command prompt, type the command “head -n20 rfc2186”. What was the output? How was it different from last time? _________________________________________________________________________ ____________________________________________________________________________________________ 9d. At the command prompt, type the command “tail rfc2186”. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 9e. At the command prompt, type the command “tail -c20 rfc2186”. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 9f. At the command prompt, type the command “tail -n20 rfc2186”. What was the output? How was it different from last time? _________________________________________________________________________ ____________________________________________________________________________________________ 19
  • 20. 9g. What is the difference between options “c” and “n”? _________________________________________________________________________ ____________________________________________________________________________________________ 2.1.5. The “grep” Command The “grep” command searches prints the lines in a file with a matching pattern. This is useful for searching patterns in a text or binary file. Most of the time, network administrators uses this to search if a certain process is running (to be discussed later) or searching for keywords in a configuration file (again, to e discussed later). Step 10 At the command prompt, enter the command “grep apple fruits”. 10a. What was the output? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 10b. At the command prompt, enter the command “grep broccoli fruits”. Was there an output? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 10c. At the command prompt, enter the command “grep broccoli vegetables”. Was there an output? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 2.1.6. The “sort” Command The “sort” command allows a user to sort alphanumeric text in a file. If the text file has columns, the “sort” command is able to sort by column. This is useful if you have a spreadsheet like text file. Step 11 At the prompt, enter the command “cat fruits”. Observe the output of the command. 11a. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 11b. At the prompt, enter the command “sort fruits”. Observe the output of the command. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ Step 12 At the prompt, enter the command “cp /home/files/fruits2 fruits2”. 12a. After copying the file, enter the command “cat fruits2”. Observe the output of the command. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 20
  • 21. 12b. At the prompt, enter the command “sort fruits2”. Observe the output of the command. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 12c. At the prompt, enter the command “sort -r fruits2”. Observe the output of the command. What was the output? How is different from the previous command? _________________________________________________________________________ ____________________________________________________________________________________________ 12d. At the prompt, enter the command “sort -k1 fruits2”. Observe the output of the command. What was the output? How is it different from the command in step 2b? _________________________________________________________________________ ____________________________________________________________________________________________ 12e. At the prompt, enter the command “sort -r -k1 fruits2”. Observe the output of the command. What was the output? How is it different from the command in the previous step? _________________________________________________________________________ ____________________________________________________________________________________________ 2.2. Redirection and Pipes Redirectors “redirect” the standard output of a command to a file or device file. This is useful for saving a long list of directories and files in text file for example. A redirection command looks like: command > file or command > file_device The “>” is the redirection symbol. Redirection symbols are: Pipes are the same as redirection but use the output of a command as input to another command. The pipe symbol is “|”. Step 13 At the command prompt, enter the command “ls -l > list”. 13a. Was the text file list created? _________________________________________________________________________ ____________________________________________________________________________________________ 13b. Use the “cat” or “more” command to view the “list” text file. What does the text file contain? _________________________________________________________________________ ____________________________________________________________________________________________ 21
  • 22. 13c. At the command prompt, enter the command “ls -l > list”. Was a new text file list created? What does the text file contain? Was it the same as before? _________________________________________________________________________ ____________________________________________________________________________________________ 13d. At the command prompt, enter the command “ls -l >> list”. Was a new text file list created? What does the text file contain? Was it the same as before? _________________________________________________________________________ ____________________________________________________________________________________________ 13e. What is the difference between the “>“ and the “>>” redirection symbol? _________________________________________________________________________ ____________________________________________________________________________________________ Step 14 At the command prompt, enter the command “cd /etc/”. After changing to the “/etc” directory, enter the command “ls -l”. 14a. Were you able to see all the file names? Did just scrolled by? _________________________________________________________________________ ____________________________________________________________________________________________ 14b. At the command prompt, enter the command “ls -l |more”. Were you able to see the directory listing properly? _________________________________________________________________________ ____________________________________________________________________________________________ 14c. Which are the commands in the previous command? Which is the pipe symbol? _________________________________________________________________________ ____________________________________________________________________________________________ Remember that the “more” in the command is neither an option nor an argument. “more” is a command utility that is used to view a file. Step 15 At the prompt, enter the command “cd ~” and “mkdir dir1 dir2”. 15a. At the prompt, enter the command “ls -l”. Observe the output. What was the output of the command? _________________________________________________________________________ ____________________________________________________________________________________________ 15b. At the prompt, enter the command “ls -l |sort -k1”. Observe the output. How is different from the previous command? _________________________________________________________________________ ____________________________________________________________________________________________ 22
  • 23. 15c. At the prompt, enter the command “ls -l |sort -r -k1”. Observe the output. How is different from the previous command? _________________________________________________________________________ ____________________________________________________________________________________________ 15d. At the prompt, enter the command “ls -l |sort -k8”. Observe the output. How is different from the command in step 3b? _________________________________________________________________________ ____________________________________________________________________________________________ 15e. At the prompt, enter the command “ls -l |sort -r -k8”. Observe the output. How is different from the previous command? _________________________________________________________________________ ____________________________________________________________________________________________ Remember that the “sort” in the command is neither an option nor an argument. “sort” is a command utility that is used to sort text in a file. 2.3. The vi Text Editor The vi text editor is a built-in in the Unix operating system. This text editor is a standard on all Unix versions. Most people would say that vi is not user-friendly, which is very true but vi very powerful. Only the most basic command set will be tackled in this section. If you need or want to learn more, you can use the man page for vi for further reference or the suggested reference books in this course. Vi has three modes of operation: command, entry mode and last-line mode. In the command mode, accepts command for cursor positioning, going into other modes, deleting characters or lines and searching for string patterns. The entry mode allows editing of text while the last-line mode allows saving and exiting from vi. Upon starting of vi, the program goes into the command mode. The following is a summary of the commands: 23
  • 24. Step 16 At the command prompt, enter the command “vi rfc2186”. 16a. In which mode are in right now? _________________________________________________________________________ ____________________________________________________________________________________________ 16b. In the command mode of vi, type “:22”. In which line of test are you in now? (Write down the first few words of the line) _________________________________________________________________________ ____________________________________________________________________________________________ 16c. Go to the word “describes”. Use the cursor keys or (h, j, k, l). Type the “a” command. In which mode are you in now? _________________________________________________________________________ ____________________________________________________________________________________________ 16d. Type the word “cat” and press the escape key. Where did the cursor allowed you to enter text? Before or after the cursor? In which mode are you in now? _________________________________________________________________________ ____________________________________________________________________________________________ 16e. Type the “i” command. In which mode are you in now? _________________________________________________________________________ ____________________________________________________________________________________________ 16f. Type the word “hello” and press the escape key. Where did the cursor allowed you to enter text? Before or after the cursor? In which mode are you in now? _________________________________________________________________________ ____________________________________________________________________________________________ 16g. Press the escape the key. In which mode are you in now? _________________________________________________________________________ ____________________________________________________________________________________________ 16h. Type the command “x”. What happened? What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16i. Type the command “2dd”. What happened? What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 24
  • 25. 16j. Type the command “yy”. What happened? What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16k. Type the “p”. What happened? What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16l. Type the command “:wq”. What happened? What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16m. Enter the command “vi rfc2186”. Go to line 21. Did vi saved your edited file? _________________________________________________________________________ ____________________________________________________________________________________________ 16n. Type the command “yy”. What happened? What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16o. Type the “p”. What happened? What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16p. Type the command “:q!”. What happened? What did the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 16q. Enter the command “vi rfc2186”. Go to line 21. Did vi saved your edited file? _________________________________________________________________________ ____________________________________________________________________________________________ There are other text editors in the Unix system. There is the Emacs text editor and pico. Emacs is standard in the Unix system while pico is not. The pico text editor is only found in the Linux version of Unix. You may refer to man pages for pico and Emacs or the suggested references in this course. 25
  • 26. 2.4. Advanced File Commands 2.4.1. Disk Usage and Disk Free The Unix environment allows the user to check his disk usage and the available disk space in the file system. The commands are “du” and “df” respectively. The “du” command allows a user to his/her disk usage including usage in subdirectories. By default, the disk usage is presented in 1024 bytes per block. If a user sees that his/her disk usage is 108 blocks, this means that it is really 110592 bytes total (108*1024 bytes per block). The “df” command shows the disk statistics of a file system. Typing “df” on the command prompt will produce an output on the screen: Looking at the sample output above, the filesystem column shows the partition/s on the server. The next column, 1kblocks, shows the capacity (total size) of the partition. The Used column shows how much is already used on the partition, while Available shows how much can still be used. The Use% shows how much percentage is used on the partition. The Mounted on column shows what is the directory name of the partition. In the example above, partition /dev/sda2 shows that it has a capacity of around 3.6Gbyte. On the same partition, around 359Mbyte is already used with still 3.1Gbyte available. Data on the partition occupies only 11% of the disk space. This partition is mounted as the root (the meaning of mounted will be discussed later in the course). Before starting the exercise, delete all files in your home directory by entering the command “rm *”. Step 17 At the command prompt, type the command “cp /home/files/rfc2186.txt rfc2186.txt” and press enter. This command should be done at your home directory. After the copying the file, type the command “du” at the command prompt. Observe the numbers. 17a. How many directories do you have? How many blocks are you using in your directory? _________________________________________________________________________ ____________________________________________________________________________________________ 17b. At the command prompt, type the command “du -k”. The switch used in the command defines that each block is 1024 bytes. How many bytes are you using in your home directory? _________________________________________________________________________ ____________________________________________________________________________________________ 17c. At the command prompt, type the command “du -ck”. How is this different from the previous command? _________________________________________________________________________ ____________________________________________________________________________________________ Step 18 At the command prompt, type the command “cp /home/files/OPERSYS_Lab_Manual.pdf OPERSYS_Lab_Manual.pdf” and press enter. 18a. Type the command “du -ck” on the command prompt and press enter. Did the total number of blocks used increase? _________________________________________________________________________ ____________________________________________________________________________________________ 26
  • 27. 18b. How many bytes are you using? _________________________________________________________________________ ____________________________________________________________________________________________ Step 19 At the command prompt, type the command “df”. 19a. How many bytes is one block in the command? _________________________________________________________________________ ____________________________________________________________________________________________ 19b. How many bytes is the capacity of /dev/sda1? _________________________________________________________________________ ____________________________________________________________________________________________ 19c. How many bytes are used on /dev/sda1? _________________________________________________________________________ ____________________________________________________________________________________________ 19d. How many bytes are available on /dev/sda1? _________________________________________________________________________ ____________________________________________________________________________________________ 19e. What is the percentage of data used in /dev/sda1? _________________________________________________________________________ ____________________________________________________________________________________________ 19f. At the command prompt type the command “df -m”. What is the size of each block in this command? _________________________________________________________________________ ____________________________________________________________________________________________ 2.4.2. Hard Links and Soft Links A file link is a directory entry for a file. Each file has a file name entry with a corresponding information entry that allows access to the file. A file can have two types of links: hard link and soft link (also sometimes called symbolic link). A hard link creates a new file name entry for a file but does not create another copy of the file (this is synonymous to having two pointers point to a file) while a symbolic link creates a new file entry pointing to the original file entry. Most of the time, symbolic links are more useful since you can use it to create “short cuts” to a directory. Step 20 At the command prompt, type the command “du -ck”. 20a. What is your total disk usage? _________________________________________________________________________ ____________________________________________________________________________________________ 27
  • 28. 20b. At the command prompt, type the command “cp rfc2186.txt rfc_2186.txt”. This will create a copy the text file “rfc2186.txt”. Verify of the file was created using the “ls -l” command. Was the file created? _________________________________________________________________________ ____________________________________________________________________________________________ 20c. At the command prompt, type the command “du -ck”. What is your total disk usage? Did your disk usage increased? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 20d. View the contents file “rfc2186.txt” by typing the command “more rfc2186.txt”, to exit type “q”. Also view the contents of the file “rfc_2186.txt” using the command “more rfc_2186.txt”, to exit type “q”. Were you able to view both files? _________________________________________________________________________ ____________________________________________________________________________________________ 20e. Delete the file “rfc_2186.txt” and check your disk usage using the command “du -ck”. What is your disk usage? _________________________________________________________________________ ____________________________________________________________________________________________ 20f. At the command prompt, type the command “ln rfc2186.txt rfc_2186.txt”. This command creates a hard link for the file “rfc2186.txt” text file. Verify if the hard link was created using the command “ls - l”. Was the hard link created? _________________________________________________________________________ ____________________________________________________________________________________________ 20g. At the command prompt, type the command “du -ck”. What is your total disk usage? Did your disk usage increased? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 20h. View the contents file “rfc2186.txt” by typing the command “more rfc2186.txt”, to exit type “q”. Also view the contents of the file “rfc_2186.txt” using the command “more rfc_2186.txt”, to exit type “q”. Were you able to view both files? _________________________________________________________________________ ____________________________________________________________________________________________ 28
  • 29. 20i. Delete the file “rfc2186.txt” and try to view the file “rfc_2186.txt” using the more command. Were you still able to view the file? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ 20j. Delete the file “rfc_2186.txt” and copy the file “rfc2186.txt” using the command “cp /home/files/rfc2186.txt rfc2186.txt”. Verify if the file was copied using the “ls -l” command. _________________________________________________________________________ ____________________________________________________________________________________________ 20k. At the command prompt, type the command “ln -s rfc2186.txt rfc_2186.txt”. This command creates a soft link (symbolic link) for the file “rfc2186.txt” text file. Verify if the hard link was created using the command “ls -l”. Was the soft link created? How would you know if it were a soft link (do not use the color of the text to know the difference)? _________________________________________________________________________ ____________________________________________________________________________________________ 20l. View the contents file “rfc2186.txt” by typing the command “more rfc2186.txt”, to exit type “q”. Also view the contents of the file “rfc_2186.txt” using the command “more rfc_2186.txt”, to exit type “q”. Were you able to view both files? _________________________________________________________________________ ____________________________________________________________________________________________ 20m. Delete the file “rfc2186.txt” and try to view the file “rfc_2186.txt” using the more command. Were you still able to view the file? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ Delete the soft link created for the file “rfc2186.txt”. Step 21 At the command prompt, type the command “ln -s /home/dir1 test_dir”. 21a. Was the soft link for the directory created? _________________________________________________________________________ ____________________________________________________________________________________________ 21b. How do you know if it is a soft link by using the “ls -l” command? _________________________________________________________________________ ____________________________________________________________________________________________ Step 22 On the command prompt type the command “ls /home/dir1” and then type the command “ls test_dir”. 22a. Were the contents of the directories the same? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 29
  • 30. 22b. Use the command “rmdir test_dir” to delete “test_dir”. Were you successful? What was the message on the screen? _________________________________________________________________________ ____________________________________________________________________________________________ 22c. Use the command “rm test_dir” to delete “test_dir”. Were you successful? _________________________________________________________________________ ____________________________________________________________________________________________ 2.4.3. File Ownership, File Permissions and Groups Each file in the Unix system has an owner and permission. Each file is associated to an owner using its user ID. The username is just a way for us to remember than just a bunch of numbers. A group is a logical grouping of users. Each group name in the Unix system has a group ID. A group may also have ownership of a file. Most of the time, the owner has access to the file and modifies the permission of a file. File permission is way to provide file security in the Unix system. When you enter the command “ls –l”, notice the first column. The first column in the output of the command shows the file permission of a file. The column is composed of 10 characters. The first character indicates whether the file is a directory, the next nine characters show the permission of the file that can be grouped into three columns where each column is composed of three characters. Each three-character column shows the file permission for the owner, group, and world. Each character in the column indicates a read, write or execute permission. The third column in the output of the “ls –l” command shows the owner of the file, while the next column shows which group can have access to the file or which groups the user belongs to. File permissions are also applicable to directories. File permissions can be changed using the “chmod” command. The command uses integers to change the permission of a file. The command “chmod” is used in the form: chmod vyz [file_name] Where vyz is the permission integer to be put into the file. The v is actually a binary representation for rwx. Which “r” is read, “w” is write and “x” is executable. If a “r” is a logic 1, then the file has read permission, if the “r” is logic 0 then the file has no read permission. The same rule applies to w and x. For y and z, the rwx rule applies. Example: chmod 744 rfc2186.txt This command sets the file permission of the text file “rfc2186.txt” as read, write and executable for owner, read for group and last, read for world. Step 23 At the command prompt, enter the command “cp /home/files/rfc2186.txt rfc2186.txt”. 23a. What is the file permission of the owner for the file “rfc2186.txt”? Who is the owner? Which group does it belong to? What is the group’s file permission? _________________________________________________________________________ ____________________________________________________________________________________________ 23b. Enter the command “chmod 444 rfc2186.txt”. Use the vi text editor and try to edit and save the file. Were you successful? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 30
  • 31. 23c. Enter the command “chmod 644 rfc2186.txt”. Use the vi text editor and try to edit and save the file. Were you successful? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 23d. Enter the command “cp /home/files/long_list long_list”. View the file using vi text editor, more or cat command. What does the file contain? Is it a command? What is the file permission for the owner? _________________________________________________________________________ ____________________________________________________________________________________________ 23e. Enter the command “./long_list” at the prompt. What happened? What was the message? _________________________________________________________________________ ____________________________________________________________________________________________ 23f. Enter the command “chmod 766 long_list” at the prompt. What is the file permission for the owner after the command was executed? _________________________________________________________________________ ____________________________________________________________________________________________ 23g. Enter the command “./long_list” at the prompt. What happened? What is the command similar to? _________________________________________________________________________ ____________________________________________________________________________________________ Step 24 At the prompt, enter the command “ls -ld /home/student_files”. 24a. Who is the owner of the file? What is the file permission of the owner? Which group does the directory belong to? What is the group permission? What is the world permission? _________________________________________________________________________ ____________________________________________________________________________________________ 24b. At the prompt, enter the command “groups”. To which group do you belong? _________________________________________________________________________ ____________________________________________________________________________________________ 24c. At the prompt, enter the command “cd /home/student_files”. In the directory, enter the command “touch <username>”. Were you successful? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 24d. At the prompt, enter the command “cd /home” and also enter the command “ls -ld faculty_files”. Who is the owner of the file? What is the file permission of the owner? Which group does the directory belong to? What is the group permission? What is the world permission? _________________________________________________________________________ ____________________________________________________________________________________________ 31
  • 32. 24e. At the prompt, enter the command “cd /home/faculty_files”. In the directory, enter the command “touch <username>”. Were you successful? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 32
  • 33. Laboratory Activity 3 Name: __________________________________ Date: _____________ Processes, Unix Shells, and Shell Scripts 3.0 Unix / Linux Command Line Interface (CLI) Basics – Processes, Unix Shells and Shell Scripts The Unix system allows job control because each command or program executed in the Unix system is a considered a process. Job control allows running of processes, killing processes or creating background processes. The “ps” command shows which processes are running on the system. This like the “ls” command for processes. Running processes can also be terminated using the “kill” command. Job control will be discussed more in the course. The Unix shell is a program that allows interactive use of the Unix operating system and the computer hardware. There are different shells created for the Unix system. The first shell was the Bourne shell. After the Bourne shell, the Korn and C shell was later created. The Korn shell is a superset of the Bourne shell while the C shell was “C” like (“C” as in the C programming language). Although there are several shells available, the shells have the same set of features with only subtle differences. For example, the “history” command is not available in the Bourne shell but is available in the Korn and C shells. The prompts of different shells also look different. Today, the Linux system uses the Bourne Again shell. This “new” shell has the useful features of Korn and C shells. You could say that it is the hybrid of the Korn and C shell. Do remember that the Bourne Again shell is only in Linux versions of Unix systems. As mentioned earlier, these shells have same set features. These features are aliasing, environment setting, variables and shell programming or also known as shell scripts. These features will be discussed in better detail in this section. Shell scripts allow a user to make useful utilities using Unix commands or other utilities. Shell scripts also have constructs like programming languages that allow flexibility. With a minimum background of shells, scripts and job control, the objectives of this section are: 1. Familiarization with Unix shells, it features and how to use it. 2. Familiarization with Unix shell scripts and how create and use shell scripts. 3. Familiarization with controlling jobs on the Unix system. 3.1. Processes One of the ability of the Unix system is run several programs at a time. This is called multi-tasking. The Unix system is the first system to provide this feature. Each process running on the Unix system has a process ID. Since there are several programs running at the same time, there must be a way to control these programs or processes. There are several types of processes on the Unix system. Two basic types of processes is the parent and child process. As the name implies, the parent spawns a child process. If the parent process terminates before the child process returns, the child process will become an orphan. If the child process does not return, it is a zombie or defunct process. Also, the “daemon” process has the process ID of 1 which is the “main” parent of the processes in the Unix system. Users can control the process using the “ps” and “kill” command; that allow a user to control processes. When the “ps” command is executed, the following will be seen on the screen. The first column shows the process id. The second column shows which terminal is running it while the third column shows how much processing time is being used by the process. Fourth column shows the name or the command name. 33
  • 34. The “kill” command can be used to terminate a process. When the “kill” command is used, make sure you know the process ID. There are two ways to kill a process, soft kill and hard kill. With the soft kill, processes are terminated properly while the hard kill terminates a process abruptly. Step 25 On the prompt, type the command “ps”. 25a. How many processes are running? Are the processes running only yours? _________________________________________________________________________ ____________________________________________________________________________________________ 25b. On the prompt type the command “ps -e”. Are all the processes displayed yours? If not, some of the processes belong to whom? _________________________________________________________________________ ____________________________________________________________________________________________ 25c. On the prompt type the command “ps -f”. Is the number or columns different from last time? What is the “f” option for? _________________________________________________________________________ ____________________________________________________________________________________________ 25d. On the prompt type the command “ps -e |more”. What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 25e. On the prompt type the command “ps -e |grep min”. What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ Step 26 On the prompt enter the command “sleep 1000” and open another remote session to same server. Do not exit your first remote session. 26a. Using the new remote session, at the prompt, enter the command “ps -u <user name>”. Were you able to see the “sleep” program? What is the process ID of the “sleep” program? _________________________________________________________________________ ____________________________________________________________________________________________ 26b. At the prompt, kill the “sleep” program using the “kill <pid>” command. Was the “sleep” program terminated? _________________________________________________________________________ ____________________________________________________________________________________________ 26c. Log-out of the new remote session. If ever the process cannot be killed using the soft kill command, use the command “kill -9 <pid>” (hard kill). Before using the command, use the soft kill first because it terminates a process properly than the hard kill command. Step 27 At the prompt, enter the command “sleep 1000 &”. 34
  • 35. 27a. Was this command different from last time? Why? _________________________________________________________________________ ____________________________________________________________________________________________ The “&” at the end of the command tells the shell to make it a background process. 27b. At the prompt, enter the command “ps -f”. Looking at the “PPID” column, what is the parent ID of the process of the “sleep” process? Why was it the parent? _________________________________________________________________________ ____________________________________________________________________________________________ 27c. Kill the sleep program. Step 28 At the prompt, enter the command “ps -f”. Record the process ID of the current shell. 28a. At the prompt, open a new shell using the command “bash” and then enter the command “sleep 1000 &”. Use the command “ps -f” to check the processes. What is the parent ID of the “sleep” program? _________________________________________________________________________ ____________________________________________________________________________________________ 28b. Exit the new shell by using the command “exit”. Enter the command “ps -f”. What is the parent id of the “sleep” process? Which is this process? Why did it changed? _________________________________________________________________________ ____________________________________________________________________________________________ Since the process that spawned the sleep program was terminated before the sleep program ended, the sleep program is now called an orphan. Notice that the daemon process adopted the sleep program. 28c. Kill the “sleep” process that was orphaned. Were you able to kill it? _________________________________________________________________________ ____________________________________________________________________________________________ 3.2. The Unix Shell As mentioned earlier, the shell allows an interactive use of the Unix system and the computer hardware. Without it, it will be hard to use the Unix system and computer. There are different shells available in the Unix system. These shells have same set of features with only little differences. Most of the time, their differences are how the commands are entered. 3.2.1. Bourne Shell (bsh), Bourne Again Shell (bash) and C Shell (csh or tcsh) The Bourne, Bourne Again and C shell are different shell available on the Linux version of the Unix system. These three shells have differences that are only minor. The Bourne and C shell were already available on all Unix system and were the original shells. When Linux came, the Bourne Again shell was developed by the Free Software Foundation. The Bourne Again shell incorporates useful features of the Korn and C shells. Step 29 On the prompt, enter the command “csh”. Observe what happens to the prompt. Always take note that you are in the C shell. 35
  • 36. 29a. What is does your prompt your look like? Why do you think the prompt changed? (In this case, the usual prompt for the C shell in most Unix systems is “%” but in Linux, it has different prompt.) _________________________________________________________________________ ____________________________________________________________________________________________ 29b. On the prompt, enter the following commands: “ls -l”, “ls”. Try using the up and down cursor keys. Were you able to call the previous commands? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ 29c. Clear the command prompt and type the command “history”. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 29d. On the prompt, type the command “!!”. What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 29e. On the prompt, type the command “vi this_is_a_file_with_a_long_name.txt”. Type in the text “The quick brown fox jumps over the lazy dog.” Save the text file. Try to display the file using the “cat this_” then press the “tab” key. What happened? Did the shell complete the filename? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ Step 30 Type the command “exit” at the command prompt and enter the command “bsh”. 30a. Did the prompt changed? What does the prompt look like? _________________________________________________________________________ ____________________________________________________________________________________________ 30b. On the prompt, enter the following commands: “ls -l”, “ls”. Try using the up and down cursor keys. Were you able to call the previous commands? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ 30c. On the prompt, type the command “history”. What was the output? _________________________________________________________________________ ____________________________________________________________________________________________ 30d. On the prompt, type the command “cat this_“ then press the “tab” key. What happened? Did the shell complete the filename? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ 36
  • 37. Step 31 Type the command “exit” at the command prompt. 31a. On the prompt, enter the following commands: “ls -l”, “ls”. Try using the up and down cursor keys. Were you able to call the previous commands? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ 31b. Clear the command prompt, and then enter the command “history”. What happened? _________________________________________________________________________ ____________________________________________________________________________________________ 31c. On the prompt, type the command “touch testfile” and then enter the command “vi !*”. What happened? What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 31d. On the prompt, type the command “cat this_” then press the “tab” key. What happened? Did the shell complete the filename? Why do you think so? _________________________________________________________________________ ____________________________________________________________________________________________ 3.2.2. Shell Features “alias” Command An alias allows a way to give a different name or shorter name for a command. This allows a user to “personalize” some commands that are used often. Step 32 On the prompt, enter the command “alias ll=“ls-l“”. Again on the prompt, enter the command “ll”. 32a. What is the output of the command? What is the equivalent of the command? _________________________________________________________________________ ____________________________________________________________________________________________ 32b. What other command can you think of that you might need an alias? (Include the options for the command) _________________________________________________________________________ ____________________________________________________________________________________________ 32c. On the prompt, type the command “unalias ll”. Enter the command “ll” at the prompt. What happened? Where you able to show the listing of you directory? Why not? _________________________________________________________________________ ____________________________________________________________________________________________ 32d. What does the alias and “unalias“ command do? _________________________________________________________________________ ____________________________________________________________________________________________ 37
  • 38. “set” Command The set command allows setting and unsetting of flags that control shell-wide characteristics. There are a lot flags available on the Unix system. What will be presented are the useful ones. Step 33 At the prompt, enter the command “ls > list” and then enter the command “cat list”. 33a. At the prompt, enter the command “ls -l > list” and then enter the command “cat list”. Was the text file overwritten? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 33b. At the prompt, enter the command “set -o noclobber” and then enter the command “ls > list”. Were you allowed to overwrite the file? What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 33c. At the prompt, enter the command “set +o noclobber” and then enter the command “ls > list”. Were you allowed to overwrite the file? What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ Step 34 At the prompt, enter the command “set -o verbose” and then enter the command “ls -l”. 34a. What does the command do? _________________________________________________________________________ ____________________________________________________________________________________________ 34b. At the prompt, enter the command “set +o verbose” and then enter the command “ls -l”. Did it turned off the verbose mode? Why? _________________________________________________________________________ ____________________________________________________________________________________________ Command Sequencing Several commands can be executed in succession in the Unix system. By using the “;”, commands can be sequenced together. The Unix system is also able to do conditional sequencing. With conditional sequencing, a command will only be executed if the first one is successful or the next command will only be a executed if there was an error. Step 35 At the prompt, type the command “date; ls -l |more”. 35a. What did the command do? Did it execute two commands in succession? _________________________________________________________________________ ____________________________________________________________________________________________ 35b. At the command prompt, type the command “date; ls; pwd > out.txt”. View the text file using a text editor or “cat” command. What was on the “out.txt” file? (Describe) _________________________________________________________________________ ____________________________________________________________________________________________ 38
  • 39. 35c. At the command prompt, type the command “(date; ls; pwd) > out.txt”. View the text file using a text editor or “cat” command. What was on the “out.txt” file? (Describe) _________________________________________________________________________ ____________________________________________________________________________________________ 35d. Why were the output of the two previous command were different? What was the command? _________________________________________________________________________ ____________________________________________________________________________________________ Step 36 At the prompt, type the command “mkdir dir1” then enter the command “ls -d dir1 && echo ”Directory found” Notice that this is a conditional command. The “&&” specifies that the next command will be executed when the first command is successful. 36a. Did it execute the second command? _________________________________________________________________________ ____________________________________________________________________________________________ 36b. At the prompt, type the command “ls -ld dir3 && echo “Directory found“”. Did it execute the second command? Why? _________________________________________________________________________ ____________________________________________________________________________________________ Shell Variables Shell variables are store information required by processes so that processes can function properly. An example of a variable is how your command prompt looks like. The variable is called PS1. There are two types of shell variables: local and global (also known as environment variable). Local variables are variables that are available for the current shell session only while global variables are variables that are available to the current and all child or sub-shells that the user or the system might start Step 37 At the prompt, enter the command “my_name=“<your first name>“” and then enter the command “echo $my_name”. 37a. What was the output of the command? Were you able to create a variable? _________________________________________________________________________ ____________________________________________________________________________________________ 37b. At the prompt, enter the command “echo my_name”. Was the output same as before? Is the “$” sign needed to display the value of the variable? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 37c. What did you create? A local or global variable? _________________________________________________________________________ ____________________________________________________________________________________________ 39
  • 40. 37d. At the prompt, enter the command “bsh” and then enter the command “echo $my_name”. Were you able to see you name? _________________________________________________________________________ ____________________________________________________________________________________________ 37e. Without exiting the shell yet, type the command “my_name=“<your first name> <your last name>“” and enter the command “echo $my_name”. Were you able to see your name? Explain why you were not able to see your name earlier? _________________________________________________________________________ ____________________________________________________________________________________________ 37f. Exit the shell and enter the command “echo $my_name”. Was the output same as previous shell? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 37g. At the prompt, enter the command “export my_name” and then enter the command “bsh”. Display the variable “$my_name” by using the command “echo $my_name”. Is the output the same with the previous shell? Why? _________________________________________________________________________ ____________________________________________________________________________________________ 37h. What did you create? Local or global variable? _________________________________________________________________________ ____________________________________________________________________________________________ Step 38 At the command prompt, enter the command “PS1=”%”. 38a. What happened to the prompt? Did it changed? _________________________________________________________________________ ____________________________________________________________________________________________ Notice that PS1 is a shell variable. It was created by the operating system. In this case, the variable PS1 holds the text or command what the prompt should look like. 38b. At the prompt, enter the command “set |more”. What did it displayed? Were able to find PS1? _________________________________________________________________________ ____________________________________________________________________________________________ 38c. At the command prompt, enter the command “PS1=”[u@h W]$” ”. Did the command prompt go back to original state? _________________________________________________________________________ ____________________________________________________________________________________________ 40
  • 41. There are special characters that the shell can accept for the prompt setting. These settings are: 38d. Using the command “set |more”, find the shell variable for your log-in name. Is there shell variable for it? What is the name of the variable? _________________________________________________________________________ ____________________________________________________________________________________________ 38e. Using the command “set |more”, find the shell variable for your home directory. Is there shell variable for it? What is the name of the variable? _________________________________________________________________________ ____________________________________________________________________________________________ Initialization Files Initialization files or scripts can contain series of commands, settings and variables. Initialization files allows a user to personalize some settings. There are two types of initialization files: system wide and personal. The system wide initialization is set by the administrator and is the default initialization file. The personal initialization file resides in the user’s home directory and can be “personalized” by the user. In the bash shell, there are two initialization files, the “.bash_profile” and the “.bashrc”. The first initialization file can contain shell variable settings while the second initialization file contains alias settings. The “.bash_profile” can also contain other command that can be executed during the logging in. Step 39 At the prompt, enter the command “PS1=%”. Make sure that the prompt has changed and enter the “exit” command. 39a. Login to the server and check the prompt. Were you able to change the prompt? Did it go back to its original state? _________________________________________________________________________ ____________________________________________________________________________________________ 39b. Edit the “.bash_profile” using the vi text editor. At the end of the file, enter the text “PS1=“[u@h W]$“”. Save the text file and exit. Login to the server again and check the prompt. Did the prompt changed permanently? _________________________________________________________________________ ____________________________________________________________________________________________ Step 40 At the prompt, enter the command “alias ll=“ls “l“”. Enter the command “ll”. 40a. Were you able to see the effect of the alias? _________________________________________________________________________ ____________________________________________________________________________________________ 41