Category Archives: linux

How to disable-enable touchpad in ubuntu terminal


STEP 1: Determine the device id (the device name should be something with touchpad or glidepoint)

xinput list

STEP 2: Disable it (e.g. here the device id is 13)

xinput set-prop 13 "Device Enabled" 0

you can also dis/enable some other devices.
You may run the command during session startup

Original link: cannont open shared object file: No such file or directory.

after installed nginx, got some error message when raunch as: `/opt/nginx/sbin/nginx`

/opt/nginx/sbin/nginx: error while loading shared libraries: cannot open shared object file: No such file or directory

still i’m sure i’ve installed the latest pcre. and also i can find the with:

find /usr/ -name ""

ok, why cannot found the in `/user/local/lib` ??

strace /opt/nginx/sbin/nginx

So how does the dynamic loader know where to look for executables? As with many things on Linux, there is a configuration file in /etc. In fact, there are two configuration files, /etc/ and /etc/ Note that /etc/ specifies that all the .conf files from the subdirectory should be included.
Dynamic library configuration

ldconfig -p | grep ""

not found any matches.

so the problem is the dynamic loader not serach for my lib dir in /usr/local/lib

Then Use shared libraries in /usr/local/lib??

For the current session you can

export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

or to make the change permanent you can add /usr/local/lib to /etc/ (or something it includes) and run `ldconfig` as root.

keep reading. If not, read aboout ldconfig first.

after all, grep it:

ldconfig -p | grep "" (libc6,x86-64) => /usr/local/lib/

ok, got it!
run again /opt/nginx/sbin/nginx

that all..

these are some keyword need to read for details: `strace`, `ldconfig`, `/etc/ld.conf`, `/etc/ld.conf.cache`.

Input/Output Error: Bad Blocks: How To Restart Linux

-bash: /usr/bin/du: Input/output error

$ du
-bash: /usr/bin/du: Input/output error
$ reboot
bash: /sbin/reboot: Input/output error
$ shutdown -r now
bash: /sbin/shutdown: Input/output error


If the above reboot commands doesnot work try either forced reboot or shutdown

# Forced Reboot
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

# Forced Shutdown
echo 1 > /proc/sys/kernel/sysrq
echo o > /proc/sysrq-trigger

see also for details

Upgrade Bash to 4+ on OS X and Use GNU Instead of BSD Command

Install latest bash

Install by brew for OS X user brew install bash

Compiling bash with source code:

  • Add /usr/local/bin/bash to /etc/shells
  • Change the default shell with chsh -s /usr/local/bin/bash
  • To see your current version of bash do the following: echo $BASH_VERSION

Install and Use GNU Command Line Tools on Mac OS X

If you are moving onto Mac OS X from Linux, you would probably find out that the command line tools shipped with Mac OS X are not as powerful and easy to use as the tools in Linux. The reason is that Mac OS X uses the BSD version command line tools, which are different from the Linux version, while they are both compliant with POSIX standards.

  • Install the GNU Command Line Tools

    Get the latest GNU Coreutils and install to /usr/local/coreutils/

    tar xzf coreutils-8.22.tar.xz && cd coreutils-8.22
    ./configure --prefix=/usr/local/coreutils-8.22
    sudo make install
    sudo ln -sf /usr/local/coreutils-8.22 /usr/local/coreutils
  • Enable GNU coreutils, add coreutils bin folder to $PATH

    add script to .profile or .bash_profile

    export PATH="/usr/local/coreutils/bin:$PATH"


How to: Check the bash shell script is being run by root or not

Sometime it is necessary to find out if a shell script is being run as root user or not.

When user account created a user ID is assigned to each user. BASH shell stores the user ID in $UID variable. Your effective user ID is stored in $EUID variable. You can

Old way…

You can easily add a simple check at the start of a script:


# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1

New way: Using EUID

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1

Example: Mount /dev/sdb1 only if you are a root


if [[ $EUID -ne 0 ]]; then
  echo "You must be a root user" 2>&1
  exit 1
  mount /dev/sdb1 /mnt/disk2

Reference from

The final version function checkRoot

checkRoot() {
    if [ "x$EUID" = "x" ] ; then
      EUID=`id -u`
    if [ "$EUID" != 0 ] ; then
      case "`uname 2>/dev/null`" in
          # Cygwin: Assume root if member of admin group
          for g in `id -G 2>/dev/null` ; do
            case $g in
              0|544) root=t ;;
          done ;;
      if [ $root != t ] ; then
        echo "$self: You must run this as root" >&2
        exit 1

Create a socket proxy by ssh port forwarding

Enable TCP Forwarding by sshd server

cat /etc/ssh/sshd_config

Here are some example. First let’s restrict the users who are allowed to forward TCP sessions:

# SSH1, SSH2, OpenSSH
AllowTcpForwarding no

and then at the end of the file put

Match User allex,john,andy
    AllowTcpForwarding yes

Or better, allow specific ports per user groups:

AllowTcpForwarding no
Match Group admins
AllowTcpForwarding yes
Match User john,andy,ted
AllowTcpForwarding yes

After all, restart openssh-server,

/etc/init.d/sshd restart

Use ssh -D port forwarding create a local socket proxy server

# Create socket proxy channel
ssh -CfNg -D user@host &>/dev/null &

Note: man ssh for more details,

  • -C Requests compression of all data
  • -f Requests ssh to go to background just before command execution.
  • -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
  • -g Allows remote hosts to connect to local forwarded ports (if just use local env AVOID IT)
  • -D Specifies a local “dynamic” application-level port forwarding.

Setup socket proxy in Browser.

There are lots of proxy tools for web browser extensions. (such as SwitchySharp for chrome.)

Use socks proxy for commands in terminal

export http_proxy=socks5:// https_proxy=socks5://

Reference Links

*nix find files by file size

*nix find 按文件大小查找文件:


find {/path/to/directory/} -type f -size +{size-in-kb}k


find /mp3collection -name '*.mp3' -size +5000k


find . -size -1k


YUM Hangs And Won’t Respond

keyword: yum hangs and won’t respond

ssh 到测试机更新subversion1.7, 需要删除之前的老版本,发现yum命令没有响应,提示 “yum hangs and won’t respond”,

rm -f /var/lib/rpm/__*
rpm --rebuilddb -v -v   
yum clean all

If that did not work, you can set a debug level, error level and timeout for yum in /etc/yum.conf:


The timeout is standard 30 seconds. So if a repository does not respond, the error takes 30 seconds to appear. Also try using yum without the plugins (like fastest mirror and priorities) with the option –noplugins. Now starting yum again should give you more info faster. Test with:

yum --verbose --noplugins info

Creating .deb-Packages With Checkinstall and install nodejs

Checkinstall is a nice tool to create simple .deb-packages that you can use in your local network (e.g. if you have to install the same piece of software on multiple computers running Debian). It lets you compile and install software from the sources like before, but with the difference that you end up with a simple Debian package which also means that you can easily uninstall the software you just compiled by running:

dpkg -r pkgname

I will demonstrate the use of checkinstall by compiling and installing the anti-virus software ClamAV on a Debian system.
This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind!

1 Install Checkinstall

apt-get install checkinstall

2 Install nodejs latest

apt-get install python g++
mkdir ~/nodejs && cd $_
wget -N
tar xzvf node-latest.tar.gz && cd `ls -rd node-v*`
# make install
checkinstall -D make install

This even works on the computer you compiled nodejs on! This is a nice way to install software from the sources and remove it if you are unsatisfied with the result.

NOTE: man dpkg for details pkg manager in ubuntu.

# install *.deb file

# list all package installed
dpkg -l

# list files of a Debian package without install
dpkg --contents PACKAGENAME