Вы находитесь на странице: 1из 66

Linux Introduction

Introduction to Linux
- Created by Linus Torvalds in response to his frustrations
with MINIX licensing
- First release was on October 5 1991
- Designed to be an open source, free, and easy to use
(somewhat)
- Distro, Shell, Root & Capitalization.
Linux Introduction
 1: Navigation

 2: Ownership, Privileges, Change/Modify.

 3: Search, Find, Grep

 4: Make, Move, Copy, Remove

 5: Network Basics

 6: Additional Linux Process Details


Navigation:
Command line_
 All commands follow the same general form
Command <Arguments> <Arguments>

 It’s easy to pipe the output of a command into the input of another
Example: ls | more
ls : List files
 General form: ls <argument><argument>

 Common arguments:
 List hidden directories: - a
 List permissions (or long list): - l
 Human readable format: -h
(Usually combined with –l)
cd : Change Directory
 Common usage: cd <directory name>
Relative path names
 Relative to where you currently are
 Example: cd ..

Absolute path names


Example: cd /var/log
Pwd : Where am I?
Displays current directory

 Returns the directory that you are currently in


History : What have I done?
Displays previously typed commands

 General form: history <number of lines to display>


Man: Manual pages
Help pages for various Linux commands

 Complete documentation for almost all Linux commands


Usage:
Directory Structure

• Important folders
• /var/log - This is where all Avaya logs are located
• /home – Location of home folder
• /tmp – Temporary folder that can be used to move
files
• /etc – System configuration
Clear : Clears the screen
Clears the screen

 Usage: clear
VI:
I insert

a append Displays the contents of a file


A Append at the end of the line
 By performing vi on a file we can see
d delete +arrow key

dd delete the line (2dd delete 2 lines) the contents and modify them

x cut
 IE: vi test
yw Yank pulls highlight word  You can use the legend to move around in
Y Yank line these files.
:q! Quit

:wq! Save and Quit

:w Write file
Lab 1 : Navigation
2: Ownership, Privileges,
Change, Modify.
File permissions

https://www.ics.uci.edu/computing/linux/file-security.php
Chown: Change ownership of file/dir

Description: This command allows you to change the owner of a file or directory.
 -R is Recursive and will change the ownership of all subsequent files in the directory
 Allows you to change the group as well

Example: chown student filename


chown –R student file*
chown student.group filename
Chgrp: Change group ownership
This command allows you to change the group name of a file or directory
 Can be used recursively
 Example: chgrp studentgroup myfile
chgrp –R studentgroup file*
Cp: Copy
Copies files from one location to another

 General form: cp <name of file> <location>


 Example: cp /etc/passwd /tmp
Lab 2 : Ownership,
Privileges, Change, Modify.
3: Cat, Search, Find, Grep,
Cat : Displays contents of file
Displays the contents of a file to the screen.

 Useful options:
 Enable line numbers: -n
 Number nonempty output lines –b
Tac: Display contents of file in reverse
Displays the contents of a file with the newest events displayed first

 Same as cat, except items are displayed in reverse order


More: Page breaks
Allows you to display large amounts of text one page at a time.

 Arguments:
 <filename> Example: more <filename>
 / Search the text for a specific string
 SPACE Advance to the next page
Can be called directly or data can be ‘piped to it’
Less : Page breaks (with navigation)
Less allows you to filter through large amounts of text with the added bonus of
being able to use arrow keys.

 Allows for page up/page down functionality


 Entire file must be loaded into memory, which can cause
significant delays
 If the file is too large, less will not display the text
Usage:
Tail: Output the last part of files
Allows you to view the last ‘x’ number of lines in the file.

 One of the most useful Linux commands


 Follow output with the –f parameter
Usage:
-f Follow – Displays the last 10 lines of a file, and pauses until new
input arrives.
-n Output the last X lines.
-c Output the last X number of bytes
Head : Display the first parts of a file
Displays the first ‘x’ number of lines of a file

 Similar functionality to the tail command


Usage:
-c Print the first ‘x’ bytes of a file
-n Print the first ‘x’ number of lines in a file
Grep: The Swiss army knife of searching
Allows you to search through large amounts of text for specific strings.
 Regular Expressions (pattern matching)
 Search for specific strings
 Allows you to display contents above and below the matched line
Usage:
-A <NUM> - Print number of lines AFTER matched line
-B <NUM> - Print number of lines BEFORE matched line
-v - Invert match (Display all context except for matched line)
Find: Search for files
Description: search for files in a directory hierarchy
 Extremely versatile
 Typical argument (use “man find” for more information):
 -name Search for a filename
Example: find / -name "dir-name-here"
Locate: find files by name
Description: locate reads one or more databases prepared by updatedb and
writes file names matching at least one of the PATTERNs to standard output
 Much quicker than using the find command
 Caveat: updatedb must be ran before results will be returned

 Example: locate passwd

 This is not native to Avaya Linux installs


Lab 3 : Search, Find, Grep,
4: Make , Move, Copy,
Remove
Making a Txt File:

 Cat > sample.txt


 > sample.txt
 touch sample.txt
Mkdir: Make Directory
Creates a directory

 General form: mkdir <name>


Mv: Move
Moves files from one location to another.

 General form: mv <filename> <location>


CP: Copy
Copies files from one location to another.

 General form: CP <filename> <location>


RM: Remove a file, directory.

 rm filename.txt
 rmdir directoryname
5: Network Basics
SSH: Secure remote terminal
 Uses strong encryption (AES 256) to provide a secure terminal shell
 Can forward X sessions, and provide socks tunneling
 General form: ssh username@hostname –p port
Ifconfig : Display network adapter info
Description: Allows for network interfaces to be configured
 Displays statistics on RX/TX packets received
 Shows IPV4 and IPV6 mac addresses

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500


inet 172.22.22.56 netmask 255.255.255.0 broadcast 172.22.22.255
inet6 fe80::20c:29ff:fe41:26bb prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:41:26:bb txqueuelen 1000 (Ethernet)
RX packets 409051 bytes 105465093 (100.5 MiB)
RX errors 0 dropped 299 overruns 0 frame 0
TX packets 68167 bytes 10118400 (9.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
“Virtual” IP addresses
 You are able to assign multiple IP addresses to a single network interface. A
“virtual” IP address is commonly used in a CM duplex pair, where the active
and standby servers ‘share’ an IP address for high availability.
 The adapter name will contain a colon followed by a number
Example: eth0:0 or eth0:1

eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500


inet 172.22.22.99 netmask 255.255.255.0 broadcast 172.22.22.255
inet6 fe80::20c:29ff:fe41:26bb prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:41:26:bb txqueuelen 1000 (Ethernet)
RX packets 409051 bytes 105465093 (100.5 MiB)
RX errors 0 dropped 299 overruns 0 frame 0
TX packets 68167 bytes 10118400 (9.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Vlans
 Although it is rare to see a vlan associated with a network interface, it is
important to know what they look like
 General form: <adapter name>.<vlan>

eth0.100: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>
mtu 1500
inet 172.22.23.56 netmask 255.255.255.0 broadcast
172.22.22.255
inet6 fe80::20c:29ff:fe41:26bb prefixlen 64 scopeid
0x20<link>
ether 00:0c:29:41:26:bb txqueuelen 1000 (Ethernet)
RX packets 409051 bytes 105465093 (100.5 MiB)
RX errors 0 dropped 299 overruns 0 frame 0
TX packets 68167 bytes 10118400 (9.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Network bridges
 Layer 2 (OSI model) bridge
 Allows for many virtual machine interfaces to be attached to one physical NIC
 Used in System Platform
Route – Modify/Show routing information
 A route modified with this command with not survive a reboot.
 Shows routing information
 Allows you to temporarily change a route
Nslookup : DNS resolver tool
 Used to convert an IP address to a DNS hostname
 General form: nslookup <domain name>
Ping: ICMP echo tool
 Determines if a resource is ‘reachable’
 Also has uses for VOIP engineers
 Fields of interest
 Rtt avg = delay
 Mdev = jitter
 Packet loss = loss
 This should only be used as an indicator, and the results should never be
provided to a customer. QOS can easily skew these results
Netstat: Shows listening ports
 Typically this tool would be used to determine if a service is actively listening
on a port
 Options:
 -l show listening ports
 -t show only tcp
 -u show only udp ports
 -n do not resolve commonly used port names (display only the port number)
Arp: Address Resolution Protocol
 ARP table contains the layer 2 MAC addresses and the corresponding IP
address.
 ARP tool takes an IP address as an input, and returns the corresponding layer
2 MAC address
Arping
 Tool is commonly used to detect IP conflicts.
 Gratuitous arp requests are sent to an IP address. The response should come
from a single MAC address (only 1 device should have an IP at any given time).
If multiple devices reply, then you will see multiple MAC addresses in the
response.
Traceroute
 Print the route packets trace to network host by sending ICMP “Time
Exceeded” messages to each host.
 Can be easily blocked by a firewall (and it should be). Do not rely on it.
FTP/SFTP: Secure FTP
 Uses the same encryption and ports as SSH
 Used to transfer files between systems
 Options:
 put <filename>
 get <filename>
Lab 5: Network Basics
6: Additional Linux
Process Details
Linux Kernel
 Linux kernel is responsible for loading device drivers
 Kernel writes logs to /var/log/dmesg
 Systemd or init is called when the kernel is ready to
pass control to user-space.
 Init and Systemd will always have process #1
Top – Shows system processes
Description: Top will show all system processes in a GUI like interface.
 This is what a lot of hacker movies use when they want to show off Linux
 Able to sort by CPU utilization, memory utilization, and process state
Linux Processes
 Processes carry out tasks within the operating system
 Multi-tasking occurs when processes fork child processes
 Each process will have a ‘state’ associated with it
 Running – Currently consuming CPU cycles
 Waiting – Waiting for an event or resources
 Stopped – Received a signal indicating that the process is to ‘stop’ or ‘pause’
 Zombie – Not responding, or child process no longer has a parent
w – Shows logged in users
Description: Shows who is logged on and what they are doing
 Example: bash# w
ps – Print process list
Description: Reports a snapshot of the current processes
 Options:
 -a Select all processes
 -u Select user (if blank select all users)
 -x Display all processes regardless if they have a tty

Example: ps –aux
Free: Shows memory information
Description: Displays the memory information for the system.

The amount of free memory is the sum of Mem + buffer


Example:
Mem 1958620
Buffers 2467896
-----------
4426516 Available memory
Kill : Forcefully terminate a process
Description: Forcefully terminates a running process by sending the process a
pre-determined signal number.
 1) SIGHUP - “Signal Hangup” – Signals to the process that the window has
been closed, or the TTY has been abandoned
 9) SIGKILL – “Signal Kill” – Causes the process to terminate immediately.
Process cannot perform any clean up

Kills the bash process with the PID (process ID) of 11131
uname: Print System Information
Description: Prints system information such as kernel version and hostname
 Options:
 -a All
 -s Kernel-name
 -o Operating system
du : Estimate file space usage
Description: Summarize disk usage of each FILE, recursively for directories.

 Options:
 -h Print output in human readable form

Tip: This command is useful to determine large files on a system. To sort by


largest file, use this command: du | sort -rn | more
Tar: Archives Files
Description: used to correlate many files into one archive. This tool utilizes
commonly used compression algorithms such as bzip and gzip
Options:
c Create file
x Extract files
v Verbose
f Refers to files and directories

Example: tar –cvf ”outputname” /var/home/student1/* < for entire directory

IE2 : tar -cf “outputname”.tar “targetfilename”


Gzip: Compress/Decompress a file
Description: Typically gzip is used when you need to compress or decompress 1
file (could be an archive or a standalone file)
Usage:
Compress: gzip <file>
Decompress: gzip –d <file.gz>
Lab 6: Practical Application
and CM Specific Commands.
Questions?

Вам также может понравиться