Archive

Archive for August, 2009

How to created a list of PHP files that have been modified for the past twenty four

August 24th, 2009 Comments off
  find /home/web1/public_html  -type f -daystart -mtime -1 -exec ls -l {} \;
 | egrep -v "(xls$|jpg$|png$|gif$|tif$)" > /root/files_last_modified.txt

I have given an explanation of each flag used in the above command as well.

  • /home/web1/public_html , specifies the directory to search, in this case the website document root
  • -type f , will only search for files and not directories
  • -daystart , will tell find to start with today date
  • -mtime, tells find to include every thing that was modified on and before a twenty fours hour period
  • -exec ls -l {}, will fun the ls -l command on each results
  • | , will redirect the output to another binary, in this instance egrep
  • The egrep flags will only display files that do not end in xls,jpg,png,gif, and tif.

301 Redirect

August 12th, 2009 Comments off

IIS Redirect

  • In internet services manager, right click on the file or folder you wish to redirect
  • Select the radio titled "a redirection to a URL".
  • Enter the redirection page
  • Check "The exact url entered above" and the "A permanent redirection for this resource"
  • Click on ‘Apply’

PHP Redirect

<? Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" ); ?>

ASP Redirect

<%@ Language=VBScript %>
<%
 Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>

ASP .NET Redirect

 <script runat="server">
 private void Page_Load(object sender, System.EventArgs e)
  {  Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
  }
</script>

Redirect Old domain to New domain – .htaccess

Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain. The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

#BOF :: Script for URL Rewrite
Options +FollowSymLinks
RewriteEngine on
rewritecond %{http_host} ^olddomain.com [NC]
rewriterule ^(.*)$ http://www.xyz.com/$1 [r=301,L]
#EOF :: Script for URL Rewrite

Please REPLACE www.newdomain.com in the above code with your actual domain name. In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website. Note - This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www – .htaccess

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Please REPLACE domain.com and www.newdomain.com with your actual domain name. Note –  This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Archiving Files at the Shell Prompt

August 11th, 2009 1 comment

A tar file is a collection of several files and/or directories in one file. This is a good way to create backups and archives. Some of the options used with the tar are:

  • -c — create a new archive.
  • -f — when used with the -c option, use the filename specified for the creation of the tar file; when used with the -x option, unarchive the specified file.
  • -t — show the list of files in the tar file.
  • -v — show the progress of the files being archived.
  • -x — extract files from an archive.
  • -z — compress the tar file with gzip.
  • -j — compress the tar file with bzip2.

To create a tar file, type:

tar -cvf filename.tar directory/file

In this example, filename.tar represents the file you are creating and directory/file represents the directory and file you want to put in the archived file. You can tar multiple files and directories at the same time by listing them with a space between each one:

  tar -cvf filename.tar /home/mine/work /home/mine/school

The above command places all the files in the work and the school subdirectories of /home/mine in a new file called filename.tar in the current directory. To list the contents of a tar file, type:

 tar -tvf filename.tar

To extract the contents of a tar file, type:

 tar -xvf filename.tar

This command does not remove the tar file, but it places copies of its unarchived contents in the current working directory, preserving any directory structure that the archive file used. For example, if the tarfile contains a file called bar.txt within a directory called foo/, then extracting the archive file will result in the creation of the directory foo/ in your current working directory with the file bar.txt inside of it. Remember, the tar command does not compress the files by default. To create a tarred and bzipped compressed file, use the -j option:

  • tar -cjvf filename.tbz file
  • tar -cjvf filename.tbz foldername/

tar files compressed with bzip2 are conventionally given the extension .tbz; however, sometimes users archive their files using the tar.bz2 extension. The above command creates an archive file and then compresses it as the file filename.tbz. If you uncompress the filename.tbz file with the bunzip2 command, the filename.tbz file is removed and replaced with filename.tar. You can also expand and unarchive a bzip tar file in one command:

 tar -xjvf filename.tbz

To create a tarred and gzipped compressed file, use the -z option:

 tar -czvf filename.tgz file

tar files compressed with gzip are conventionally given the extension .tgz. This command creates the archive file filename.tar and then compresses it as the file filename.tgz. (The file filename.tar is not saved.) If you uncompress the filename.tgz file with the gunzip command, the filename.tgz file is removed and replaced with filename.tar. You can expand a gzip tar file in one command:

tar -xzvf filename.tgz

Compressing Files at the Shell Prompt

August 11th, 2009 Comments off

Compressed files use less disk space and download faster than large, uncompressed files. In Red Hat Linux you can compress files with the compression tools gzip, bzip2, or zip.

The bzip2 compression tool is recommended because it provides the most compression and is found on most UNIX-like operating systems. The gzip compression tool can also be found on most UNIX-like operating systems. If you need to transfer files between Linux and other operating system such as MS Windows, you should use zip because it is more compatible with the compression utilities on Windows.

Compression Tool File Extension Uncompression Tool
gzip .gz gunzip
bzip2 .bz2 bunzip2
zip .zip unzip

By convention, files compressed with gzip are given the extension .gz, files compressed with bzip2 are given the extension .bz2, and files compressed with zip are given the extension .zip. Files compressed with gzip are uncompressed with gunzip, files compressed with bzip2 are uncompressed with bunzip2, and files compressed with zip are uncompressed with unzip.

Bzip2 and Bunzip2

To use bzip2 to compress a file,The file will be compressed and saved as filename.bz2.  type the following command at a shell prompt:

bzip2 filename

To expand the compressed file , The filename.bz2 is deleted and replaced with filename.type the following command:

bunzip2 filename.bz2

You can use bzip2 to compress multiple files and directories at the same time by listing them with a space between each one:

bzip2 filename.bz2 file1 file2 file3 /usr/work/school

The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) and places them in a file named filename.bz2.

Gzip and Gunzip

To use gzip to compress a file, type the following command at a shell prompt:

gzip filename

The file will be compressed and saved as filename.gz. To expand the compressed file, type the following command:

 gunzip filename.gz

The filename.gz is deleted and replaced with filename. You can use gzip to compress multiple files and directories at the same time by listing them with a space between each one:

gzip -r filename.gz file1 file2 file3 /usr/work/school

The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) and places them in a file named filename.gz.

Zip and Unzip

To compress a file with zip, type the following command:

 zip -r filename.zip

filesdir In this example, filename.zip represents the file you are creating and filesdir represents the directory you want to put in the new zip file. The -r option specifies that you want to include all files contained in the filesdir directory recursively. To extract the contents of a zip file, type the following command:

unzip filename.zip

You can use zip to compress multiple files and directories at the same time by listing them with a space between each one:

 zip -r filename.zip file1 file2 file3 /usr/work/school

The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) and places them in a file named filename.zip.