1.AWK
The Awk is a powerful scripting language used for text scripting. It searches and replaces the texts and sorts, validates, and indexes the database.
You can also say it's a combination of grep and find commands.
2.Features of AWK command:
It scans a file line by line.
It splits a file into multiple fields.
It compares the input text or a segment of a text file.
It performs various actions on a file like searching a specified text and more.
It formats the output lines.
Awk COMMANDS:
1. To print any column from the given file:
awk '/INFO/ {print $1, $4}' log_file.txt (it will print column 1 and column 4)
2. To print any column with NR (no of records):
awk '/INFO/ {print NR, $1, $4}' log_file.txt
3. To print column 1, 2, 4 where NR should be >20 and less than 50:
awk 'NR>20 && NR<50 && /INFO/ {print NR, $1, $2, $4}' log_file.txt
WORD COUNT:
This is used to count the number of lines and a number of words.
1. To count a number of lines:
wc -l log_file.txt
2. To count a number of words:
wc -w log_file.txt
HEAD & TAIL COMMAND:
1. Head ( use to display the top lines of a file).
head log_file.txt
2. Tail ( use to display the bottom lines of a file)
tail -n 5 log_file.txt
SECURE SHELL - SSH:
SSH or Secure Shell is a network communication protocol that enables two computers to communicate.
Keys are used for authentication and there are two types of keys: Public and Private keys
To generate ssh keys we need ssh - key gen
SECURE COPY - SCP:
SCP (secure copy) command in Linux system is used to copy file(s) between servers securely. The SCP command or secure copy allows the secure transferring of files between the local host and the remote host or between two remote hosts.
1. Transfer file local to remote server:
For File:
scp myfile.txt root@<ip_address>: /mnt/
For Directory:
scp -r /prod root@<ip_address>: /mnt/
2. Transfer files remote to local server:
For File:
scp root@<ip_address>: /mnt/myfile.txt /root/desktop/
For Directory:
scp -r root@<ip_address>:/ root@<ip_address>: /mnt/myfile.txt /root/desktop/ /root/desktop/