WINLAB
 

Zhibin´s web templates

Zhibin ´s research

Zhibin´s web templates

Zhibin´s resume

Zhibin´s real life

Zhibin

 

 

 

 

 

 

 

UNIX User Guide

Command Usage Q&A

Go back to previous directory: cd -
Display only directories with ls: ls -d */
How to save and exit emacs? Ctrl-X and Ctrl-C
How to use tar? for extracting files? tar -xvf for compress files: tar -cvf
How to handle .gz file? gzip or gunzip
Use ping with address IP resolution: ping -sR cell
How to check disk usage? df
Quota for a user: du -sk  This will show the usage for this user in kilobytes.
How to print from xpdf? click print button, then "lpr -Plpco"
How to set file access control list? setfacl -s user:pkamat:rw-,user::rw-,group::---,other:---,m:rwx spwbde.pdf Also applied for the directory.
how to batch rename files? Use shell or perl program for file in *.htm ; do mv $file `echo $file | sed 's/\(.*\.\)htm/\1html/'` ; done # change .htm files to .html

Wrong LineFeed! DOS to UNIX text file format conversion

Use "dos2unix" command
open with vi, :set ff=unix , or set ff=mac, then save it
col -bx <file1 >file2

g++ and gcc

When I encounter some problems with gcc compile source code, probably cannot recognize finction as "sin" cos",
I use g++ to compile:
$g++ source1.c source2.c -o source

Plot with gnuplot

It is a tool to plot figures and curves , instead of MATLAB.
the two commands for print it:
gnuplot>set output "a.ps"
gnuplot>set term post
gnuplot>replot
gnuplot>quit

other options
gnuplot> set multiplot
gnuplot> set nomultiplot
gnuplt> clear
gnuplot > set xrange [20:50]
lp a.ps

Use Daily Cron Job

crontab -e to add some entry
crontab -l to list all jobs
file /etc/crontab
Or put something in /etc/cron.daily directory
 

Use AWK

Using AWK is more easy than perl to process TEXT file see
awk '$5 ~ /^1$/ { print ($3,$4,$5) >> "new_adj"}' scen_god

First, the $5 is a text separate default by space. It is mean the fifth element of each line
~ means match
^ means beginning with $ means end with ($3,$4,$5) is actually printed in the file separated with space, not comma
new_adj is the output file
scen_god is the input file
 

How to open XWindows application in another terminal?

In Linux or Unix, use "ssh -X" in your ssh process.
In Windows, use Exceed, then type
$xterm -display 10.0.0.1:0
10.0.0.1 is the IP address of the computer (not a NAT) which can be resolved by remote host.

How to handle "_" character in Regular expressions

_ is not special. But if it is combined with a variable like $aa_, PERL will interpret as a new variable $aa_, rather than $aa + '_'. So the correct way to put it in is:  ($aa)_.

For example, if $line ~= /^_($aa)_$/

Advanced Shell Tools

So what can you do with Regular Expressions? Lots! I don't have the time to go into each utility in detail right now, but all of these use regular expressions. Check their man pages for more detail on actual usage:

Command and Description
awk Pattern Scanning & Processing Language
cut Select columns from stdin
diff Compare & Select differences in 2 files
grep Search every line of a file for an occurance of a regular expression.
head Gives first few lines of specified file.
line Read in the first line of stdin
sed Edit streams of data
tail Select last few lines of a file (like head)
uniq Select unique lines & rows.
wc Count words, characters, & lines in a file.
 

Set up SSH passphrase between two machines

Basically, for a Public Key Encryption system to work.
Both two sides have to store the public key of each other.
Here, we have server and terminal:
Server store public key of client in $HOME/.ssh/authorized_keys
Clietn store public key of server in $HOME/.ssh/known_hosts

Attention: Each key is only one line ( one very long line) in the file.

Generally, client could trust the server if it like. So, Once this occurs:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the DSA host key has just been changed.
The fingerprint for the DSA key sent by the remote host is
14:b0:b4:42:01:5f:d6:20:69:4f:5b:e6:10:cb:65:cf.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:3
DSA host key for 10.0.0.3 has changed and you have requested strict checking.
Host key verification failed.

There could be solved by easily removed the offending line in known_hosts file.

Examples:
It's important to know that there are essentially two versions of SSH out in the wild. On most GNU/Linux systems the OpenSSH implementation is installed which (these days) defaults to SSH protocol 2. On Windows SSH Shell, the commercial version of SSH is installed (also using protocol 2).

  • Client OpenSSH, Server: OpenSSH
    1. use  ssh-keygen -t rsa   to generate a id.rsa file
    2. copy the content of id_rsa.pub into server's ~/.ssh/authorized_keys file.
    3. if thte filename is not id_rsa, it can be any name , such as "wzb" and "wzb.pub"
    4. copy the content of wzb.pub into server's ~/.ssh/authorized_keys file, appended as one line.
    5. use ssh -i wzb liman1a.rutgers.edu  , it will prompt for the passphrase of identity file named "wzb", however, if you rename the key pair files as "identity" and identity.pub, thrn it will not need this -i option.
    6. use ssh-agent to avoid passphrase. Or you can try to use empty passphrase
    7. use ssh-add
  • Cleint: Windows SSH Shell: Server: OpenSSH
    Do following steps in client:
    1. start SSH shell, connect server with password
    2. menu-settings select key, generate keys.
    3. give name "userid" and comment, without pass-phrase (empty pass-phrase)
    4. upload keys to ".ssh" direcotory of the server
    5. go to home directory of server, cd .ssh
    6. run "ssh-keygen -X -f  userid.pub >>authorized_keys" or "ssh-keygen -i -f  userid.pub >>authorized_keys"
    7. In client, disconnect and connect again. You don't need to type password anymore.

    The above method works in liman server.

 



Home  l  Research   l  Toolbox  l  Resume  l  Life  l  Contact Me

Last Updated in April, 2007 Zhibin Wu. ©All rights reserved.