Difference between ./ and / (relative path and Absolute path)

In web or desktop programming/command-prompt use, we often come through such situations where we have to use relative/absolute paths. Is there are any differences between the notation “./” and “/” ?

./

Yes, there are! When you use “./” we mean an relative path. Suppose, you are in the location http://www.somedomain.com/some_directory/index.html

Now, if you want to insert an Image file which is located at this directory “some_directory”, you can write following code in your index.html page:

<img src = "./myimage.jpg">

If you want to use an image from a directory “another_dir” on level up, you should use “../”

<img src = "../another_dir/another_image.jpg">

Both some_dir and another_dir are located under the home of your domain (www.somedomain.com).

/

Now, let’s talk about using “/”

“/” means beginning from the Root level of your file system. Suppose, in Linux, you want to Change your current working directory to the directory “etc”. Since “etc” is placed just in the Root directory of your file system (see the image below), you should type something like this in your command-prompt:

cd /etc

If you tried with the command “cd ./etc”, it wouldn’t work! Why? Because “./” means beginning from the Current Working directory. Normally, when you use a command-prompt it selects the user’s Home folder as current working directory. So if you want to go to a directory based on root level, you should use “/” instead of “./”

Image: Unix/Linux File System. See, the folder “etc” stays just below the “root” or “/”

Advertisements

How to install program/Application/Software from .tar.gz / .tar.bz2 / .sh / .deb in Ubuntu Linux

Usually, .tar.gz or .tar.bz2 files are compressed files (just like zip files in windows). so, first you need to extract the contents of the .tar.gz file.

Extract a .tar.gz or .tar.bz file:

Right-click on the file and select Extract. Optionally, you can extract using a terminal:

.tar.gz files:

tar xzvf filename.tar.gz

.tar.bz2 files:

tar xjvf filename.tar.bz2

Now examine the extracted files! Normally, .tar.gz files contain source-codes which should be compiled to executable files. This means extra work to do. Instead, if the contents are .deb files or shell script (.sh format), you are lucky.

Step 2: Copy all the contents to desktop. Use it just for simplification!

Now depending on the types of extracted files, choose one of the following method:

Install from a .deb file:

Just double-click to open it!

Install from .sh file:

Open terminal and press following codes:

sudo chmod a+x ~/Desktop/filename
sudo sh ~/Desktop/filename

Install from Source files:

How to understand if the contents of .tar.gz file are source files? If the .tar.gz contains too many files, possibly files with .c or .cpp extentions, you may assume that they are source codes. You may try following methods to make executable (binary) files from source code:

Terminal job once again! Press following code:

cd ~/Desktop
./configure
make
sudo make install

or,

cd ~/Desktop
sudo apt-get install checkinstall
./configure
make
sudo checkinstall

As you can see, it’s always troublesome trying with .tar.gz or .tar.bz files! So better try Add/Remove Application or Synaptic Package Manager to install new programs in Ubuntu.

Create HTML by PHP – Easy and Quick Free HTML Generator!

To generate HTML Pages by PHP, we need to echo certain HTML tags, like <head>,<html>, external javascripts, css, <meta> tags blah blah blah…. it’s boring to print these tags each time you create a HTML page just to display a short message or short body. So I’ve created a template called html.php, you can include this source in your php page and call html_head() to generate the basic HTML tags!

Download Links

Latest Version |  Old Version | Mirror link

Why use it?

Wondering why use this generator? Just include the html.php in your source by calling

require_once('html.php');

Then call

html_head();

Bingo! the function html_head automatically generate following HTML tags for you!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html>
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<LINK REL="SHORTCUT ICON" HREF="http://i46.tinypic.com/111up8o.jpg">
			<meta name="description" content="Generated HTML by PHP" />
			<meta name="keywords" content="Generated HTML by PHP" />
			<title>Generated HTML</title>
                <style type="text/css">body{font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#333;}</style>

Cool! Of course, you can pass optional parameters in html_head() and customize the generated HTML.

Documentations

Pass optional parameters in html_head() function. The function has a definition like:

html_head($title = "Generated HTML", $css_array = "", $js_array = "", $start_body=false)

Explanation:

$title: Document Title

$css_array: Array of External CSS files (.css) to be included

$js_array: Array of External javascript files (.js) to be included

$start_body: If passed as true, it will print </head><body>, otherwise not.

You see, all parameters are optional. For Example, if you need to include myjs.js you can call html_head like this:

html_head("My New HTML File", "", array('myjs.js'));

Other Functions:

html_foot: prints </body></head>

html_error: Prints an Error/OK message. See source for more details.