Bash scripting Notebook {part 2}
List of Contents:
- File exploring and directory commands.
- file manipulation commands
- Networking(ifconfig,ping,ip,hostname,dig,traceroute,netstat)
- text processing commands
File exploring and directory commands:
which — Display which program will be executed.
which bash
/usr/bin
type: Display information about command type.
less & more: less is a terminal pager program.
man: more is a command to view the contents of a text file one screen at a time.
cat: allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.
info: Info pages usually give more detailed information about a command then its respective man pages.
whatis: whatis searches a set of database files containing short descriptions of system commands for keywords and displays the result on the standard output. Only complete word matches are displayed.
mkdir : for creating directory .
rmdir: It is used for removing directory.
rm: It is used for removing files.
pwd: prints current working directory.
ls: ls is a command to list computer files.
strings: The strings command returns each string of printable characters in files.
file: determines the file type of a file.
cp: used for copy files or directoy.
cp [source] [destination]
mv: used for rename file or moving file.
mv [source] [destination]
Networking commands:
ifconfig-List the current network interface configuration
Displaying IP addresses
$ifconfig #for list all the interface with ip address$ifconfig wlan0 #for checking wlan0 interface ip address
changing the local IP address
$ifconfig wlan0 192.168.0.45 #it changes the local ip
Spoofing the hardware address (MAC address)
$ifconfig eth0 hw ether 08:00:27:27:80:4a
Name server and DNS (Domain Name Service)
Name servers assigned to the current system can be viewed by
$cat /etc/resolv.conf
dig-DNS lookup utility
DNS lookup commands
$nsloopup google.com$host google.com
route -Showing routing table information
ping - check the connectivity of two hosts on a network
traceroute — displays the address of all intermediate gateways through which a packet travelled to reach a particular destination.
$traceroute google.com
netstat — netstat is another command for the network service analysis.
Use netstat -tnp to list opened port
ssh -To connect to a remote host with the SSH server running.
ssh root@10.10.10.105 #root=username,10.10.10.105=hostname
netcat — Netcat is a computer networking utility for reading from and writing to network connections using TCP or UDP.
nc -lvpn 1111 #for listing on port 1111nc 192.168.0.3 1111 #for connecting with sepecified ip and port
#On the receiver machine, run the following command:
nc -l 1234 > destination_filename#On the sender machine, run the following command:
nc HOST 1234 < source_filename
curl- command line utility for transferring data from or to a server designed to work without user interaction.
wget — Wget is a computer program that retrieves content from web servers.
wget http://192.168.0.43:8080/a.py#downloading file from local network
Iptable — administration tool for IPv4/IPv6 packet filtering and NAT
IP — IP is the transport layer protocol used by the Internet protocol family.
tcpdump: allows you to capture and analyze network traffic going through your system.
openvpn-connect with openvpn
$openvpn filename.ovpn
Text processing commands:
cut: for cutting in column fashion.
$ cat student_data.txt
No Name Mark Percent
1 Sarath 45 90
2 Alex 49 98
3 Anu 45 90$ cut -f1 student_data.txt
No
1
2
3
awk: awk is a tool designed to work with data streams.
syntax:
awk ' BEGIN{ print "start" } pattern { commands } END{ print "end" }
file$ seq 5 | awk 'BEGIN{ sum=0; print "Summation:" }
{ print $1"+"; sum+=$1 } END { print "=="; print sum }'Summation:
1+
2+
3+
4+
5+
==
15
sed: steam editor is used for text replacement.
grep: for finding the pattern in the file