Linux

How to change the root password in Linux

Posted in Linux on February 12th, 2012 by Joonas – Be the first to comment

Changing the root password in Linux is super easy.

  1. Simply login to your server as root via SSH
  2. Type “passwd” in the command prompt.

The “passwd” program will prompt you for your current password and then the new password that you want to set.

This command works on all the modern Linux distributions. If you need help using the command, type “man passwd” in your command prompt.

How to replace a string in a large file

Posted in Linux, PHP on December 28th, 2011 by Joonas – Be the first to comment

I run in to this quite often where I have a situation where I need to replace some characters or strings within a large file. Assume that the file is too large to read in to memory and do the replacement within PHP. The solution is to use Linux’s sed command.

sed -i -e 's/search/replace/g' myFile.txt

Calling sed in a PHP script, this might look something like:

<?php
 
$filename = "myFile.txt";
 
$output = passthru(sprintf("sed -i -e 's/%s/%s/g' %s",
    escapeshellarg("this is some text i don't want"),
    escapeshellarg("we want this instead"),
    escapeshellarg($filename)
));
 
?>