How to search string in all files in a folder and sub folder recursivelly

How to use “grep” command in linux or macos to find text inside all files in a folder and including subdirectories

Command for the same is
grep -rl "string to search" /absolute-path/to/folder/

-r (or –recursive) option is used to traverse also all sub-directories of /path
-l (or –files-with-matches) option is used to only print filenames of matching files
-i ( for ignore case sensitive)

If you’re looking for lines matching in files, then use the below command

grep -Hrn "string to search" /absolute-path/to/folder/

-H causes the filename to be printed (implied when multiple files are searched)
-r does a recursive search
-n causes the line number to be printed
/absolute-path/to/folder/ can be . (dot) to search in the current directory

How to create date wise apache error log and access log

By default apache write the access log and error log in the single file. Later it grow in sizes over days and then when you have to debug you find the issue from the apache log, it become difficult to open and read the file. And over a time, the log size bigger so big that, many of the file editor fail to load the file.

Default Logformat
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

So apache come with a inbuilt program called rotatelogs.
First you need to check if rotatelogs is present on your server or not.

To check if rotatelogs is present type the below command
> whereis rotatelogs

The output of the command will be as below
rotatelogs: /usr/bin/rotatelogs /usr/share/man/man8/rotatelogs.8.gz

This “/usr/bin/rotatelogs” indicate that rotatelogs program is present

Now to split your errorlog and accesslog by date, you need to comment the default log format
#ErrorLog ${APACHE_LOG_DIR}/error.log
#CustomLog ${APACHE_LOG_DIR}/access.log combined

and write down the below format.

CustomLog “| /usr/bin/rotatelogs -l /var/log/apache2/access.%Y.%m.%d.log 86400” common
ErrorLog “| /usr/bin/rotatelogs -l /var/log/apache2/error.%Y.%m.%d.log 86400”

What this does is…everyday a new error log and access log file will be created like error.2020.04.03.log and access.2020.04.03.log respectively.

To explore more option for the custom logging you can refer the apache project page http://httpd.apache.org/docs/current/programs/rotatelogs.html