Tag: command
-
Analyse Access Log with awk for most common ip addresses
Some cat with awk and then sort to find out what ips are most common in your apache access.log file. Remember that all ips are include here. Bots, crawlers, clients… cat /path/to/log | awk ‘{print $3}’ | sort | uniq -c | sort -rn | head -20
-
Empty a database table command
How to empty a mysql database. Forget about delete * command #!/bin/bash mysql -D $DATABASE -e ‘TRUNCATE TABLENAME;’
-
Read a text file with bash line by line
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. while read line; do echo “${line}”; done
-
Find and list files containing a string
Recursively search all files matching a regexp in the current directory and then listing them. find . -type f -name “*.file” | xargs grep -l “STRING” This could also be done like this: find . -type f -name “*.file” –exec grep -l “STRING” {} \;
-
DDos attack: Display IP connection count
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: $ netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort…
-
Watch a page for changes with watch
This is a recursive description. Watch if a page changes with watch. watch -d -n 5 “echo `date` `wget –timeout=5 -qO – URL
-
RPM – Verify if a package is already installed
Command to search for an installed package in .rpm systems rpm –verify mysql
-
List folders with a slash
Option for ls command to list directories with and ending slash. Just to visualize directories in a different way. ls -p
-
Linux – Mount Bind
An example of mounting with bind. mount –bind Folder NewFolder
-
Add an existing user to existing group in Linux
#add the user to the supplemental group(s) usermod -a -G group user #Change existing user primary group to www: usermod -g www user