Shell Script

Clear Cache Directory Files

In Linux we are using PHP Smarty template engine,
since the cache is created for each and every execution of PHP script,
it is hard to clear manually the tpl folder for each time in the development system.
in that case we are forced to delete the tpl files in that directory. so we need a solution so that automatically clear the cache entry.

This kind of deleting files in the given folder can be easlily done by the shell script,
Assume we have to delete cached file in Dir = /var/www/Smarty/template_c/;
Here the Bash Shell Script as follows:

For this kind of you have to write

Searching text in the given folder

Assume you want to search vivek text in the folder /var/www/

grep -R vivek /var/www

How to compare two folder which has n Sub Folders and Files

For that we have to make use of Find,Sort ,Diff command as follows


find ./ -name "*.*" | sort > file_1.txt
find ./ -name "*.*" | sort > file_2.txt
diff file1_sort.txt file2_sort.txt

First we have run the find command in one folder & store in file_1.txt
then we have run the find command in anoter folder & store in file_2.txt
then just run the command diff file 1 file2

Brainbench question in Unix Administration

i have attached Brainbench question and answers in unix Administraton as follows:

1.Command: telnet localhost 25
Question: A system administrator types in the above command.Which one of the following does this command do? It perfoms a port scan of the localhost
It tries to connect to the localhostwith the tomeout of 25 seconds
It attempts to compromise the local system's security
It sends 25 SYN packets to the localhost & then connects
Answers: 3

2.Excessive context switching is an indication of which one of hte following? A disk botleneck

Addition of two array elements

The array is created on the first assignment,Array element value can be retried by using {} operator

=`expr ${arr[1]} + ${arr[2]}`
"The Addition of two array Elements are: "$result

More samples :

How to extract all the files in the given Folder

I want to extract all the files in the given Folder

This is the code which extract all the bzip files in the current folder. if you have other format , change bzip2 to the exact command.


for vFileName in *.*; do
echo $vFileName;
bzip2 -d $vFileName;

Reading Linux System configuration how to modify it

Reading Linux System configuration how to modify it

To know full details of the current machine configuration like file system,virtual memory,kernel,devices,networking,sunrpc. you can easily get from the proc file system /proc/sys/.
TO change these parameter use command sysctl

sysctl -a

Date Format

date command as follows : Tue May 12 06:48:14 PDT 2009
Hence get by the position as follows
date | awk '{ print $3 $2 $6 }'

Non Killable Process

Generally all the process having parent process ID is 0 is not killable, because kernel process id is 0.
Depends upon the kernel it varies, just check it yours by giving command as :
ps -ef | awk ' $3==1 { print $0 }'

root 1 0 0 Apr06 ? 00:00:01 /sbin/init
root 2 0 0 Apr06 ? 00:00:00 [kthreadd]

1.init : init program is the first program run after your kernel begins running.
2.kthreadd: Kernel thread daemon which mainly used for device drivers