Base Linux 1
Base Linux 1
Base Linux 1
1.1 Welcome
1.2 Menu
Notes:
Intended for Internal Service for reference purposes only.
2. Introduction to Linux
Notes:
Notes:
Was Initially written in 1991 by Linus Torvalds. Linux was created from ground up as an
open source operating system. Being Linux is Open source, that allowed various groups
to create their own versions. Linux is not another type or flavor of UNIX. Although it does
share a good deal of UNIX files and command structure. Many of the commands that we
will be learning are applicable in a UNIX (Solaris) environment.
Notes:
When we use the term “Open Source” what does that REALLY mean? In most cases, it
means you can view the source code but you are not free to modify.
Also, In most cases, Open Source does NOT mean free.
- You have to pay up front in some manner
- Pay for Service Contract
- and Usually its’ free for personal, non commercial use
Notes:
We had mentioned there are different flavors of Linux, much in the same way there are
different flavors or versions of UNIX
The different vendors had different goals in mind with their versions:
- Red Hat offers Enterprise Support
- and Trustix is very secure
Notes:
As noted, Linux is NOT another flavor of UNIX. However, as indicated throughout this
course, most of the commands and tools you will learn to use will work in a Solaris
environment just as well as they do in a Linux environment. As we’ll see, there are far
more similarities than differences. As of Enterprise Imaging 8.1, Enterprise Imaging
Database servers can run on Oracle Enterprise Linux 6.8 (OEL 6.8) which is the
Operating System of choice. OEL 6.8 is the latest release of distribution's legacy branch
based on Red Hat Enterprise Linux 6.8. OEL is an enterprise-class Linux distribution
supported by Oracle and is fully compatible with Red Hat Enterprise Linux.
3. Navigation in Linux OS
Notes:
Notes:
Putty is the tool we’ll most often use to interface with Linux Servers. Putty is a
free, downloadable terminal emulation program used to navigate from pc to Linux
server. It supports several network protocols, including SCP, SSH, Telnet, rlogin,
and raw socket connection. We’ll make use of a SSH connection. As we can see,
we have the putty icon on our desktop. Double clicking the putty icon will open up
the Putty configuration page. We can enter either the Host Name (if we have
DNS enabled locally ) or the IP address of the server we want to navigate to. We
want to be sure that we have chosen SSH as the Connection Type. We also
have the option to define the IP and “Save” the entry for ease of use. We’ll
access the entry for my database server below….highlight the entry, click load
and then click open. That opens a terminal screen on the Linux server in
question. And you see that we’ve logged into our server. That’s how we use putty
as a means of accessing either a Linux or Solaris server
Notes:
Which user you are currently logged in as ( root or oracle ) will be directly expressed
through the type of symbol that accompanies command line prompt.
Users current present working directory will also be incorporated into prompt.
- Logged in as root - # sign.
- Logged in as any other user - $ sign.
Tildy is indicative of a users home directory - Both cases we see the tildy in the prompt
which indicates the users home directory. In the screen capture, via the command
whoami, we see that we are currently logged in as root. And as noted, the prompt is
denoted with a # sign, signifying root user. We can switch user to the oracle user: su -
oracle (more on that later). Once again use the whoami to verify the current user -
oracle. And we see as noted earlier that the prompt is a $ sign rather than a # sign. This
is very significant due to the fact that when you are logged in a root user, you have
complete access and control of the system. Mistakes made as root user can result in
serious loss of data. Golden Rule # 1 - Never su to root unless you absolutely
need to be root
Notes:
Here is a generic look at the Linux file structure. Linux file system starts with /,
the root directory. All other directories are 'children' of this directory.
Critical second level directories include, but are not limited to:
/bin /etc /usr /var /sbin /dev /tmp /lib /boot and /opt
Hover over the purple directories for it’s definition.
Notes:
Root user account is comparable to the administrator user in Windows. Once logged into
a server as root, you have complete access.
Root Home Directory (/root)
Intended for Internal Service for reference purposes only.
Notes:
cd (change directory) is a command that is used to change from our current directory to
another directory.
Please click on the cd's syntax to find out . Items in square brackets are optional.
- cd .. This command brings you back one directory
- cd ~ This command returns user to home directory
Notes:
When you log into a Linux server with a specific login, you're placed in a directory called
the home directory for that specific user. Every user within Linux has a home directory.
So no matter where you are in the file structure, by typing: cd ~ or cd. This will bring you
back to home directory of your current user. The symbol ~ (Tildy) is indicative of the
users home directory.
As noted the command pwd (present working directory) reflects our current location the
directory structure. Upon login, we are located in the home directory of the user that we
logged in with. In this case it’s the root directory. This is denoted by the location, but
also by the tildy (~) symbol in the prompt
Notes:
The pwd Command returns your working directory (sometimes called your current
working directory or present working directory). Pwd is the directory you're currently
working in. At the start of every session, your home directory is your working directory.
You may change to another directory, in which case the directory you move to becomes
your present working directory.
As noted the command pwd (present working directory) reflects our current location the
directory structure. Upon login, we are located in the home directory of the user that we
logged in with. In this case it’s roots home directory.
When we type cd / , we navigate from root’s home directory to the base of the Linux file
system. We can see the actual root directory when we type pwd and we can also see
that reflected in the prompt.
As we noted earlier the cd command stands for change directory. When we type cd
/etc/opt - we navigate to the /etc/opt directory. As we talked about earlier….typing cd ..
Will bring me back one directory. And as we mentioned as well…..when we type cd by
itself (or cd ~) that will bring us back to that users home directory.
Notes:
An absolute pathname defines a path of directories to get from root to the directory or
file you want. When specifying an absolute path, we begin the path name with a slash
(/). Signifying that you will start from the root directory
A relative pathname gives a location relative to your present working directory. Unless
you use an absolute pathname (starting with a slash), Linux assumes that you're using a
relative pathname. Like absolute pathnames, relative pathnames can go through more
than one directory level by naming directories along the path.
One of the more critical components to navigating through a Linux or Solaris file
structure is understanding the difference between using an absolute pathname vs a
relative path name.
As we noted before, / is indicative of the root directory, so when we include a slash in
our navigation path, we are starting from root and working our way down the directory
structure.
So in this example, I need to move to /etc/opt directory. We type: cd /etc/opt and
that would get us to the correct location.
However if I’m already in /etc and easier way, with slightly less typing would be to use
the relative path to opt. With the term meaning navigation is relative to my current or
pwd. We’ve seen that cd .. command will take me back one directory. So we can type
cd opt and navigate to /etc/opt via a relative path.
A fairly common mistake that people new to Linux or Solaris make is including the /
when its not wanted or needed. As we see, if I include a / preceding opt, that would take
you to a completely different directory. To recap. When using an Absolute path, I begin
Intended for Internal Service for reference purposes only.
Notes:
When we use su, telnet, ssh or do a variety of commands, we fork to a new shell. A fork
in a multithreading environment means that a thread of execution is duplicated, creating
a child thread from the parent thread. A bit like stepping through a door, we have the
ability to back out gracefully by typing exit.
Using the whoami command, we see that we are currently logged in as root. Using the
su - oracle command, we switch users from root to oracle. But we also “Fork” to another
thread. When we type exit, we exit the current thread and step back to our original
terminal window. We see we’re back at user root, without having to switch users.
Notes:
Windows does not discriminate between upper and lower case. The only exception is
passwords. Linux was created by and for computer experts. In Linux, upper and lower
case makes a huge difference. Each ASCI character is a separate entity. Usernames,
passwords, file names and folder/directory names are case sensitive. Please see the
slide for the different variations.
Notes:
A man page (short for manual page) is a form of online software documentation usually
found on a Unix or Linux operating system.
Topics covered include computer programs, specific commands and their associated
arguments.
You type man space the command in question. In this example it's the command ping
Notes:
Here are is a command summary for navigating in Linux OS. Click on the commands to
obtain a full description.
Notes:
Notes:
Typing ls -l will provide long format output, please click on each listing to get the full
description:
Notes:
(first images goes here) Shown on this slide are 12 common uses and variations
of the ls or list commands.
***Running the command ls will give us a simple listing of the names of the files and
sub-directories in the current directory.
Running the command ls -l will provide us with a long listing of the files and sub-
directories in the current directory.
The initial letter or symbol denotes the type of entity it is, usually a dash for a file or a d
for directory.
The next 9 letters denotes the permission set for the file or directory.
R for read permissions, W - for write permissions and X - for executable permissions.
We’ll be diving deeper into permissions shortly. This denotes the owner of the directory
Intended for Internal Service for reference purposes only.
This denotes the group that has been granted permissions to the directory or file.
We see the last date and time the file or directory was modified. We see the name of the
directory (or file).
Notes:
Notes:
Notes:
Notes:
Notes:
The cat command will dump the entire file to the screen. The command is useful if you
are viewing a smaller file, or you want to use the output from a file. The more command
allows us to view a file and then page through if the output is too large for the screen. To
exit the screen type q to quit. The more command also allows us to search through the
file for a particular word or string of characters. We initiate the search via a forward slash
followed immediately by the string we are looking for. The less command works pretty
much the same way as the more command. The major advantage is that when we
initiate search, the search will actually highlight each time the search string is found. We
had initiated the search the same way we did with the more command, but with the less
command, each entry we search for is highlighted. The head command shows me (by
default) the 1st ten lines of a file. I can specify the number of lines to see. Conversely, the
tail command will show me the last lines in a file. Very useful for checking on the
successful completion of a command, say database backup.
Notes:
The top command provides an ongoing look at processor activity in real time. It
displays a listing of most CPU-intensive tasks on the system and can provide an
interactive interface for manipulating processes. The top command sorts the tasks by
CPU , memory and runtime usage.
Notes:
The df space dash h command reports the number of free disk blocks and inodes
available on all mounted file systems or on the given name. Besides the options listed,
there are additional options specific to different file system types or df Chapters.
du -h
The du command reports the sizes of directory trees including all of their contents and
the sizes of individual files. This command is very useful when tracking down space
hogs
Notes:
lsblk command displays a list of available block devices. Here are a few displays of the
ls block command, hover over them to see the block devices.
Notes:
Df -h shows you all of the currently mounted file systems, their size, amount of space
used, amount of space available, percentage of used space as well as the mount point
for the file system. Once you identified a file system that may be hogging space, you can
use du -h to further identify which directory in the file system may be the culprit. ls block
command gives you a different perspective on the current disk space usage.
Notes:
Here is a command summary for Listing and viewing a file. Click on the commands to
obtain a full description.
5. Critical Files
Notes:
Notes:
As your machine gets started, it will need to know the mapping of some hostnames to IP
addresses before DNS can be referenced. This mapping is kept in the /etc/hosts file. In
the absence of a name server, any network program on your system consults this file to
determine the IP address that corresponds to a host name. IP to host name translation.
Notes:
Notes:
Notes:
/var/log/yum.log contains information that are logged when a package is installed using
yum.
/var/log/cron Whenever a job, kicked off in cron runs it logs the information about that
cron job in this file.
/var/log/sssd is used by system security services daemon that manage access to
remote directories and authentication mechanisms.
Notes:
Linux shell programs interprets user commands: Entered by a user or read from
a file. Main task of a shell is providing a user environment, which can be
configured individually using shell resource configuration files. There are various
types of shells, with the Bash Shell being the most user friendly and flexible. To
determine the current shell, type: echo $SHELL. We see that the default shell is
bash shell.
Notes:
Typing the word history will return a list of the previously run commands. Use the up
and down arrow key's to scroll through previously typed commands. Press [Enter] to
execute them or use the left and right arrow keys to edit the command first.
Notes:
Tab Completion
Use Using the TAB key and bash will attempt to complete the command for you
automatically. It can be used to complete command (tool) names. Can also use
it when working with the file-system, changing directories, copying files, etc.
Notes:
The alias command will list your current aliases. An alias command allows one
command to be substituted for another. It’s used to make a command do something
else or to automatically add certain options. This command can be run during one
session using alias command or information can be added to .bashrc file. The .bashrc
file is found in users home directory.
Notes:
When you start a program in Linux a new process is created. The process runs within
what is called an environment. That environment has certain characteristics which the
program/process interacts with. Every program runs in its own environment.
Environment parameters can be set so that the running program can find the desired
values when it runs. Environmental variables contain certain settings that various shells
can use. Variables are defined for current shell and are inherited by any child shells or
processes. They are used to pass information into processes that are spawned from the
shell.
All current environmental variables and their values can be seen by running the env
command without any options or commands. Permanent variables are defined within the
./bashrc file.
Notes:
PATH is an Environmental variable that tells shell which directories to search for
executable files in response to commands issued by a user.
The command to display the path variable is echo $PATH.
SHELL defines the default shell for the current environment. The command for SHELL
is: echo $SHELL.
PS1 defines a shell prompt. By default, bash shell prompt is ' $ ‘. The command for
PS1 is: echo $PS1.
Notes:
Here are is a command summary for the Critical File Summary. Click on the commands
to obtain a full description.
6. File Permissions
Notes:
6.2 Permissions
Notes:
Notes:
Notes:
The chmod <permissions> <file name> command changes current permission set of a
file or directory. Particular care should be taken when a directory is the target because
the effect is not intuitive. In addition, it will not work on all file types. For example, it has
no effect on a symbolic link. chmod <permissions> followed by the <file name> Here
is an example $ chmod 744 myfile.
We build a directory within /root named jim.
Via an ls -l command we see that it is:
- a directory with the default permission set of rwxr-xr-x
- read, write and execute for the owner and read and execute for the group and
everyone else
- We associate a value to the letter representation of the permission set in the following
way
- From a binary perspective, we define a numeric value to the place in the order rwx
- Giving the right to read (R) = 4
- Giving the right to Write (W) = 2
- Giving the right to execute (X) = 1
So we can define a numeric value for each “section”. Owner, Group, Other.
Via the chmod 777 jim command, we change the permission set of the jim directory to
777. Read write and execute for everyone.
Via the chown (change own) command, we change the owner from root to oracle. Not
that you would have to be currently logged in as root to affect that change.
Notes:
The $ chown <new owner> <file name> command changes current owner of a file or
directory.
The $ chgrp <new group> <file name> command changes current group of a file or
directory.
Notes:
find the path name followed by a particular condition is a very useful command for
finding particular files. find works it’s way down the directory structure and locates files
that meet specified conditions. At least one pathname and one condition must be
specified. Most common conditions include -name and -type . Here are Some
Examples . In the example we are looking for the location of the control files. We’re
starting the search from root, searching by name. Using the star as a wild card in
conjunction with the suffix .ctl . The find command is a very powerful search tool. See
the man pages for all of the search options we can use with find.
Notes:
SUDO means Super User Do. Similar to Run as Administrator in Windows. It allows
various commands to be run with root privilege with having to actually become the root
user. hover over to see what The command is. The SUDO command allows the user to
restart the networking service (which is owned by root) without having to switch to the
root user.
Notes:
Switch users (su) via the command su -. We pick up certain environmental elements
when we include a dash ( - ).
The command, su - oracle, will allow you to switch to oracle user. su - without a
designated user defaults to root user.
As we saw earlier in the course…..the whoami command returns to the current user.
Su - oracle allows us to switch users to oracle.
Notes:
grep (globally search a regular expression & print) is a command line utility for
searching plain-text data sets for lines matching a regular expression. Search pattern
specified as an argument is case sensitive by default. Output can be viewed on the
screen or sent to a file. As you can see In this example, we are searching through the
daily incremental (L1) backup log file to confirm that the backup did successfully
complete. We had initially navigated to the location of the log file. Using the cat
command, we pipe (|) or push the output of the cat command to the grep command
The grep command reads through the entire messages file looking for lines with the
word complete. The -i makes the search case sensitive. In this example we then take the
output of the grep -i gets redirected to an output file we named backups. That output file
gets built dynamically in the local directory as long as you have permission to write in
that location.
Notes:
cp [options] file1 file2 and cp [options] files directory. The cp command allows for a
copy of one file to another, for renaming. It also allows us to copy one or more files to
the same names under a specified directory. If destination is an existing file, the file is
overwritten. If destination is an existing directory, the file is copied into the specified
directory. Copy leaves the existing file in place. The Golden rule of editing critical
system files is that you always make a copy of that file PRIOR to making changes to that
file so that you can roll back to the original if needed. In this example, we made a copy of
the hosts table and stored it in /etc. We could have easily changed the storage location
of the file via the destination location. Once again keep in mind you have to have the
proper permissions to copy a file into the target directory. When logged in as root, you
have that permission.
Notes:
Options
-i Prompt for confirmation (y for yes) before overwriting an existing file.
-p Preserve the modification time and permission modes for the copied file. (Normally
cp supplies the permissions of the invoking user.)
-r Allows you to copy recursively.
Hover over to see the example of the command for options. ALWAYS copy critical
system files BEFORE you edit them.
Notes:
Notes:
rm <file name>
rm command deletes files or directories from file system. Deleting a file normally
requires write permission on parent directory. rm will not delete a directory structure that
is not empty. Hover over to see the example of the rm command
-f:(dash f) Forcefully removes file.
-r: (dash r) will Remove the contents of directories recursively.
Running the rm -r (rm dash r) (recursive) option is very powerful and potentially
dangerous. It will recursively delete the current directory and ALL child files and
directories.
Notes:
Flags can be set to force a check, but by default, Linux assumes that you KNOW what
you are deleting. There is no trash bin in Linux or Solaris.
Notes:
Hare a some rules we’ve discussed in this course, please be aware that there are a
few new ones.
- Never login as root unless you have to
- After doing what you need to do as root, change back to your user
- Research commands before using them
- rm -r (rm space dash r) from the root will delete everything
- Before rebooting, make sure you are on the server you want to reboot
- Backup any configuration file before editing
Notes:
Here are is a command summary for File Permissions. Click on the commands to obtain
a full description.
Notes:
In the creating and Editing Files section we will discuss the following:
- Touch
- Introduction to VI
- Setting Environment in Putty
- Creating & Editing Files With VI
- Working in Command Mode
- Working in Insert Mode
- Changing Text
- Deleting Text
- Cutting & Pasting text
- and Saving & Quitting a File
Notes:
Notes:
vi <file name> is Short for visual editor which is a Text / file editing tool. vi is the default
editor in Linux.
There are two primary modes in vi:
- The command mode, allows the user to issue commands.
- and the insert mode, we can enter text while in insert mode.
Notes:
Notes:
$ vi <filename> is to Create or edit a file. New filename must be unique inside its
directory.
Filenames can consist of any combination of:
- Uppercase and lowercase letters
- Numbers
- Characters dot (.) & underscore (_)
Remember that Linux is case-sensitive. Lowercase letters are distinct from uppercase
letters.
There is no easy way to get comfortable using the vi editor other than practice. As we’ll
see there are a few tricks and tips that we can use to ease the pain that is vi. But as
noted, you have to work with it to get better. There are numerous on line cheat sheets
and as well as tutorials available online.
Notes:
As stated, our two modes are the command mode and insert mode. Navigate in the file
while in command mode.
We can also issue file editing commands while in command mode. We normally start
out in command mode, where every keystroke represents a command. If we wanted to
move from line 1 to line 25, then edit a word on line 25, we would complete the
navigation while in command mode, then switch to insert mode to actually complete the
edit. Hitting the Esc key well bring you back into command mode.
Using vi can initially be a great source of frustration. One of the VERY nice things about
this version of Linux, that you will NOT find in Solaris is that once you have moved into
insert mode, that is reflected on your screen. It may seem like a small thing but it’s huge
when looking to determine if you are currently in command mode or insert mode. Hitting
the Esc key will bring you out of Insert mode back to Command mode.
To save your edits and exit the vi session enter the following: Esc:wq!
Just as valuable as knowing how to save is understanding that if you really mess up a
file during a vi session, you can ALWAYS quit out and start again. Enter the following:
Esc:q!
Notes:
For Insert mode Everything you type becomes text in your file.
There are certain characters that will “put” you into insert mode:
- Inserting or Adding text
- Break out of insert mode by hitting the <Esc> key
Click on the commands to obtain a full description.
Notes:
Here is a command summary for Changing Text in Command Mode. Click on the
commands to obtain a full description.
Notes:
Here are is a command summary for Cutting and Pasting Text. Click on the commands
to obtain a full description.
Notes:
Notes:
We can copy & paste from Notepad or Word into a vi editing session. However, many of
our edits do not require extensive typing. Ability to effectively use vi can be a time
saving tool. There will be situations where we will NOT be able to copy and paste. So a
rudimentary understanding of vi is an essential tool in our technical skills tool belt.
We have initiated a vi session on the file backups. Initially, we are in command
mode. In this case, by typing a lower case letter o, that will drop me down to a fresh line
and put my vi session into insert mode. As noted, we can use to insert or edit our text,
then copy & paste that into our vi session. However some vi enthusiasts would consider
that cheating.
Notes:
Here are is a command summary for creating and editing files. Click on the commands
to obtain a full description.
Notes:
This concludes the training. Please close this window to return to the course description
page in ALP. Once there, don't forget to confirm your participation by clicking the "here"
icon. This enables the ALP to set the training to complete. You can now exit this training
and complete the course appraisal. Thank you for completing this course.
9. Author