Sunday, June 28, 2015

Find files on certain directory for excluding files certain permission

Why is this useful? When your directory contains thousands of files.
Yes, CHMOD is slow and surprisingly very I/O taxing.
So being able to use 'find' command first to only CHMOD certain files
that needs to be CHMODED is useful.


find /your_directory ! -perm 0777

-OR-

find /your_directory \! \( -perm 0777 -o -perm 0775 \)

Check if file or directory exists using bash or shell script sh

if [ -f file_path_name.ext ]
then
echo "file exists"
else
echo "file does not exists"
fi


if [ -d directory_path ]
then
echo "dir exists"
else
echo "dir does not exists"
fi

Send HUP hangup hang-up signal to linux process to re-read configuration file

kill -HUP $( cat /var/run/nginx.pid )

Find inodes where it is being used inside directories

This command will show inodes being used in directories recursively:

find {{{starting directory}}} -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

Friday, February 27, 2015

Sunday, February 1, 2015

Quick and dirty bash shell script to find issues on your linux server

I usually would place this file in my home directory and name it 'find_issues.sh'

cd ~
nano find_issues.sh
chmod +x find_issues.sh

content of find_issues.sh:


#!/bin/bash

read -sn 1 -p "Press any key to check keyword 'error'";echo
tail -n 1000 /var/log/messages | grep error

read -sn 1 -p "Press any key to check keyword 'fail'";echo
tail -n 1000 /var/log/messages | grep fail

read -sn 1 -p "Press any key to check keyword 'panic'";echo
tail -n 1000 /var/log/messages | grep panic

read -sn 1 -p "Press any key to check keyword 'fault'";echo
tail -n 1000 /var/log/messages | grep fault

read -sn 1 -p "Press any key to check keyword 'timeout'";echo
tail -n 1000 /var/log/messages | grep timeout

Check if directory exists using bash or linux shell script

if [ -d directory_path ]
then
   echo "dir exists"
else
   echo "dir does not exists"
fi