Introduction To Oracle Linux - Shell and Command Line
Introduction To Oracle Linux - Shell and Command Line
Learn
Note:
This tutorial is available in an Oracle-provided free lab environment. Introduction to Oracle Linux: Shell and
Command Line
It uses example values for Oracle Cloud Infrastructure credentials, tenancy,
and compartments. When completing your lab, substitute these values
Introduction
with ones specific to your cloud environment.
Objectives
Introduction
What Do You Need?
This lab explores introductory tasks for using Oracle Linux.
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and Monitor System Processes
other usage instructions.
Overview
1. If not already connected, open a terminal and connect via ssh to the ol-server system. More Learning Resources
1. Verify that the default shell, /bin/bash, is running, and use the echo command on Oracle
Linux to display the contents of the SHELL variable.
2. Make certain you’re in the user’s home directory using the tilde (~) metacharacter with the
cd command.
cd ~ Copy
3. Ensure the current number of command lines maintained by the history command.
HISTSIZE=20 Copy
5. Confirm that the command-line history for an open terminal window size is set to 20.
history 10 Copy
history -c Copy
10. View the cleared history using the history command again.
history Copy
pwd Copy
2. Display a long list of all the contents of the current working directory running ls command.
ls -la Copy
3. Display the file types in your current directory using the ls command.
ls -Fa Copy
4. If a temp directory doesn’t already exist, create a directory called temp using the mkdir
command.
cd temp Copy
pwd Copy
7. Display the files and directories under the root directory using the ls command.
ls / Copy
cd ~ Copy
cd .. Copy
10. Display the present working directory using the pwd command.
pwd Copy
cd - Copy
12. Create a new file called myfile using the echo and redirect commands.
13. Verify the new myfile file was created using the ls command.
ls Copy
14. Display the contents of the myfile file using the cat command.
15. Copy the myfile file to another file name using the cp command.
16. Display a long list of the contents of the current working directory using the ls command.
ls -l Copy
17. Display the myfile2 file type using the file command.
18. Display the file contents of myfile2 using the cat command.
19. Copy the myfile2 file to the temp directory using the cp command.
20. Display the contents of the temp directory using the ls command.
ls -l temp/ Copy
22. Display the file types in your current directory using the ls command.
ls -F Copy
23. Copy all files in the temp2 directory to a new directory, temp3, using cp command.
ls -R Copy
26. Create a new file called alpha using the touch command.
27. Display the contents of your current directory using the ls command.
ls Copy
rm alpha Copy
30. Display the file types in your current directory using the ls command.
ls -F Copy
31. Starting in your home directory, find all files named myfile using the find command.
32. Starting in your home directory, find all files named temp2 using the find command.
vim Copy
2. Press the i key to change into insert text mode and type the following text.
Hello World
What is your Copy
Use the h, j, k, l or arrow keys to navigate to the last character of the line.
Press the a key to append and insert a space with the next string name?.
Move the cursor to the third line by pressing the j or down arrow key. This will
move the cursor down.
To move the cursor to the left, press h or the left arrow key.
Place your cursor on the character a of the word Waht and execute the cw
command.
Enter the text hat. This will change the whole word Waht to what.
Execute the p command to paste the string. The whole line is copied and pasted.
Move the cursor to the beginning of the second line Hello World and execute
the dd command. The entire line is deleted.
Enter the text What and press Enter. The cursor automatically moves to the
first string in the file that it encounters. Notice that /What appears at the bottom
of the terminal window screen.
9. Search for the next occurrence of the same string by pressing the n key.
Enter the :set nu command and press Enter. Notice that :set nu appears
at the bottom of the terminal window screen.
11. Remove the line numbers.
Press Esc to enter command mode.
Type the :set nonu command and press Enter. The line numbers disappear.
1. Ensure you are in your home directory using the pwd command.
pwd Copy
ls -ld Copy
The owner of the existing directory is displayed in the third column of the output.
3. Identify the owner of the contents in the temp2 directory using the ls command.
ls -l temp2 Copy
sudo su
chown root temp2 Copy
ls -l Copy
6. Change the user and group ownership of its contents to root and root, by running the
chown command again with the recursive -R option.
exit Copy
8. Ensure that the umask value is set to 0022 on your system. To verify, run the umask
command.
umask Copy
9. If the umask is not set to 0022, then set the umask value to 0022 running the umask
command.
10. Create a new directory called perm in the temp3 directory using the mkdir command.
11. Change to the etc directory and list these four files – group, motd, shadow, fstab for
Oracle Linux using the ls command.
cd /etc
ls -l group motd shadow fstab Copy
12. Copy the four files to your ~/temp3/perm directory. The shadow file will fail to copy.
Example Output:
Copy
cp: cannot open ’shadow’ for reading: Permission denied
13. Go to your temp3 directory and verify the contents of its ~/temp3/perm directory.
cd ~/temp3
ls -l perm Copy
cd Copy
15. Create a new directory called test and a new file called test1.
mkdir test
touch test/test1 Copy
ls –l test/test1 Copy
18. Using the chmod command and symbolic mode, add write (w) permission for the group
permission set to the motd file.
Note: Symbolic mode uses a combination of letters and symbols to add or remove
permissions for each type of user.
19. Using octal mode, change the permissions on the motd file to -rwxrw----.
Octal mode is the use of values with a base 8, in this case 0-7.
20. Using octal mode, add write (w) permission for other on the file named group.
21. Identify the GID and UID for the motd file using the ls command.
ls -n temp3/perm/motd Copy
22. Create a new directory called notes using the mkdir command.
touch notes/memo
ls -l notes/memo Copy
24. Remove the read (r) permission for the owner from the memo file in the notes directory.
You can use symbolic mode to do this.
Note: This fails because read permission has been removed from the user. Even
though you are part of the group, the permissions are viewed in the order in which
they appear.
1. Use the following ps command to list the processes currently running on your system.
ps Copy
ps -f Copy
3. Use the –e option to print information about every process running. Then use the ps and
wc commands to show the total number of processes.
ps -e
ps -e | wc -l Copy
ps -f Copy
Note: Observe the TTY column where the controlling terminal is pts/0.
5. Open a second terminal window and connect via ssh to the ol-server system.
ps -f Copy
Note: Observe the TTY column in the second terminal window, where the controlling
terminal is pts/1. This is because you now have two separate and concurrent terminal
window sessions open at the same time.
8. In the second terminal window, use the ps and grep commands to identify the PID of the
sleep process.
The PID can be found under the second column of the output.
9. From the second terminal window, use the kill command with the PID argument to
terminate the sleep process.
This example uses a PID of 29987.
10. In the second terminal window, enter the tty command to identify the name of this
terminal window. The name appears as /dev/pts/, where n is a number (for example,
/dev/pts/1).
tty Copy
11. Return to your first terminal window. Use the pgrep -t (terminal option) command to find
the PID associated with the second terminal window.
12. In your first terminal window, use the kill command to terminate the ssh session and log
off the ol-server system in your second terminal window.
This example uses a PID of 29957.
Notice you are logged off the ol-server system in the second terminal window
13. Run the following kill -l (list option) commands to identify the signal names and signal
values.
kill -l 9
kill -l kill Copy
kill -l 15
kill -l term
Note: signal value 9, the signal name is KILL, and for the signal name kill, the signal
value is 9. For signal value 15, the signal name is TERM, and for the signal name term,
the signal value is 15.
14. In the terminal window, enter the sleep command and place it in the background.
15. Use the ps command to identify the bash shell process running in that window.
ps Copy
16. In the second terminal connect via ssh to the ol-server system.
17. In the second terminal window, display the process tree and provide the PID of the sleep
process running in the first terminal window as an argument, using the pstree -p <PID>
command.
This example uses a PID of 1252.
18. In the second terminal window, terminate the first terminal window using the kill
command with the bash shell PID.
19. In the first terminal window, enter the ps command and notice that the sleep 600
process was killed.
ps Copy
Content on Oracle Help Center Learn is published for your convenience. It is not part of the Product
Documentation for any Oracle product or service.
© Oracle About Oracle Contact Us Products A-Z Terms of Use & Privacy Cookie Preferences Ad Choices