Read a text file in bash line by line with while. It will read till the end of line. You can modify the end of line setting a new value to EOF variable.
bash |copy code |?
1 while read line; do echo "${line}"; done < <(cat file.lst)
Read a text file in bash line by line with while. It will read till the end of line. You can modify the end of line setting a new value to EOF variable.
bash |copy code |?
1 while read line; do echo "${line}"; done < <(cat file.lst)
Easiest way to clone a partition in command line.
bash |copy code |?
1 dd if=/dev/sda1 of=/dev/sdb1
Recursively search all files matching a regexp in the current directory and then listing them.
bash |copy code |?
1 find . -type f -name "*.file" | xargs grep -l "STRING"
This could also be done like this:
bash |copy code |?
1 find . -type f -name "*.file" --exec grep -l "STRING" {} \;
If you notice high load in your server or unresponsive services it might be you are suffering an ddos attack. If you want to have one snapshot of ips connected to your server, just type this command:
bash |copy code |?
1 $ netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
This is a recursive description. Watch if a page changes with watch.
bash |copy code |?
1 watch -d -n 5 "echo `date` `wget --timeout=5 -qO - URL
Easy easy. Just like this. Dont forget to down/up the interface
bash |copy code |?
1 #sudo ifconfig eth0 down hw ether 11:22:33:44:55:662 #sudo ifconfig eth0 up
Don’t use it as a way to count visits, as all these ips are not real visits, but bots, crawlers, etc.
bash |copy code |?
1 cat access.log | grep -o '\([0-9]\{23\}.\)\{3\}\.[0-9]\{23\}' | sort | uniq | wc -l
If typing ifconfig is too simple for you here it is the geeky way to get the ip of your interfaces.
bash |copy code |?
1 ifconfig | sed -n "/en0//netmask/ p" | grep "inet " | awk '{print$2}' copy to .bash_profile:2 alias getip='ifconfig | sed -n "/en0//netmask/ p" | grep "inet " | awk ''{print\$2}'''
How to extract a tar file to a directory
bash |copy code |?
1 tar -cvvf archive.tar /pathtoextract
Here’s the trick:
bash |copy code |?
1 cat /tmp/test | awk 'NF > 0' > /tmp/test1