Nothing Special   »   [go: up one dir, main page]

3-Linux Basics For A DB Administrator

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Welcome to Section 3

Linux Basics for a DB Administrator

By: Imran Afzal


www.utclisolutions.com
Important Things to Remember in Linux
• Linux has super-user account called root
• root is the most powerful account that can create, modify, delete
accounts and make changes to system configuration files
• Linux is case-sensitive system
• ABC is NOT same as abc
• Avoid using spaces when creating files and directories
• Linux kernel is not an operating system. It is a small software within Linux
operating system that takes commands from users and pass them to system
hardware or peripherals
• Linux is mostly CLI not GUI
• Linux is very flexible as compared to other operating systems.

By: Imran Afzal


www.utclisolutions.com
What is Root?
• There are 3 types of root on Linux system
1. root account: root is an account or a username on Linux machine and it is the
most powerful account which has access to all commands and files

2. root as /: the very first directory in Linux is also referred as root directory

3. root home directory: the root user account also has a directory located in /root
which is called root home directory

By: Imran Afzal


www.utclisolutions.com
Directory Listing Attributes
Total columns = 9

Type # of Links Owner Group Size Month Day Time Name

drwxr-xr-x. 21 root root 4096 Feb 27 13:33 var

lrwxrwxrwx. 1 root root 7 Feb 27 13:15 bin

-rw-r—r-- 1 root root 0 Mar 2 11:15 testfile

The second column is the number of hard links to the file. For a
directory, the number of hard links is the number of immediate
subdirectories it has plus its parent directory and itself

By: Imran Afzal


www.utclisolutions.com
Creating Files and Directories
• Creating Files
touch
cp
vi

• Creating Directories
mkdir

By: Imran Afzal


Changing Password

• You should change your initial password as soon as you login

Command = passwd userid


Old password: - enter your current password
New password: - enter your new password
Retype new password: - re-enter your new password

By: Imran Afzal


Commands Syntax
• Command options and arguments

Commands typically have the syntax:


command option(s) argument(s)

Options:
Modify the way that a command works
Usually consist of a hyphen or dash followed by a single letter
Some commands accept multiple options which can usually be grouped together after a single hyphen

Arguments:
Most commands are used together with one or more arguments
Some commands assume a default argument if none is supplied
Arguments are optional for some commands and required by others
File Permissions
• UNIX is a multi-user system. Every file and directory in your account can be protected from or made
accessible to other users by changing its access permissions. Every user has responsibility for
controlling access to their files.

• Permissions for a file or directory may be restricted to by types


• There are 3 type of permissions
• r - read
• w - write
• x - exeawke = running a program

• Each permission (rwx) can be controlled at three levels:


• u - user = yourself
• g - group = can be people in the same project
• o - other = everyone on the system

• File or Directory permission can be displayed by running ls –l command


• -rwxrwxrwx

• Command to change permission


• chmod
Help Commands

• There are 3 types of help commands

• whatis command
• command –-help
• man command
Adding Text to Files (Redirects)

• 3 Simple ways to add text to a file


• vi
• Redirect command output > or >>
• echo > or >>

By: Imran Afzal


Pipes
• A pipe is used by the shell to connect the output of one command directly to the input
of another command.

The symbol for a pipe is the vertical bar ( | ). The command syntax is:

command1 [arguments] | command2 [arguments]


Pipes

ls -l | more
File Maintenance Commands

• cp
• rm
• mv
• mkdir
• rmdir or rm -r
• chgrp
• chown
File Display Commands

• cat
• more
• less
• head
• tail
Linux File Editor
• A text editor is a program which enables you to create and manipulate data
(text) in a Linux file

• There are several standard text editors available on most Linux systems
• vi - Visual editor
• ed - Standard line editor
• ex - Extended line editor
• emacs - A full screen editor
• pico - Beginner’s editor
• vim - Advance version of vi

• Our editor = vi (available in almost every Linux distribution)


Introduction to vi Editor

• vi supplies commands for:


• Inserting and deleting text
• Replacing text
• Moving around the file
• Finding and substituting strings
• Cutting and pasting text

• Most common keys:


• i – insert
• Esc – Escape out of any mode
• r – replace
• d – delete
• :q! – quit without saving
• :wq! – quit and save
User Account Management
Commands
• useradd
• groupadd
• userdel
• groupdel
• usermod

Files
• /etc/passwd
• /etc/group
• /etc/shadow

Example:
useradd –g superheros –s /bin/bash –c “user description” –m –d
/home/spiderman spiderman
Switch Users and sudo Access
Commands
• su – username
• sudo command
• visudo

File
• /etc/sudoers
“ps” command
• ps command stands for process status and it displays all the currently running processes in the
Linux system

Usage examples:
• ps = Shows the processes of the current shell

PID = the unique process ID


TTY = terminal type that the user logged-in to
TIME = amount of CPU in minutes and seconds that the process has been running
CMD = name of the command

• ps –e = Shows all running processes


• ps aux = Shows all running processes in BSD format
• ps –ef = Shows all running processes in full format listing (Most commonly used)
• ps –u username = Shows all processes by username.

By: Imran Afzal


www.utclisolutions.com
“top” command
• top command is used to show the Linux processes and it provides a real-time view of the running system
• This command shows the summary information of the system and the list of processes or threads which
are currently managed by the Linux Kernel
• When the top command is executed then it goes into interactive mode and you can exit out by hitting q

• Usage: top

PID: Shows task’s unique process id


USER: Username of owner of task
PR: The “PR” field shows the scheduling priority of the process from the perspective of the kernel
NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
VIRT: Total virtual memory used by the task
RES: Memory consumed by the process in RAM
SHR: Represents the amount of shared memory used by a task
S: This field shows the process state in the single-letter form
%CPU: Represents the CPU usage
%MEM: Shows the Memory usage of task
TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.

By: Imran Afzal


www.utclisolutions.com
“top” command
• top –u iafzal = shows tasks/processes by user owned
• top then press c = shows commands absolute path
• top then press k = kill a process by PID within top session
• top then M and P = To sort all Linux running processes by Memory usage

Please note:
Top command refreshes the information every 3 seconds

By: Imran Afzal


www.utclisolutions.com
“crontab” command
• Crontab command is used to schedule tasks

Usage:
o crontab –e = Edit the crontab
o crontab –l = List the crontab entries
o crontab –r = Remove the crontab
o crond = crontab daemon/service that manages scheduling
o systemctl status crond = To manage the crond service

o Create crontab entry by scheduling a task:


crontab –e
schedule, echo “This is my first crontab entry” > crontab-entry By: Imran Afzal
www.utclisolutions.com
Network Files and Commands
• Interface Detection
• Assigning an IP address
• Interface configuration files
• /etc/nsswitch.conf
• /etc/hostname
• /etc/sysconfig/network
• /etc/sysconfig/network-scripts/ifcfg-nic
• /etc/resolv.conf

• Network Commands
• ping
• ifconfig
• ifup or ifdown
• netstat
• tcpdump

By: Imran Afzal


SCP – Secure Copy Protocol
• The Secure Copy Protocol or “SCP” helps to transfer computer files
securely from a local to a remote host. It is somewhat similar to the
File Transfer Protocol “FTP”, but it adds security and authentication

• Protocol = Set of rules used by computers to communicate

• Default SCP Port = 22 (same as SSH)

• For this lecture we need 2 Linux machines


• Client = MyFirstLinuxVM
• Server = LinuxCentOS7

By: Imran Afzal


SCP – Secure Copy

Client = A Server = B
ssh
scp

sshd = 22

By: Imran Afzal


SCP – Secure Copy
• SCP commands to transfer file to the remote server:

• Login as yourself (iafzal)


• touch jack
• scp jack iafzal@192.168.1.x:/home/iafzal
• Enter username and password

By: Imran Afzal


System Updates and Repos

• yum (CentOS), apt-get (other Linux)


• rpm (Redhat Package Manager)

By: Imran Afzal

You might also like