Use sudo

1. when you forget to run a command with sudo, instead of retyping the command you could use
# to run the last command in history with sudo
sudo !!
# or you could use if you prefer
sudo !-1
# run the second to the last command in the history with sudo
sudo !-2 
2. To have an interactive shell as root:
sudo -i
# or
sudo su -
3. when you use vim and forget to type sudo
:w !sudo tee %

A command line tool to record your terminal activity

Script is a simple command line tool to record your terminal activity, including your command history and outputs of the commands, basically everything showed on the terminal screen.
To use it
script [file_name]
#or
script
By type this command, script will create a typecript file at your current directory if you do not provide a file name in the command.
After finished, execute exit to save your command history and outputs.

Obtain IP address of Linux

Two commands used to obtain ip address of linux machine:
#set 1
#displays all cuurentlly active network interfaces
/sbin/ifconfig
# IP address in the output of this command is you IP
/sbin/ifconfig eth0 | grep 'inet addr:'
#set 2
/sbin/ip addr list
/sbin/ip addr list eth0

Restore CentOS top panel

Have you ever messed up top panel of your CentOS?
Here is a way to restore it to it's default.
sudo mv ~/.gconf/apps/panel ~/.gconf/apps/panel.bak
sudo reboot

Disable system beep for CentOS

Here is way to disable the system beep for CentOS
# unloading the pcspkr module: 
rmmod -v pcspkr
In addition, add the following line in /etc/rc.d/rc.local file to automatic disable it during boot.
/sbin/rmmod pcspkr
if you ever want to re-enable the speaker, run the following command:
/sbin/modprobe pcspkr

Copy files between Linux Systems using scp

1. Copy file from a remote server to local server: copy directory pathogenbase from remote server /srv/www/ directory to current working directory

scp -r user_name@remote_ip:/srv/www/pathogenbase/ .
2. Copy file_name from local server to remote server: copy file_name from /srv/www on local server to remote server /srv/www/
scp /srv/www/file_name user_name@remote_ip:/srv/www/
3. If you are copying files between windows and Linux you could use winSCP.

Eclipse and CentOS

1. install
$ sudo yum groupinstall Eclipse
2. configuration

3. install Django
$sudo pip install django
4. install PyDev: use eclipse install new software feature by adding http://pydev.org/updates

use rdesktop to access windows desktop from CentOS

CentOS comes with rdesktop installed:
run the following command to access your windows desktop:
rdesktop -u user_name -f ip_address
To toggle full screen mode, use
ctrl+alt+enter

Problems and solution


1. While suing this program you may encounter WARNING: Remote desktop does not support colour depth 24; falling back to 16 if your windows system is Windows XP.
To fix the problem go to windows machine:

# go to Start -> Run -> gpedit.msc
# In the Group Policy Editor, navigate to Local Computer Policy -> Computer Configuration -> Administrative Templates -> Windows Components -> Terminal Services, and double-click on the 'Limit maximum Color Depth' object. Set the item to "Enabled" and set "Color Depth" to "24 bit"
2. One other problem you may encounter is: Idle time over and rdesktop closed the connection. To fix this problem:
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows NT\terminal services\MaxIdleTime
It was set to 900,000 mSec. or 15-minutes. I increased the value to 10,800,000 or 3-hours.

Dual Head display on CentOS using ATI Radeon HD 3450

Go to official AMD site to download the official linux driver for this video adapter:
1. install the driver:
$ sudo sh ./ati-driver-installer-x86.x86_64.run 
#Here I choose custom installation and opt out Catalyst Control Center.
2. Configure the driver after installation and enable dual head display
$ sudo aticonfig –initial
# if your second display is at the right of your main display
$ sudo aticonfig --initial=dual-head --screen-layout=right

Disbale SELinux on CentOS

Sometimes you want to disbale SELinux on your CentOS machine, here is how:
[sourcecode language="text"]
Edit /etc/sysconfig/selinux  and change SELINUX=disabled
[/sourcecode]

After you disable SELinux, you need reboot your system to make it take effect.

Diff results explanation

$diff from_file to_file

The results of the command look like:

change-command
< from-file-line
< from-file-line...
---
> to-file-line
> to-file-line…

change-command means if you modify from_file according to this command you will get the same file as to_file.

$ diff /tmp/1.txt /tmp/2.txt
1d0: delete 1.txt line 1
< aaa: content in line 1 of 1.txt
3c2: change line 3 in 1.txt to line 2 in 2.txt
< ccc: content in line 3 of 1.txt
---
> c c: content in line 2 of 2.txt
7a7: add line 7 to 1.txt from line 7 in 2.txt
> hhh

Lines like "1d0" and "3c2" are the coordinates and types of the differences between the two compared files, while lines like "< aaa" and "> hhh" are the differences themselves.

Diff change notation includes 2 numbers and a character between them. Characters tell you what kind of change was discovered:

d – a line was deleted
c – a line was changed
a – a line was added

Install VSFTPD on CentOS Enable local user to log in to their home directory

Install VSFTPD on CentOS, enable L

$ yum install vsftpd

Make necessary configurations for vsftpd

$ vim /etc/vsftpd/vsftpd.conf

There are many configuration options, configure according to your needs.

Disable anonymous FTP

anonymous_enable=NO

Allow local user to log in

local_enable=YES

trap FTP users in their own /home/username directory

chroot_local_user=YES

 

Start the vsftpd service

$ /etc/init.d/vsftpd start

 Turn on vsftpd service on boot

$chkconfig vsftpd on

 

If you can not get access to the FTP server, check the iptables at /etc/sysconfig/iptables to allow whichever port you used for your vsftpd

and restart the iptables /etc/init.d/iptables restart

 

Find and replcae across multiple files in linux

I have been looking a better way to replace certain string in a file accross many folders under one directory and come up with two sultions.

$ find . -name "*.html" -print | xargs sed -i 's/base_site.html/base.html/g'
$ grep -lir "base.html" * | xargs sed -i 's/base.html/base_site.html/g'

The differences are find-- looking for files based on the file names, means it only modifies certain type of file

                                grep-- looking for files based on the content of the file, any files contains "base.html" string will be replaced.

 

Installing HTSeq on CentOS 5.4

Installing lapack, blas and atlas on CentOS 5

1. Installing lapack and atlas on CentOS 5.4 is very simple if you have enabled EPEL and RPMForge on CentOS.

For how to enable this repositories, go to http://wiki.centos.org/AdditionalResources/Repositories

$ sudo yum install atlas.x86_64 lapack.x86_64

2. Install numpy and scipy make sure you use the correct pip tool

$ sudo pip2.7 install numpy

Before installing Scipy do the followings to prevent the failure:

sudo ln -s /usr/lib64/liblapack.so.3.0.3 /usr/lib64/liblapack.so

$ sudo ln –s /usr/lib64/liblapack.so.3.0.3 /usr/lib64/liblapack.so
$ sudo ln –s /usr/lib64/libblas.so.3.0.3 /usr/lib64/libblas.so

then do the installation

$ sudo pip2.7 install scipy

3. Install HTSeq

$ sudo pip2.7 install HTSeq

 Test installation:

$ python2.7
>>>import HTSeq
 

Convert pdf file to eps

I was looking for a tool which can convert pdf file to eps file. pdftops comes to my attention.

usage:

pdftops -eps name.pdf

which can convert the name.pdf file to name.eps.

Should you really have to wait longer time to change your pass word on Linux?



When you try to change the pass word for a user on Linux, you may encounter "You must wait longer to change your password".  Do you really need to wait longer time to change the pass word? No! You can use chage command to solves this kind of issue :

The following command will list policies for your pass word.

$ chage -l username


Last password change                                    : Feb 08, 2012
Password expires                                        : Apr 08, 2012
Password inactive                                       : Apr 08, 2012
Account expires                                         : never
Minimum number of days between password change          : 1
Maximum number of days between password change          : 60
Number of days of warning before password expires       : 14


In this case, your password policy specifies that the minimum number of days between password changes is 1 day.  You can change this attribute to 0 to make enable pass word change right now. To change the policy for this user, use :

$ chage username

Changing the aging information for username
Enter the new value, or press ENTER for the default

Minimum Password Age [1]: 0
Maximum Password Age [60]:
Last Password Change (YYYY-MM-DD) [2012-02-08]:
Password Expiration Warning [14]:
Password Inactive [0]:
Account Expiration Date (YYYY-MM-DD) [1969-12-31]:

-M option: which can be used to specify the maximum number of days the password is valid. combine 99999, you could disable password expiration.

$ chage -M 99999 user_name

Create a new Git Remote Repository

The following steps are creating a remote Git Repositories and push a local copy of a project into the newly created repositories:

#On local machine
if you want to ignore some files or folders from putting them in the repository, you could create a .gitignore file before running git add .
$ cd foo_project
$ git init
$ git add *
$ git commit -m "initial msg"
(Do not forget to do this step, or you will enconter "Git error: src refspec master does not match any")


Now, create the repository on your Git server. All of my git repositories are located at /usr/local/git_root/ of the remote server
#On remote machine
$ mkdir git_root/
$ cd /usr/local/git_root/


Create your new project git repo as a bare Git repository

$ mkdir project_name.git
$ cd project_name.git/
$ git --bare init

Make sure permissions are set properly. These are common options I use for my shared repositories

$ git config core.sharedrepository 1
$ git config receive.denyNonFastforwards true
$ find objects -type d -exec chmod 02770 {} \;

#The core.sharedrepository flag tells git to keep everything group readable and writable.
#The receive.denyNonFastforwards flag makes sure that merges can't happen when you push to the repo.
You have to do the merges on your local machine, and then push the result.

Now, go back to your local repository, and add the newly created remote repository so it tracks from the remote repository (origin).
#On local machine, in your git project
adding a remote by:

git remote add origin ssh://ip_address_of_remote_server/usr/local/git_root/project_name.git
git remote add origin user_name@ip_address:/usr/local/git_root/EMAN2.git
(I used this command in my case)
git push -u origin master

Install R develop version and RPy2 on CentOS 5.5

Prepare the environment

Before configure and compile R source code, I did the following updating of CentOS in order to support R capabilities by installing these packages:

[sourcecode language=""]
libtiff libtiff-devel
libpng libpng-devel
libjpeg libjpeg-devel
cairo cairo-devel
libX11 libX11-devel
libXt ibXt-devel
readline readline-devel
[/sourcecode]

and in order to produce the pdf version of the R-manual, I also installed all search results of

[sourcecode language="bash"]
yum search tetex except tetex-doc
[/sourcecode]

The RPy2 requires that you enabling R-shlib when you install R package. To do so you can build your own R package from source code.

1. donwload R source code: from http://cran.r-project.org/src/base/R-2/

[sourcecode language="bash"]
./configure --enable-R-shlib
[/sourcecode]

Here are my configuration results:

[sourcecode language=""]
R is now configured for x86_64-unknown-linux-gnu
Source directory:          .
Installation directory:    /usr/local
C compiler:                gcc -std=gnu99  -g -O2
Fortran 77 compiler:       gfortran  -g -O2
C++ compiler:              g++  -g -O2
Fortran 90/95 compiler:    gfortran -g -O2
Obj-C compiler:
Interfaces supported:      X11, tcltk
External libraries:        readline
Additional capabilities:   PNG, JPEG, TIFF, NLS, cairo
Options enabled:           shared R library, shared BLAS, R profiling, Java
Recommended packages:      yes
configure: WARNING: inconsolata.sty not found: PDF vignettes and package manuals will not be rendered optimally (as for this warning, specific fonts is not found.)
[/sourcecode]

 

2. Continue the following steps to complete installing R

[sourcecode language="bash"]
make
make check
make install
[/sourcecode]

some other errors you may encounter:

[sourcecode language=""]
configure: error: no acceptable C compiler found in $PATH  --install gcc gcc-c++
configure: error: No F77 compiler found --install compat-gcc-34-g77 gcc-gfortran
configure: error: --with-x=yes (default) and X11 headers/libs are not available  --install libXt-devel
[/sourcecode]

 

3. Install RPy2:

[sourcecode language="bash"]
/opt/python2.7/bin/easy_install rpy2
[/sourcecode]

You could use python2.7 if you have made a symbolic link in /usr/bin/python2.7 by

[sourcecode language="bash"]
ln -s /opt/python2.7/bin/python /usr/bin/python2.7
[/sourcecode]

** I had encountered a problem showing that lpython2.7 cannot be found, to solve this problem I created a symbolic link

[sourcecode language="bash"]
cd /usr/lib64
ln -s /opt/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
ln -s libpython2.7.so.1.0 libpython2.7.so
[/sourcecode]

If you have more than one R package installed on your system you may encounter some errors, like "rpy2.rinterface.baseenv.get("show") show not found" when you try to use the rpy2 package.

solution:
configure the  /etc/ld.so.conf.d/R-x86_64.conf file, create the file if the file does not exist Put the path of the R package whic you used to build your rpy2 into this file. Mine is /usr/local/lib64/R/lib.

Run /sbin/ldconfig
You may solve the problem by now.

3. install libraries in R

[sourcecode language="bash"]
sudo  R
install.packages('package_name')
[/sourcecode]

pay attention to the location of the installation of new packages "/usr/local/lib64/R/library/e1071/libs"
Sometimes when you install a package and it requires at least certain version of the R, you could download the source code of the package and do the following installation:

[sourcecode language="bash"]
install.packages("/path/to/the/packages/source/file", repos=NULL, type="source")
[/sourcecode]

How to find the procss using specific port and kill it

I am using PyDev in Eclipse on CentOS. Eclipse crashes sometimes and leaves python still using port 8000. Before you can restart the development server, you have to kill the previous process, to do so,
$ sudo /usr/sbin/lsof -w -n -i tcp:8000
which will list the process pid using port 8000

COMMAND    PID  USER   FD   TYPE DEVICE SIZE NODE NAME
python2.7 6211 htang    3u  IPv4 157102       TCP 127.0.0.1:irdmi (LISTEN)

$ sudo kill 6211
which will kill process 6211.

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...