Linux e Unix tips and tricks

Yes I know linux and unix are a universe... but whit few command and the basic idea about the power of this OS you can do really many task.

So please see below my preferret and returning command used:

Copy server to server
Copy the file foobar.txt to remotehost.edu folder /some/remote/directory with user your_username
$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory

Show process running
ps aux | grep httpd
ps aux | grep apache2
ps aux | grep java
ps - ef|grep java

pidof httpd
pidof apache2
pidof java

VIew logs live

tail -100f <filename>

View disk usage

df -k

Kill process
kill PID
kill -9 PID

TAR and GZ
To compress a directory use the following syntax:
# tar -zcvf archive_name.tar.gz directory_to_compress

To decompress an archive use the following syntax:
# tar -zxvf archive_name.tar.gz
This will extract the files in the archive_name.tar.gz archive in the current directory. Like with the tar format you can optionally extract the files to a different directory:
# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

start apache
/etc/init.d/httpd start
Apache conf:
/etc/httpd/conf (httpd.conf must have -> ProxyRequests Off)
/etc/httpd/conf.d/tomcat-httpd.conf (file dependent from DNS backend)

remove recursively without confirmation
rm –Rf foldername

Stop and start MYSQL
sudo service mysqld stop
sudo service mysqld start

Create csv from sql table (mysql export)
select * from fnbl_subscription_plan INTO OUTFILE '/tmp/exportFile.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

Find string in files
This will search for string in all the FOLDER descendant and will show only the filename
grep -H -r "string" FOLDER
grep -Ril "text-to-find-here" FOLDER

Find from PATH descendant all the file named FileName
find [PATH] –name “FileName”

Find file bigger than
Find files from current path discendent bigger than 300 MB
find . -type f -size +300000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Send email from linux server

mutt -s "test" -b "<MYEMAIL>" < /dev/null
-s = subject
-b= destination

scritp to send email in case of error 500 on a HTTP services
#!/bin/bash
#clear
stato=""
stato=`wget --spider -S "http://<SERVER TO CHECK>" 2>&1 | grep "HTTP/" | awk '{print $2}'`

if [[ $stato == 500* ]]; then
   #echo $stato
   mutt -s "Error 500 on xxxxxxx " -b "MYEMAIL" < bodyTextFile
else
  echo "OK"
fi

Configuring Apache for slow dos attack

https://www.acunetix.com/blog/articles/slow-http-dos-attacks-mitigate-apache-http-server/

Enabling network on your centos7

http://www.krizna.com/centos/setup-network-centos-7/

Interesting unix command ad suggesiotions

http://www.commandlinefu.com/commands/browse