HOW TO Flush The Linux File Cache

You can’t prevent Linux from using the file cache and you don’t want to. However, on occasion you may want to flush it. Here’s how:

First, flush your filesystems to disk. Just run the command sync

Then, echo 1, 2 or 3 in to /proc/sys/vm/drop_caches. It breaks down like this:

  1. free pagecache: echo 1 > /proc/sys/vm/drop_caches
  2. free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches
  3. free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, linux | Leave a comment

HOW TO Extract the contents of a .scexe file

HP Releases self-extracting firmware update files for Linux as .scexe files. These files usually contain an installer and a bunch of XML controlls. A -h flag provides a couple options for running the installer, but sometimes you don’t want to run it, you want to get at the contents.

.scexe files contain a hidden --unpack flag that will unpack the contents to the directory of your choosing.

For example:

# ./SOMEFILE.scexe --unpack=/tmp/test/
SOMEFILE.xml
SOMEFILE-PayLoad-version.version.version-1.zip
something.txt
installer
readme.txt
reference.xml

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, linux, Unix | 2 Comments

HOW TO Use Multiple Filter Flags in PHP Filter Functions

Using multiple filter flags in PHP is easy, but the documentation does not explain it well.

The Filter capabilities in PHP 5.3 and above are very powerful and save a ton of effort, but the passing of flags to various filter functions is described minimally as a “bitwise disjunction of flags”. This means you need to pass a bitwise conjunction of flags.

Here’s the english translation:
Pass a pipe-separated list of flags.

That’s it. You need to use the logical ‘OR’ to create a parameter the parser will understand.

If you want to use filter_var() to sanitize $string with FILTER_SANITIZE_STRING and pass in FILTER_FLAG_STRIP_HIGH and FILTER_FLAG_STRIP_LOW, just call it like this:

$string = filter_var($string, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);

That’s it. Nothing magical.

The same goes for passing a flags field in an options array in the case of using callbacks. Here is an extended version of the example from php.net:

$var = filter_var($string, FILTER_SANITIZE_SPECIAL_CHARS,
array('flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_ENCODE_HIGH));

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, php, Programming | 2 Comments