Linux Stuff

.screenrc

vbell off

# Enable mouse scrolling and scroll bar history scrolling

termcapinfo xterm* ti@:te@

scrollback 10000


.nanorc

#set mouse
set linenumbers
set smarthome
set smooth
set trimblanks

.bashrc (addition)

if [ -z "$STY" ]; then screen -x -R; fi


Find most recent modified files

find . -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -n | tail -10

# find . -type f -printf '%TY-%Tm-%Td %TH %p\n' | sort -n | tail -10 | cut -f2- -d" "

# https://stackoverflow.com/questions/4561895/how-to-recursively-find-the-latest-modified-file-in-a-directory

Trim whitespace from BASH variable

How to remove all whitespace (denoted by [:space:] in tr):

FOO=' test test test '
FOO_NO_WHITESPACE="$(echo -e "${FOO}" | tr -d '[:space:]')"
echo -e "FOO_NO_WHITESPACE='${FOO_NO_WHITESPACE}'"
# > FOO_NO_WHITESPACE='testtesttest'
echo -e "length(FOO_NO_WHITESPACE)==${#FOO_NO_WHITESPACE}"
# > length(FOO_NO_WHITESPACE)==12

How to remove leading whitespace only:

FOO=' test test test '
FOO_NO_LEAD_SPACE="$(echo -e "${FOO}" | sed -e 's/^[[:space:]]*//')"
echo -e "FOO_NO_LEAD_SPACE='${FOO_NO_LEAD_SPACE}'"
# > FOO_NO_LEAD_SPACE='test test test '
echo -e "length(FOO_NO_LEAD_SPACE)==${#FOO_NO_LEAD_SPACE}"
# > length(FOO_NO_LEAD_SPACE)==15

How to remove trailing whitespace only:

FOO=' test test test '
FOO_NO_TRAIL_SPACE="$(echo -e "${FOO}" | sed -e 's/[[:space:]]*$//')"
echo -e "FOO_NO_TRAIL_SPACE='${FOO_NO_TRAIL_SPACE}'"
# > FOO_NO_TRAIL_SPACE=' test test test'
echo -e "length(FOO_NO_TRAIL_SPACE)==${#FOO_NO_TRAIL_SPACE}"
# > length(FOO_NO_TRAIL_SPACE)==15

How to remove both leading and trailing spaces--chain the seds:

FOO=' test test test '
FOO_NO_EXTERNAL_SPACE="$(echo -e "${FOO}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo -e "FOO_NO_EXTERNAL_SPACE='${FOO_NO_EXTERNAL_SPACE}'"
# > FOO_NO_EXTERNAL_SPACE='test test test'
echo -e "length(FOO_NO_EXTERNAL_SPACE)==${#FOO_NO_EXTERNAL_SPACE}"
# > length(FOO_NO_EXTERNAL_SPACE)==14

https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable

PHP - Search File and Get Line Number


// https://stackoverflow.com/questions/3686177/php-to-search-within-txt-file-and-echo-the-whole-line
<?php
$file = 'somefile.txt';
$searchfor = 'name';

// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/html');  //was /plain

// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);

// escape special characters in the query
$pattern = preg_quote($searchfor, '/');

// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";

// search, and store all matching occurences in $matches
if (preg_match_all($pattern, $contents, $matches))
{

   echo "<table cellspacing=5><tr><TH>Found matches:</TH><th>IP</th><th>Line</th></tr>";
  //   echo implode("\n", $matches[0]);
foreach (current($matches) as $match) {
 $matchValue = $match[0];
    $lineNumber = substr_count(mb_substr($contents, 0, $match[1]), PHP_EOL);//+ 1;
    $matchValue = trim(preg_replace('/\s\s+/', ' ', $matchValue));
    echo '<TR><TD><a href=delete.php?line='.($lineNumber).'&ip='.$matchValue.'>[delete]</a></TD><TD>'. $matchValue.'</TD><TD>'.$lineNumber.'</TD><TR>';
 }
echo "</table>";

}
else
{
   echo "No matches found";
}

.