Run all scripts under in a directory
Answer:
Create the following bash script, and execute it
for FILE in /project/scripts/*.sh
do
if [-f $FILE -a -x $FILE]
then
$FILE
fi
done
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Run all scripts under in a directory
Answer:
Create the following bash script, and execute it
for FILE in /project/scripts/*.sh
do
if [-f $FILE -a -x $FILE]
then
$FILE
fi
done
Disable X-Powered-By and Server headers in Apache/PHP
Answer:
Add the following lines to the Apache configuration (httpd.conf)
Header always unset "X-Powered-By"
ServerTokens Prod
ServerSignature Off
Restart Apache to take effect
apachectl -k graceful
Assume the module mod_headers is enabled
How to redirect error message to a file
Answer:
Assume you have some program/script that print to the standard error stream (i.e. stderr)
E.g. error.pl
print STDERR 'error';
You cannot redirect the error message just by basic file redirection, e.g.
perl error.pl > error.txt
Instead, you need to use 2>
perl error.pl 2> error.txt
How to perform syntax check for Perl program
Answer:
Assume you have a Perl script test.pl, try run the command
perl -c test.pl
Syntax error will be displayed without running the code actually.
How to sort a hash in Perl
Answer:
# %hash is the hash to sort
@keys = sort { criterion() } (keys %hash);
foreach $key (@keys) {
$value = $hash{$key};
# do something with $key, $value
}