Linux Module 5 (Revision Series)
Sem 4 BCA/B.Sc. Computer Science MGU
For Notes download BCA Resources App
Module 5 Overview
• Simple filter commands: pr, head, tail, cut, sort, uniq, tr
• Filter using regular expression grep, egrep, sed
• Understanding various Servers :DHCP, DNS, Squid, Apache, Telnet,
FTP,Samba.
For Notes download BCA Resources App
Simple filter commands
• pr
• Used to format a file to make it look better when displayed
• Displays content of the file by adding suitable header & footers.
• Header part contains: last modification date & time with filename & page number
• Syntax: pr option filename
• Options:
• -t - omits page header & footers
• -n – number of lines
• -h – uses specified header string as page header
• head
• Prints first n number of lines in a file.
• Prints 10 lines by default.
• If more than one file is specified, data from each file is displayed along with filename
• Syntax: head options filename
• Options:
• -n – print first n lines
• -c – prints first n bytes
• -v – print header giving filenames
For Notes download BCA Resources App
Simple filter commands
• tail
• Prints last n number of lines in a file.
• Prints 10 lines by default.
• If more than one file is specified, data from each file is displayed along with filename
• Syntax: tail options filename
• Options same as head
• cut
• Used to cut columns/fields of a specified file
• Can be used to cut parts of a line by providing byte position, character & field
• Syntax: cut option filename
• Options:
• -b – selects only these bytes
• -c – selects only these characters
• -f – selects only these fields
• -d - used to cut a specific section by a delimiter.
For Notes download BCA Resources App
Simple filter commands
• cut -d- -f2 marks.txt
• cut -d- -f1 marks.txt
For Notes download BCA Resources App
Simple filter commands
• sort
• Used to sort the contents of a given file based on ASCII values of characters.
• Syntax: sort options filename
• Options:
• -r : sorts in reverse order
• -n : numerical sort
• -f : ignore case
• -o filename: stores output to a file
• tr
• Stands for translate
• Command line utility for translating or deleting characters.
• It supports a range of transformations including uppercase to lowercase, deleting specific characters etc.
• Can be used with pipes to support more complex translation
• Syntax: tr option set1 set2
• Options:
• -c – complements the set of characters in string
• -d – delete characters
For Notes download BCA Resources App
Simple filter commands
• tr values:
• [:alnum:] : All letters & digits
• [:alpha:] : All letters
• [:space:]: All horizontal or vertical space
• [:lower:]: All lower case
• [:upper:] : All uppercase
• [:digit:] : All digits
• Examples
• Echo “Hello World” | tr “[:lower:]” “[:upper:]”
• echo "my username is 432234" | tr -cd [:digit:]
• echo "my username is 432234" | tr –d [:digit:]
For Notes download BCA Resources App
Simple filter commands
• tr values:
• [:alnum:] : All letters & digits
• [:alpha:] : All letters
• [:space:]: All horizontal or vertical space
• [:lower:]: All lower case
• [:upper:] : All uppercase
• [:digit:] : All digits
• Examples
• Echo “Hello World” | tr “[:lower:]” “[:upper:]”
• echo "my username is 432234" | tr -cd [:digit:]
• echo "my username is 432234" | tr –d [:digit:]
For Notes download BCA Resources App
Module 5 Overview
• Simple filter commands: pr, head, tail, cut, sort, uniq, tr
• Filter using regular expression grep, egrep, sed
• Understanding various Servers :DHCP, DNS, Squid, Apache, Telnet,
FTP,Samba.
For Notes download BCA Resources App
Simple filter commands
• Grep
• Used to search for a specified pattern from a specified file & display all lines
containing that pattern.
• Grep is an acronym for globally search a regular expression and print it.
• Syntax: grep options pattern filename
• Options
• -i : Ignore cases when comparing
• -v: prints only lines that don’t match the pattern
• -c: Displays the count of matching lines
• -w: match whole word
For Notes download BCA Resources App
Grep Regular Expressions - Example
• “Linux” – Match lines containing the string Linux anywhere
• ^”Linux” – Matches Lines that starts with Linux
• “Linux”$ - Matches lines that ends with Linux
• . – Matches a single characters
• * - Match zero or more characters
• a..o – Matches word starts with “a” & ends with “o” separated by 2
characters
• a*.e –Matches word starts “a” and ends with “e” and contain n
number of characters in between
For Notes download BCA Resources App
Simple filter commands
• egrep
• Extended global search for regular expression
• Offers additional features than grep
• Multiple patterns can be searched by using pipe symbol
• Eg: egrep “anto|aju” filename
• sed
• Stands for stream editor
• Performs functions on file such as find & replace, search, insertion or deletion
• Commonly used for find & replace.
• Syntax: sed options ‘editcomand’ filename
For Notes download BCA Resources App
Simple filter commands
• Options
• -n – Supress automatic printing of pattern space
• editcommands
• i – Inserts before line
• a – append after line
• d – Delete line
• p – print line
• s/string1/string2 – Substitute String 1 by String2
For Notes download BCA Resources App
Module 5 Overview
• Simple filter commands: pr, head, tail, cut, sort, uniq, tr
• Filter using regular expression grep, egrep, sed
• Understanding various Servers :DHCP, DNS, Squid, Apache, Telnet,
FTP,Samba.
For Notes download BCA Resources App
Understanding various servers
• Server: a computer that provide data to other computers
• Serves data to systems via LAN,WAN over internet
• Different servers: mail servers, web server, file server
For Notes download BCA Resources App
DHCP – Dynamic Host Configuration Protocol
• Automatically assigns a unique IP address to each device that connect
to a network.
• No user config is necessary to connect a DHCP based network.
• Default protocol used by routers and networking equipment.
• DHCP Server provides configuration information & IP address to DHCP
client through series of messages known as DHCP transaction/
Conversation
For Notes download BCA Resources App
DHCP – Working
1. When client detects it has connected to DHCP server, it
sends a DHCPDISCOVER request
2. Request is received either by router or redirects to the
DHCP server.
3. If server accepts the new device it will send DHCPOFFER
message to client which has client mac address & IP
address offered.
4. Client returns a DHCPREQUEST message to the server
confirming it will use the IP address.
5. Finally, the server responds with a DHCPACK message that
confirms the client has been given access for certain
amount of time
For Notes download BCA Resources App
Allocation of IP in DHCP
• Three types of IP Allocation
1. Static allocation: The DHCP server allocates an IP address based on
table, which are filled manually. Only clients with a MAC address
listed in this table will be allocated an IP Address
2. Dynamic allocation: A network admin assigns a range of IP address
to DHCP, & each client on the LAN is configured to IP address from
the DHCP server during network initialization.
For Notes download BCA Resources App
Allocation of IP in DHCP
• Automatic allocation:
• Similar to Dynamic allocation.
• In this allocation DHCP server keeps a table of past IP address assignments, so
that it can assign the same IP to client again.
For Notes download BCA Resources App
DNS – Domain Name Systems
• DNS is an internet service that translates domain names into IP
addresses.
• DNS server manages, maintains & processes Internet domain names
& their records.
• Designed primarily to locate and deliver websites to end users over
Internet or private network.
• Always connected to internet
• BIND is DNS server software for Linux
For Notes download BCA Resources App
Apache
• Most widely used open source web server software
• Official name : Apache HTTP Server
• Designed for Unix environments but supports all other OS including
Linux, Windows.
• Apache is cross-platform software. Therefore supports both Unix &
Windows Server
• When a user want to access a webpage. Browsers send a request to
the server & Apache returns a response with all required files.
• Communicate through HTTP Protocol
For Notes download BCA Resources App
Apache Advantages
• Open source, free to use
• Stable & reliable web server software
• Flexible due to module based structure
• Easy to configure
• Cross platform
• Availability of support
For Notes download BCA Resources App
Apache Disadvantages
• Performance problem on heavy traffic websites
• Too many config option can lead to security issue
• Requires a strict update policy that needs to be done regularly
For Notes download BCA Resources App
Telnet
• Telnet (TELecommunication NETwork)
• Networking protocol & software used to access remote computers or
terminals via Internet.
• Also refers to command line utility “telnet”, available under all OS.
• Allows users to test connectivity to remote machines & issue
commands through the use of a keyboard.
• Computer being connected to is referred to as the remote computer.
For Notes download BCA Resources App
Squid
• widely used open-source proxy caching server for Linux and other
Unix-like operating systems.
• Known for its caching abilities, which help reduce bandwidth usage
and improve the response times for frequently requested web pages.
• commonly used in organizations, internet service providers (ISPs),
and even by individuals who want to optimize their internet access.
• Often installed on a separate server.
For Notes download BCA Resources App
Squid - Advantages
• Caching: When a client requests a web page, Squid checks its cache to see if the page has been
requested before. If it is in the cache and still fresh (not expired), Squid serves the page directly
from its cache, reducing the load on the origin server and improving response times for clients.
• Proxy Server: Squid acts as an intermediary proxy server between clients (such as web browsers)
and the internet. Clients make requests to Squid, and Squid forwards those requests to the origin
server. It then returns the response to the clients after caching it, if applicable.
• Bandwidth Control: Administrators can set bandwidth limits for clients or groups of clients,
preventing individual users from consuming excessive bandwidth.
For Notes download BCA Resources App
Samba
• Open-source software suite that enables file and print sharing between Linux/Unix-based systems
and Windows-based systems on a local network.
• Samba provides file and printer services using the SMB/CIFS (Server Message Block/Common
Internet File System) protocol, the same protocol used by Windows for file and printer sharing.
• Key features of Samba include:
• File Sharing: Samba allows you to share directories and files between Linux/Unix and
Windows machines. Linux directories can be made accessible as network shares, allowing
Windows clients to access and interact with the files over the network as if they were local.
• Printer Sharing: Samba provides printer services, allowing Windows clients to send print jobs
to printers connected to Linux/Unix systems. This enables centralized printing management
and access to printers from different platforms.
For Notes download BCA Resources App
FTP – File Transfer Protocol
• Standard network protocol used to transfer files between a client and a server on
a computer network.
• Operates on the client-server model, where the client initiates a connection to
the server to perform file transfer operations.
• The client software is commonly known as an FTP client, and the server software
is known as an FTP server.
• FTP typically uses two separate channels to transfer data:
• Command Channel: For controlling the commands & responses
• Data Channel: The data channel is used to transfer the actual files or directory
listings. Depending on the mode of FTP (active or passive), the data channel
can be initiated by either the client or the server.
For Notes download BCA Resources App
FTP – File Transfer Protocol
FTP uses two modes for data transfer:
• Active Mode: In active mode, the FTP server initiates the data connection
back to the client for transferring files.
• Passive Mode: In passive mode, the FTP client initiates the data connection to
the server.
For Notes download BCA Resources App
FTP – Advantages
• Speed – Fastest way to transfer files from one system to another
• Efficient – Don’t need to complete all the operations to get the entire
file
• Security – To access FTP Server, we need to login with username &
password
• Back & forth movement: Allows to transfer files back and forth
For Notes download BCA Resources App
FTP – Disadvantages
• Not all FTP providers offers encryption
• Size limit of a file is 2GB
• Doesn’t allow simultaneous transfer to multiple receivers
• Passwords are not that secure because they are sent in clear text.
For Notes download BCA Resources App