Expand tar file from Linux command line

If you have a file.tar.gz that you need to expand from the command line, type the following:
tar xfv file.tar.gz

Mac OS X Lion: Install Failed – Disk is Damaged

If you get this message, then your hard drive needs to be repaired. This can be difficult to solve because data may not be backed up and disk utility may not be able to repair your drive. Furthermore, our recovery options are now limited since we can’t buy Install DVD’s anymore. To make matters even worse, the installer creates a perceived loop that will not allow canceling installation or access to disk utility, terminal, or other options.

Here are the steps I followed to solve this issue:

  1. Try installing Lion and get ‘Install Failed – Disk is Damaged’ error
  2. Reboot computer and try installing again – same error (continued reboots do not allow access to install options, disk utility, or terminal; only reboot option)
  3. Reset PRAM to get out of infinite loop (rebooting, attempting to install, failing, …)
    • Turn off computer
    • Locate the following keys on the keyboard: Command (⌘), Option, P, and R. You will need to hold these keys down simultaneously in step 4.
    • Turn on the computer.
    • Press and hold the Command-Option-P-R keys before the gray screen appears.
    • Hold the keys down until the computer restarts and you hear the startup sound for the second time.
    • Release the keys.
    • Now computer should boot normally into the installer
    • For more information, see Apple Support Article About NVRAM and PRAM
  4. I downloaded an installer image from the internet to perform my install. I then used disk utility to copy the files to a flash drive. To boot from this drive, I held option as my computer started and selected this drive. If you don’t have a bootable flash drive, then boot from any installer DVD that you do have.
  5. Go to the Utilities menu and select ‘Disk Utility’
  6. Try to repair the disk here. It may not work. If it doesn’t, then close Disk Utility and open Terminal
  7. When terminal opens, type fsck_hfs -rf /dev/disk0s2 and press return
  8. This may take up to 10-15 minutes, but it should repair your drive. When it is complete, restart your computer and try the installation again. These steps worked for me on a MacBook Air Original. NOTE: your drive may not be disk0s2, so if it is not, then try to lookup the actual drive path in Disk Utility or search on Google.

Mac OS X (10.6, 10.7, 10.8) Disk Utility repair failed

If Disk Utility is unable to repair hard drive, then try booting from any install DVD or USB drive. Then open terminal from the Utilities menu.

When terminal opens, type:
fsck_hfs -rf /dev/disk0s2

Your disk partition may be called something other than ‘disk0s2’. This process may take 10-15 minutes, but is more powerful than the regular Disk Utility repair option.

Disable Automatic Restart after Windows Update – Windows XP

Go to registry editor and navigate to the following registry key:
If the key does not exist, then you must create it.


Change the “NoAutoRebootWithLoggedOnUsers” DWord value to the required number.

0 = False (Allow auto-reboot)
1 = True (Disallow auto-reboot)

Save and restart Windows Operating system.

Create your own system recovery dvd/cd to restore your system

The best program I have found to make your own Recovery DVD is Macrium Reflect. There is a free version available with all the necessary features.

Why doesn’t my cron job run?

Possible reasons your cron job won’t execute:

  • Check your script
  • Type the exact content of your script in your terminal window and verify that is is working manually. Then, if your server supports it, check if it works when you execute manually from web interface.
  • Use full paths
  • Many servers will run scripts without full paths both from the command line and in the web interface; however, they may not run on schedule.
  • If you are using:
  • * * * * * cd /users/home/username/domains/mydomain.tld/web/public/folder; php -f cron.php > /dev/null 2>&1
  • Try this, with full paths:
  • * * * * *cd /users/home/username/domains/mydomain.tld/web/public/folder; /usr/local/bin/php -f cron.php > /dev/null 2>&1
  • The time is not set correctly
  • The time is usually GMT/UTC on your server. Don’t look at your system clock. Click here for instructions to see the date/time on your server. Also, verify that the correct minutes, hours, days, months, and weekdays are active.
  • Reference files have been moved or deleted
  • Check any files used in your script and make sure they are in the location referenced by your script.
  • Your cron job is not active
  • Make sure your cron job is marked active (not disabled)

Display date and time via unix command line

To display the date and time, enter the following in your terminal:
# date
Sample output:

[myserver:~] username$ date
Sunday, April 22, 2012  8:29:14 AM GMT

What version of Apache am I running?

Httpd is the Apache HyperText Transfer Protocol (HTTP) server program. To display the current apache version, type the following in your terminal window:
# httpd -v
Sample output:

Server version: Apache/2.2.3
Server built:   Oct 28 2008 07:22:45

Output list of modules compiled into the server:

# httpd -l
This will not list dynamically loaded modules included using the LoadModule directive. To dump a list of loaded Static and Shared Modules:
# httpd -M
Sample output:

Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_file_module (shared)
 authn_alias_module (shared)
 authn_anon_module (shared)
 authn_dbm_module (shared)
 authn_default_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 authz_owner_module (shared)
 authz_groupfile_module (shared)
 authz_dbm_module (shared)
 authz_default_module (shared)
 ldap_module (shared)
 authnz_ldap_module (shared)
 include_module (shared)
 log_config_module (shared)
 logio_module (shared)
 env_module (shared)
 ext_filter_module (shared)
 mime_magic_module (shared)
 expires_module (shared)
 deflate_module (shared)
 headers_module (shared)
 usertrack_module (shared)
 setenvif_module (shared)
 mime_module (shared)
 dav_module (shared)
 status_module (shared)
 autoindex_module (shared)
 info_module (shared)
 dav_fs_module (shared)
 vhost_alias_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 actions_module (shared)
 speling_module (shared)
 userdir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 proxy_module (shared)
 proxy_balancer_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_connect_module (shared)
 cache_module (shared)
 suexec_module (shared)
 disk_cache_module (shared)
 file_cache_module (shared)
 mem_cache_module (shared)
 cgi_module (shared)
 version_module (shared)
 chroot_module (shared)
 perl_module (shared)
 php5_module (shared)
 proxy_ajp_module (shared)
 python_module (shared)
Syntax OK

Print the version and build parameters of httpd, and then exit

Type the command:
# httpd -V
Sample output:

Server version: Apache/2.2.3
Server built:   Oct 28 2008 07:22:45
Server's Module Magic Number: 20051115:3
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

To view other configuration settings open httpd.conf file (usually located in /etc/httpd directory).Red hat, CentOS and Fedora stores httpd at the following location:
# vi /etc/httpd/conf/httpd.conf
Debian and Ubuntu stores httpd.conf in apache2.conf file at the following location:
# vi /etc/apache2/apache2.conf
FreeBSD stores apache2.2 configuration at the following location:
# vi /usr/local/etc/apache22/httpd.conf
If you made any changes to httpd.conf, check httpd syntax for error using the -t option:
# httpd -t

Rename folder cp via unix command line

To rename a file or folder, enter the following in your terminal:
# cp oldfilename newfilename
# cp oldfoldername/ newfoldername/

Using SSI (Server Side Includes) with domain aliases

I had several domain aliases and wanted to show a different html page based on the domain visited. Since these sites are all very similar, I wanted to share images and other content between them. I also wanted to be able to update the content in only one location. After some research, I determined that SSI could do exactly what I needed.

Add lines to your .htaccess file

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .html .shtml
DirectoryIndex index.shtml index.html index.php

Enter the following in your index.html file

<!–#if expr='”$HTTP_HOST” = “domain1.tld” || “$HTTP_HOST” = “www.domain1.tld”‘–>
<!–#include virtual=”domain1.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain2.tld” || “$HTTP_HOST” = “www.domain2.tld”‘–>
<!–#include virtual=”domain2.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain3.tld” || “$HTTP_HOST” = “www.domain3.tld”‘–>
<!–#include virtual=”domain3.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain4.tld” || “$HTTP_HOST” = “www.domain4.tld”‘–>
<!–#include virtual=”domain4.html” –>
<!–#include virtual=”NoneOfThese.html” –>

Explanation of above:

Options +Includes Turn on includes
AddType text/html .shtml Recognize .shtml file extension
AddHandler server-parsed .html .shtml Process both .html and .shtml for SSI
DirectoryIndex index.shtml index.html index.php Display index pages in this order

You can find many resources online that will explain all the features of SSI. Here, I am only looking to say “if the domain visited is X.com or www.X.com, then show X.html”.

Breakdown of SSI index.html

<!–# … –> Process for SSI
<!–#if expr=’ … ‘–> Start ‘If’ evaluation. If … is true, then execute next action
“$HTTP_HOST” String value for current domain name
“$HTTP_HOST” = “domain1.tld” Value of ‘True’ if current domain is domain1.tld
|| ‘Or’ operation. If either is true, then result is true
include virtual=”domain1.html” Insert content from domain1.html
<!–#elif expr=’ … ‘–> If nothing true yet, then continue checking elseif lines
<!–#else–> If noting was true, then execute next line
<!–#endif–> Stop processing this ‘If’ statement