Bash Flashcards
for loop
for i in cat text.log
do
echo $i
done
awk
- simple separation and print
- run command based on output
- echo $TEXT | awk -F” “ ‘{ print $1 }’
2. echo $TEXT | awk -F” “ ‘{ for(i=1;i<=NF;i++) { system(“echo “ $i) } }’
Create a loopback interface
tcpdump -D #check interfaces
ifconfig lo1 create #create loopback interface
ifconfig lo1 #cehck loopback 1 status
ifconfig lo1 up #start lo1 interface
ifconfig lo1 inet 192.168.144.25/32 #assign IP to lo1
ifconfig lo1 down
ifconfig lo1 destroy
What is a loopback address?
Loopback interface is a software driven interface, and are not bound to any network interface cards(NICs); are always in UP state unless manually turned down or if the router is down. This makes it very good option to monitor the router’s availability.
If we monitor a router using an IP, that is attached to a NIC; we just monitor the NIC, if the NIC goes down, that doesn’t mean that the whole router is down.
Add space to AWS EC2 machine
lsblk #shows the size of the disks available.
sudo su
growpart /dev/xvda 1 #increases the size of the first partition to the available space.
resize2fs /dev/xvda1 #increment the file system size to use all avaialable space on the partition.
How to archive using tar
tar -czvf myDir.tar.gz myDir
tar -xzvf myDir.tar.gz
tar -tzvf myDir.tar.gz #list the contents of tar file.
Create Soft links
ln -s /opt/myDir/foo.exe /usr/local/bin/foo
Print multiple lines with echo
echo -e “adadas \n awdasd \n asdasd”