Linux How-To

Information here has been tested on one of these: Ubuntu, MacOS, CentOS, SunOS, Solaris


  • Hidden files have a '.' before the file name.
  • Most icons are *.svg
  • if you hit TAB twice, bash will complete the command name
  • The redirection directives, > and » can be used on the output of most commands to direct their output to a file. » appends.
  • Ctrl+C (terminates a command) differs from Ctrl+Z(command in background)

Farsi Dictionary

  • xfardic = farsi dictionary- dictionary DBs are separate
  • stardict is the best

How to write shell scripts

Running a *.bin file

First make it executable(chmod +x a.bin) and then run it normally

Set Path

We need to set PATH in .bashrc file in your home to keep something in your path permanently.
Do sudo gedit ~/.bashrc and add export PATH=$PATH:your_directory:another_directory then restart your terminal

Backgammon Game


Html Editor

bluefish, kompozer(old name=nvu)

Image Editor



when we install a package with "sudo make install" then we should be able to uninstall it with "sudo make uninstall"


For best result I choose Rendering: "Subpixel smoothing (LCDs)", Smoothing: "Subpixel (LCDs)", Hinting: "Slight", Subpixel Order: "RGB" and Resolution around 89.

Install MS Fonts

Many apps (such as document viewer) will look better now: sudo apt-get install msttcorefonts

Partition Management

gparted for partition management

Spell check in OpenOffice

For open office to spell check the doc you have to install the language specific myspell from synpatic

Mount windows ntfs

mount windows: put /dev/sda1 /media/win ntfs defaults 0 0 in /etc/fstab and then do : mount -a
to see the partitions do fdisk -l


  • "sudo apt-get install ssh" installs both openssh-server and openssh-client.
  • To be connected from outside you need to open the port 22 in your firewall as well. Now you can ssh from a Linux machine or use putty from Windows machines.
  • Some logs of ssh can be found in /var/log/auth.log or /var/log/secure or you can check the "last" command. Configs are in /etc/ssh.
  • Add "PermitRootLogin no" and "MaxAuthTries 3" to the end of config file for security.
  • If you get this error: "error: Bind to port 22 on failed: Address already in use." then uncomment "ListenAddress" and keep "ListenAddress ::" commented.
  • ssh_config is for client and sshd_config is for server (daemon) configuration.

ssh and Filezilla

without below filezilla does not work in ubuntu(7.10)

  1. sudo apt-get install openssh-server


when ubuntu does not understand the graphics card or cant find the exact driver for it, it will pick the generic one. then you need to adjust resolution in /etc/X11/xorg.conf sometimes.
if you install nvidia driver then you can configure it using nvidia-settings command.

Anjuta and c/c++

install anjuta with apt and then install autogen from synpatic as well
also need to apt-get install build-essential
This is enough to run anjuta and c compile c files.


For making gnome projects we need to install some more stuff like: automake,autoconf,libtool,intltool,glib-dev,glade-dev,libgnomeui-dev,…

JRE and Firefox

If you want to add your own JRE to firefox then in firefox directory (probably /usr/lib/firefox/plugins/) do the following:
ln -s <jdk or jre location>…/plugin/i386/ns7/
and then restart firefox.


In .bashrc add export JAVA_HOME=/home/reza/java/jdkxxxx

JavaEE Installation

  • chmod +x <the bin file> and got the cannot open shared object file: No such file or directory
  • In "/usr/lib" do "sudo ln -s" and this solved the issue


  • Using apt is better : sudo apt-get install mysql-server
  • To install mysql administrator: sudo apt-get install mysql-admin
  • To install mysql query browser: apt-get install mysql-query-browser

Installing Flash

download, extract and run installer!

Farsi font and firefox:

just do this and restart firefox. Do not change ff settings:

sudo apt-get install ttf-farsiweb xfonts-intl-arabic xfonts-intl-european xfonts-intl-phonetic
wget -c
wget -c
wget -c
sudo mkdir /usr/share/fonts/truetype/ttf-persian-fonts
sudo unzip -d /usr/share/fonts/truetype/ttf-persian-fonts
sudo tar zxvf tahoma.tar.gz -C /usr/share/fonts/truetype/ttf-persian-fonts
sudo tar zxvf bfonts.tar.gz -C /usr/share/fonts/truetype/ttf-persian-fonts

Install Apache

In apache site there was no install version for Linux. There was just source code that your can make and install (Read this: or install it the following way. It will be a bit different from what it is in Windows:

sudo apt-get install apache2
sudo /etc/init.d/apache2 restart
  • The main configuration file will be located at /etc/apache2/
  • Type a2enmod command to see the modules you can install, enable or disable modules
  • To install a module: sudo a2enmod proxy_http
  • In /mods-enabled/proxy.conf default is Deny and you probably want to change Deny to Allow from all
  • To change the default /var/www/ location you can do so by changing it in /etc/apache2/sites-available/default
  • Notice that the files in sites-enabled are links from sites-available

Apache2 with PHP

You can install Apache2 first and then install php (the version you want for instance php5) using apt-get; it will install related libapache2-mod-php5 packages too. After restarting apache you are ready to go. The php config files are under /etc/php5 in case of version 5. Just put a php file under /var/www/ and test. Also read This.

MySQL with PHP

You just probably need to install php5-mysql package if you have already installed mysql and php. Read

Build and Install from Source

You must have the compiler tools installed. They all come with the package build-essential, … in Synaptic.

./configure: To check for dependencies and then create the makefile.
sudo make: To Compile
sudo make install: Normal install
run make clean: To remove the temporary files.

To uninstall the program you run sudo make uninstall.

SVN Client

I use RapidSvn. It is a GUI client for svn. You can install it using apt-get.

Remote Desktop

The best one to work between Windows and Linux is TightVNC.
Get it using sudo apt-get install tightvncserver and run it using tightvncserver command, and for viewer: sudo apt-get install xtightvncviewer.
It also has a Java viewer that can be downloaded from its site. The Java viewer can be run by: java VncViewer HOST PORT 5900
tighvncpsswd for changing password. tightvncserver -kill to kill a server instance.

FTP server

I installed vsftpd. You can configure it in /etc/vsftpd.conf and restart it using /etc/init.d/vsftpd restart.
SFTP (port 22 = SSH port) is more secure than FTP (port 21). In /etc/ftpusers you can find the list of banned ftp users.

Adding Packages to Software Repository

In addition to using menu you can add them directly into /etc/apt/sources.list

Installing Tomcat

I downloaded it from apache site but I was getting "The BASEDIR environment variable is not defined correctly" error although I had CATALINA_HOME in my env. I just did "chmod +x *.sh" in the bin folder of Tomcat and it started working :D

Share Folders Between Ubuntu and Windows

Accessing Ubuntu from Windows XP:

  • Install samba on Ubuntu
  • Edit /etc/samba/smb.conf
  • Add this portion to the end of the file:
        comment = mi home         
        path = /home/reza/share        
         read only = No         
        guest ok = Yes
  • Change the workgroup to your Windows workgroup
  • There are a lot of things you can change in this file!
  • Now on Windows try \\your-linux-machine and you should be good.

Accessing Windows XP from Ubuntu:

  • Just do smb://your-windows-machine

Define DNS in Ubuntu server

In Ubuntu server 8.10 I was unable to find the file /etc/resolv.conf so I created one!! and put my nameservers there like:

Then "sudo /etc/init.d/networking restart" and all done! The solves the problem of pinging with computer name.

Define Static IP

Do it in /etc/network/interfaces
Something like this:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static

Read this:

How to Change Computer Name

Do it here: /etc/hostname

How to change command prompt

You need to change the PS1 shell variable. This is a simple colorful prompt that suits a black background. It just shows the current path:

PS1=$'\\[\E[0;36m\\]${PWD}\\[\E[1;34m\\]> \\[\E[1;37m\\]'

Add this to the end of your .bash_profile or .bashrc in Ubuntu. Also in Ubuntu you can just simply uncomment "force_color_prompt=yes" from within .bashrc.

Program Launcher

GnomeDo is the best. It can search for files/ programs, etc and run them.
It also has a number of plugins with useful actions. For example a plugin to index pidgin buddies so that you can search them or send them messages, etc.
Also can you Launchy which works best on Windows.

Convert between rpm, tgz and deb

Use alien.

How to open rar files

Install unrar through apt and then you can open rar files either using command line or Gnome Archive Manager (File Roller).


Gconf-editor is a GUI for gconftool. Gconf-editor gives users the ability to access settings stored in the XML-based GConf configuration database. It is used primarily by developers to debug applications, or by power users to edit hidden and complex settings. It abstracts the values from the GConf database and presents them in an interface similar to Microsoft Windows' registry editor.

Kill processes by name

We list pid of processes by searching their names and then kill them

for i in `ps -C "vuze java" -o pid=`
  kill -9 $i


  • The rules are stored in the file /etc/sysconfig/iptables and are applied whenever the service is started or restarted, including when the machine is rebooted.
  • Firewall rules are only valid for the time the computer is on; so, if the system is rebooted, the rules are automatically flushed and reset. To save the rules so that they are loaded later, use the following command: /sbin/service iptables save
**Example: iptables -A chain -j target**
The -A option appends a rule at the end of an existing ruleset. The chain is the name of the chain for a rule.
 The three built-in chains of iptables (that is, the chains that affect every packet which traverses a network) are 
INPUT, OUTPUT, and FORWARD. These chains are permanent and cannot be deleted. The -j target option specifies
 the location in the iptables ruleset where this particular rule should jump. Some built in targets are ACCEPT, DROP, and REJECT.
New chains (also called user-defined chains) can be created by using the -N option. Creating a new chain is useful
 for customizing granular or elaborate rules.
sudo iptables -L list the current rules
sudo iptables —flush delete all the rules

Run a script at startup

Add your stuff to /etc/rc.local to be executed after other system initialization scripts.

Visual diff and merge tools


Adding a service

To create a service from a script add:

#chkconfig: 2345 80 05
#description: James Mail Server

to the start of the script after #!/bin/bash. These lines are needed by chkconfig to determine how to establish the initial runlevels to add the service as well as set the priority for the start-and-stop script execution order.

These lines denote the script will start James server for the runlevels 2, 3, 4 and 5. In addition, the start priority will be set to 80 while the stop priority will be 05. After this do: chkconfig —add the_script

scp/ssh without asking for password

If you want to scp/ssw to a remote machine without being asked for password then you need to make a private/public key in the source machine. Type "ssh-keygen -t rsa" and enter for all questions. This gives a pair of public/private keys. Copy the content of your public key to the file (this is not a dir) "~/.ssh/authorized_keys" of all your remote linux machines and your are done.

How to execute a command on a remote machine

ssh username@remote_machine command for example ssh|azer#|azer ls
If you have set up public/private keys between the two machines then it will not ask for password.

Modify Key Maps

Using 'xev' you can see the code associate to every key then using 'xmodmap' you can replace key functions. The following code replaces page forward/backward keys on Thinkpad T61 with pageup/page down functionality:

Key codes from xev:
166 0x1008ff26 (XF86Back) 0x0000 (NoSymbol) 0x1008ff26 (XF86Back)
167 0x1008ff27 (XF86Forward) 0x0000 (NoSymbol) 0x1008ff27 (XF86Forward)
112 0xff55 (Prior) 0x0000 (NoSymbol) 0xff55 (Prior)
117 0xff56 (Next) 0x0000 (NoSymbol) 0xff56 (Next)

#page up
xmodmap -e 'keycode 166 = 0xff55'
#page down
xmodmap -e 'keycode 167 = 0xff56'

If you want to have these new mapping from the startup you can put the following code in a file called .xmodmaprc in your home:
keycode 166 = 0xff55
keycode 167 = 0xff56

Simple OCR

You need to install gocr. then the following command will output the text in the jpg image:

djpeg -pnm -gray someimage.jpg | gocr -

Proxy server

Squid is a Proxy server that I tried under Ubuntu. See this to add authentication to it. Default port is 3128

Programming under Ubuntu

  • Gambas (A VB like environment)
  • Python

Ubuntu Guest

If Ubuntu (tried 10.10) is a guest on VirtualBox and you do not get proper resolutions then install guest additionals and all will be fine after a restart.

Ubuntu Behind Proxy

If setting Network Proxies does not work which is my case in 10.10 you can add proxies in /etc/apt/apt.conf like this:

Acquire::http::proxy "http://username:pass@proxy:port//";
Acquire::ftp::proxy "http://username:pass@proxy:port//";
Acquire::https::proxy "http://username:pass@proxy:port//";

at least it helps in doing apt-get.

How to make VirtualBox guest visible from outside

I have a Tomcat server on an Ubuntu guest in Oracle VirtualBox and want that to be visible from the host or outside world. For this we need to do port forwarding from host to guest.

  1. Stop the guest
  2. Go to the VB directory in Windows and type VBoxManage.exe modifyvm "ubuntu1010" —natpf1 "webport,tcp80808080"
  3. ubuntu1010 is the name of my VB guest instance.
  4. webport is just a name that can be used to remove this port forwarding
  5. The rest of the command says to forward tcp request on port 8080 in host to 8080 in guest

Read more on :

Fixing Dos Partitions

I recently had problems with my USB drives. It was a FAT32 and has become readonly on Ubuntu but the command "sudo dosfsck -a -v /dev/sdf1" rescued me and made the drive RW again. It fixes dos filesystems

Mac To Ubuntu

One way to connect to Ubuntu from Mac is installing Netatalk on Ubuntu.

Terminal Too Wide Error

Try "stty columns 120"

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License