2012/12/29

Linux Symbolic links: Soft and Hard links

What is a symbolic link? Why its important ?

Symlink (Symbolic link) is a reference to another file or directory. It allows you to point multiple file names to single inode that points to a physical block address on the disk.

Symlink's  are mostly used as a shortcut's, they can make your life a lot easier by making your directories of data available for you where you want it.

How do i make a symlink ?

Use the following option in ln command:

 -s, --symbolic
              make symbolic links instead of hard links

For example:

 ln -s file1 file1_symlink  
 ls -l
 -rw-r--r-- 1 m m 0 2012-12-29 14:57 file1  
 lrwxrwxrwx 1 m m 5 2012-12-29 14:58 file1_symlink -> file1  


How do i make a hard link ?


 ln file1 file1_hardlink  
 ls -l  
 -rw-r--r-- 2 m m 0 2012-12-29 15:03 file1  
 -rw-r--r-- 2 m m 0 2012-12-29 15:03 file1_hardlink  

What is the difference between soft and hard link ?

Most important difference between hard and soft is that soft link depends on the original file.

For example, if i create a soft link and delete the original file that i linked, i cannot access my file trough symlink anymore and it becomes broken link.

 m@srv:~/symlink_test$ cat file1_symlink   
 Hello World!  
 m@srv:~/symlink_test$ rm file1  
 m@srv:~/symlink_test$ cat file1_symlink   
 cat: file1_symlink: No such file or directory  

But in the case of hard link, my file is always accessible if there is one hardlink existing of the file

 m@srv:~/symlink_test$ cat original  
 Hello World!  
 m@srv:~/symlink_test$ ln original hard_linked  
 m@srv:~/symlink_test$ cat original hard_linked   
 Hello World!  
 Hello World!  
 m@srv:~/symlink_test$ rm original   
 m@srv:~/symlink_test$ cat hard_linked   
 Hello World!  

Also hard links do not link paths on different volumes or file systems, soft links do. Soft links also consume inodes but hard links always shares the same inode.

Where is the symbolic link stored ?

Symlinks are just references to a physical location of a file, if you make symlinks, its doesn't meant that you are losing disk space by creating a copies. Symbolic links are stored in the same place as inodes, inodes are the place where disks resides its block addresses. 

2012/10/30

App Engine Templates and CSS with Python

HTML is much easier to maintain in App Engine if you use templates. Templates are way of storing you HTML code, it also has syntax to show your application data where you want it to be.

Django's templating engine is included in webapp2 framework.

Here is a sample code how to render html template:

 import webapp2  
 from google.appengine.ext.webapp import template  
 class index(webapp2.RequestHandler):  
  def get(self):  
   self.response.out.write(template.render('index.html', {}))  
 app = webapp2.WSGIApplication([('/', index)])  

Just remember to store your html file in the same folder.

Then you probably want to add CSS to your project? Create folder called css (or whatever you want to call it) and add it as a static directory to your app.yaml:

This will map your "physical" css directory into <project url>/css url.

 - url: /css  
  static_dir: css  

Create your style.css file and refer it in index.html and you are done!

 <link href="css/styles.css" rel="stylesheet" type="text/css">  


2012/10/01

Add Workspaces to Windows using VirtualWin

There is definitely one very important function missing in Windows and that is Workspaces.

Workspaces are "virtual desktops" that you can switch on fly. For instance Workspace 1 can have your browser open, Workspace 2 your applications and Workspace 3 your music player and so on. This makes managing multiple windows alot more simpler and faster.


It didn't take long googling to find this desktop manager called "VirtualWin". VirtualWin is a free software licensed under the GNU General Public License. It works on many Windows operating systems (Win9x/ME/NT/Win2K/XP/Win2003/Vista/Win7)

It looked interesting and i wanted to give it a go.

Setting up application was easy, no need to configure anything if you want to go with default settings. By default VirtualWin has 2x2 workspaces that can be changed to whatever you want in Setup screen. You can bind your own hotkeys for swapping workspaces, default is Control-Alt-Arrows combination, same as in Ubuntu for example!

For me windows was hiding application icon that tells my current Workspace, so i had to change icon behaviour.

Control Panel\All Control Panel Items\Notification Area Icons


Moving windows between workspaces works with Alt-Windows-Right/Left, it feels bit weird since it moves you with the window to next workspace, this can be also changed by changing the bind command from "WIN: Move to next desktop and follow" to "WIN: Move to next desktop".

What a great piece of software, i can only wish that i would have discovered this earlier!

VirtualWin project page