Monday, January 10, 2011

Software/Package Management in Ubuntu/debian

Ubuntu's package management system is derived from the same system used by the Debian GNU/Linux distribution. The package files contain all of the necessary files, meta-data, and instructions to implement a particular functionality or software application on your Ubuntu computer.
Debian package files typically have the extension '.deb', and typically exist in repositories which are collections of packages found on various media, such as CD-ROM discs, or online. Packages are normally of the pre-compiled binary format; thus installation is quick and requires no compiling of software.

dpkg - dpkg is a package manager for Debian based systems. It can install, remove, and build packages, but unlike other package management system's, it can not automatically download and install packages or their dependencies. I shall show examples of dpkg to manage locally installed packages:

To list all packages installed ==> dpkg -l
To list all files installed by package specified as argument ==> dpkg -L {package-name}
To install local package ==> sudo dpkg -i {package-name}
To unistall a package ==> sudo dpkg -r {package-name}
There are lot of other options also which we can use with dpkg. For more details refer to man page of dpkg.

Apt-Get - The apt-get command is a powerful command-line tool used to work with Ubuntu's Advanced Packaging Tool (APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system.

Apt-get maintains a list of packages available on repositories specified in /etc/apt/sources.list file. Unlike dpkg Apt-get automatically download the package from repository if available.

To install a new package ==> sudo apt-get install {package-name}
To remove a package ==> sudo apt-get remove {package-name}
To update index of packages ==> sudo apt-get update
To upgrade packages ==> sudo apt-get upgrade
You can find more detailed information on apt-get by typing man apt-get.

There are other tools also available like Aptitude to do all this. Ubuntu have very good graphical interfaces to do all above written stuff but if you are a Linux fan, you would love to do it from Command-line

Managing repositories for apt-get - In addition to the officially supported package repositories available for Ubuntu, there exist additional community-maintained repositories which add thousands more potential packages for installation. Two of the most popular are the Universe and Multiverse repositories. These repositories are not officially supported by Ubuntu, but because they are maintained by the community they generally provide packages which are safe for use with your Ubuntu computer.

  • Packages in the Multiverse repository often have licensing issues that prevent them from being distributed with a free operating system, and they may be illegal in your locality.
  • Be advised that neither the Universe or Multiverse repositories contain officially supported packages. In particular, there may not be security updates for these packages.

You can add/remove repositories either from UI by going to System->Administration->Software Sources or by editing /etc/apt/sources.list file.

Saturday, January 8, 2011

Link Files in Unix/Linux

Links in Unix - Links are used in Unix/Linux for better managebility of file system.

Command we use for linking two files is ln.

ln -[options] existingfilename newfilename

Common options -

-f ---> Link files without questioning the user, even if the mode of target forbids writing.
-s ---> Creates a symbolic link to existingfilename with the name of the newfilename.

Hard Link - A hard link is a reference to a file or directory that appears just like a file or directory, not a link. Hard links only work within a filesystem. In other words, don’t use hard links between mounted filesystems. A hard link is only a reference to the original file, not a copy of the file. Basically points to a file's inode. So if you delete one file , it can still be accessed from other hard link available.

How do we check hard links -
If we want to check hard links in one specific directory we can simple use ls -i command which list the files with their respective inode number.

If we want to find all files hard linked with one file we can use find command in following way -
find {location} -xdev -samefile {filename}

ls -lrt shows the number of links to a file. The column next to permissions shows number of links to that file.


Soft Link - A soft link/symbolic link is a pointer to another file or directory. It can be used just like the original file or directory. A symbolic link appears in a long listing (ls -l) with a reference to the original file/directory. A symbolic link, as opposed to a hard link, is required when linking from one filesystem to another and can be used within a filesystem as well.

How to find soft links -
If we do ls -lrt in one directory it shows the soft links with target files.
Find all links in system - find {location} -type l


How to unlink files -

unlink filename

PS: unlink and rm both remove the files, the difference is that unlink is a system call, rm is a shell utility that calls unlink.

Keep checking for more posts on Unix/Linux