Linux Commands

Watch commands:

To check Mysql in watch command

watch -n1  “mysql -uUseranme -pPassword -e ‘show full processlist’; ”

The above command will show processlist per second

To check Apache server status in watch command

watch -n1 “/usr/sbin/apachectl status”

The above command will show the server request per second

To check Nginx installer configure list

#nginx -V

Purge Mysql Binary files before specific date

connect to mysql server slave or master execute the below command (Before executing change the date as per your connivence)

purge binary logs before ‘2017-12-30 00:00:50’;

Debug using one of the process list.

Example: With the process ID, they can debug why it is sleeping.

Mysql_sleep
netstat -ntp | grep 52683

Established process will have the process ID. They need to check with the same command what that process is doing

netstat -ntp |geep “ESTABLISHED process ID”

strace -p “ESTABLISHED process ID” will show the threads of the connections.

See if any attack on port 80

netstat -plan|grep :80|awk {‘print $5’}|cut -d: -f 1|sort|uniq -c|sort -nk 1

Generate CSR on Linux,

openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr

Create User with specific Home Directory

Shell> adduser -d /path to which you want to keep default home directory/ username

How to merge mulitple files in single file on Linux.

Shell> cat 1.txt 2.txt 3.txt > 0.txt

Count files or folder in specific folder

cd to folder you need count and execute the command “ls | wc -l”

Check the latest files in folder

cd to folder you need count and execute the command “ls -lt”

to see the latest files from below execute the command “ls -latr”

to see the latest files from below with latest 10 execute the command “ls -latr | tail -l”

Find text in files

grep -rnw '/path/to/somewhere/' -e 'pattern'

Apache Htpassword: 
If Htpasswd don;t work with -c command then use below command

“htpasswd -b passwordfile user password” did the trick.

Nping: Ping continuous with port. 

nping -tcp -c3 -p 80 scanme.nmap.org

List the latest file from Multiple Sub-Directories on LINUX

find $1 -type f -print0 | xargs -0 stat –format ‘%Y :%y %n’ | sort -nr | cut -d: -f2- | head

Find out external IP address from shell prompt on LINUX

curl http://canhazip.com

Check History with Time and Date
Shell# echo ‘export HISTTIMEFORMAT=”%d/%m/%y %T “‘ >> ~/.bash_profile

Comments are closed.