From: http://www.java114.com/278/content4210.html
提高Java代码可重用性的三个措施
本文介绍了三种修改现有代码提高其可重用性的方法,它们分别是:改写类的实例方法,把参数类型改成接口,选择最简单的参数接口类型。
措施一:改写类的实例方法 通过类继承实现代码重用不是精确的代码重用技术,因此它并不是最理想的代码重用机制。换句话说,如果不继承整个类的所有方法和数据成员,我们无法重用该类里面的单个方法。继承总是带来一些多余的方法和数据成员,它们总是使得重用类里面某个方法的代码复杂化。另外,派生类对父类的依赖关系也使得代码进一步复杂化:对父类的改动可能影响子类;修改父类或者子类中的任意一个类时,我们很难记得哪一个方法被子类覆盖、哪一个方法没有被子类覆盖;最后,子类中的覆盖方法是否要调用父类中的对应方法有时并不显而易见。 任何方法,只要它执行的是某个单一概念的任务,就其本身而言,它就应该是首选的可重用代码。为了重用这种代码,我们必须回归到面向过程的编程模式,把类的实例方法移出成为全局性的过程。为了提高这种过程的可重用性,过程代码应该象静态工具方法一样编写:它只能使用自己的输入参数,只能调用其他全局性的过程,不能使用任何非局部的变量。这种对外部依赖关系的限制简化了过程的应用,使得过程能够方便地用于任何地方。当然,由于这种组织方式总是使得代码具有更清晰的结构,即使是不考虑重用性的代码也同样能够从中获益。 在Java中,方法不能脱离类而单独存在。为此,我们可以把相关的过程组织成为独立的类,并把这些过程定义为公用静态方法。 例如,对于下面这个类: class Polygon { . . public int getPerimeter() {...} public boolean isConvex() {...} public boolean containsPoint(Point p) {...} . . } 我们可以把它改写成: class Polygon { . . public int getPerimeter() {return pPolygon.computePerimeter(this);} public boolean isConvex() {return pPolygon.isConvex(this);} public boolean containsPoint(Point p) {return pPolygon.containsPoint(this, p);} . } 其中,pPolygon是: class pPolygon { static public int computePerimeter(Polygon polygon) {...} static public boolean isConvex(Polygon polygon) {...} static public boolean containsPoint(Polygon polygon, Point p) {...} } 从类的名字pPolygon可以看出,该类所封装的过程主要与Polygon类型的对象有关。名字前面的p表示该类的唯一目的是组织公用静态过程。在Java中,类的名字以小写字母开头是一种非标准的做法,但象pPloygon这样的类事实上并不提供普通Java类的功能。也就是说,它并不代表着一类对象,它只是Java语言组织代码的一种机制。 在上面这个例子中,改动代码的最终效果是使得应用Polygon功能的客户代码不必再从Polygon继承。Polygon类的功能现在已经由pPolygon类以过程为单位提供。客户代码只使用自己需要的代码,无需关心Polygon类中自己不需要的功能。但它并不意味着在这种新式过程化编程中类的作用有所削弱。恰恰相反,在组织和封装对象数据成员的过程中,类起到了不可或缺的作用,而且正如本文接下来所介绍的,类通过多重接口实现多态性的能力本身也带来了卓越的代码重用支持。然而,由于用实例方法封装代码功能并不是首选的代码重用手段,所以通过类继承达到代码重用和多态性支持也不是最理想的。
措施二:把参数类型改成接口 正如Allen Holub在《Build User Interfaces for Object-Oriented Systems》中所指出的,在面向对象编程中,代码重用真正的要点在于通过接口参数类型利用多态性,而不是通过类继承: “……我们通过对接口而不是对类编程达到代码重用的目的。如果某个方法的所有参数都是对一些已知接口的引用,那么这个方法就能够操作这样一些对象:当我们编写方法的代码时,这些对象的类甚至还不存在。从技术上说,可重用的是方法,而不是传递给方法的对象。” 在“措施一”得到的结果上应用Holub的看法,当某块代码能够编写为独立的全局过程时,只要把它所有类形式的参数改为接口形式,我们就可以进一步提高它的可重用能力。经过这个改动之后,过程的参数可以是实现了该接口的所有类的对象,而不仅仅是原来的类所创建的对象。由此,过程将能够对可能存在的大量的对象类型进行操作。 例如,假设有这样一个全局静态方法: static public boolean contains(Rectangle rect, int x, int y) {...} 这个方法用于检查指定的点是否包含在矩形里面。在这个例子中,rect参数的类型可以从Rectangle类改变为接口类型,如下所示: static public boolean contains(Rectangular rect, int x, int y) {...} 而Rectangular接口的定义是: public interface Rectangular {Rectangle getBounds();} 现在,所有可以描述为矩形的类(即,实现了Rectangular接口的类)所创建的对象都可以作为提供给pRectangular.contains()的rect参数。通过放宽参数类型的限制,我们使方法具有更好的可重用性。 不过,对于上面这个例子,Rectangular接口的getBounds方法返回Rectangle,你可能会怀疑这么做是否真正值得。换言之,如果我们知道传入过程的对象会在被调用时返回一个Rectangle,为什么不直接传入Rectangle取代接口类型呢?之所以不这么做,最重要的原因与集合有关。让我们假设有这样一个方法: static public boolean areAnyOverlapping(Collection rects) {...} 该方法用于检查给定集合中的任意矩形对象是否重叠。在这个方法的内部,当我们用循环依次访问集合中的各个对象时,如果我们不能把对象cast成为Rectangular之类的接口类型,又如何能够访问对象的矩形区域呢?唯一的选择是把对象cast成为它特有的类形式(我们知道它有一个方法可以返回矩形),它意味着方法必须事先知道它所操作的对象类型,从而使得方法的重用只限于那几种对象类型。而这正是前面这个措施力图先行避免的问题!
措施三:选择最简单的参数接口类型 在实施第二个措施时,应该选用哪一种接口类型来取代给定的类形式?答案是哪一个接口完全满足过程对参数的需求,同时又具有最少的多余代码和数据。描述参数对象要求的接口越简单,其他类实现该接口的机会就越大——由此,其对象能够作为参数使用的类也越多。从下面这个例子可以很容易地看出这一点: static public boolean areOverlapping(Window window1, Window window2) {...} 这个方法用于检查两个窗口(假定是矩形窗口)是否重叠。如果这个方法只要求从参数获得两个窗口的矩形坐标,此时相应地简化这两个参数是一种更好的选择: static public boolean areOverlapping(Rectangular rect1, Rectangular rect2) {...} 上面的代码假定Window类型实现了Rectangular接口。经过改动之后,对于任何矩形对象我们都可以重用该方法的功能。 有些时候可能会出现描述参数需求的接口拥有太多方法的情况。此时,我们应该在全局名称空间中定义一个新的公共接口供其他面临同一问题的代码重用。 当我们需要象使用C语言中的函数指针一样使用参数时,创建唯一的接口描述参数需求是最好的选择。例如,假设有下面这个过程: static public void sort(List list, SortComparison comp) {...} 该方法运用参数中提供的比较对象comp,通过比较给定列表list中的对象排序list列表。sort对comp对象的唯一要求是要调用一个方法进行比较。因此,SortComparison应该是只带有一个方法的接口: public interface SortComparison { boolean comesBefore(Object a, Object b); } SortComparison接口的唯一目的在于为sort提供一个它所需功能的钩子,因此SortComparison接口不能在其他地方重用。 总而言之,本文三个措施适合于改造现有的、按照面向对象惯例编写的代码。这三个措施与面向对象编程技术结合就得到了一种可在以后编写代码时使用的新式代码编写技术,它能够简化方法的复杂性和依赖关系,同时提高方法的可重用能力和内部凝聚力。 当然,这里的三个措施不能用于那些天生就不适合重用的代码。不适合重用的代码通常出现在应用的表现层。例如,创建程序用户界面的代码,以及联结到输入事件的控制代码,都属于那种在程序和程序之间千差万别的代码,这种代码几乎不可能重用。
Thursday, January 15, 2009
Thursday, January 8, 2009
Java - GUI development using Eclipse IDE
under eclipse Java is using SWT for GUI development.
Following is a small sample code to demostrate how to use SWT under eclipse to develop GUI using java. Also, it tells how to run your java class under ms-dos command line.
==== CablePowerView.java =============
import org.eclipse.swt.widgets.*;
public class CablePowerView {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Cable Power Viewer Started!");
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Swt working!");
shell. setSize(500, 375);
shell.open();
while(!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep();
display.dispose();
}
}
public class CablePowerView {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Cable Power Viewer Started!");
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Swt working!");
shell. setSize(500, 375);
shell.open();
while(!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep();
display.dispose();
}
}
====== antbuild.xml ===========
Screen shot for antbuild.xml is attached as *.xml can not be displayed properly in the blog.
====== Run it in command line ============
1. From http://www.eclipse.org/swt/
We download SWT Stable Version for Windows (3.4 Final Release - 19 June 2008) swt-3.4-win32-win32-x86.zip
unzip we get swt.jar, then unzip swt.jar we get swt-win32-3448.dll.
We download SWT Stable Version for Windows (3.4 Final Release - 19 June 2008) swt-3.4-win32-win32-x86.zip
unzip we get swt.jar, then unzip swt.jar we get swt-win32-3448.dll.
2. creat run.bat as follows:
chdir .\CablePowerView\build
java -classpath .\swt.jar; -Djava.library.path=.\ CablePowerView
(Note: swt.jar, swt-win32-3448.dll are stored together with CalbePowerView.class under .\CablePowerView\build
run.bat is stored at root directory
.\ -Djava.library.path=.\ use to tell where swt-win32-3448.dll stored.)
Ms-Dos> run.bat
you will see the result that one window popped up. : - )
Wednesday, January 7, 2009
Java - Serial port communication
1. Java Development Environment set up under winxp.
a. download Eclipse IDE (Eclipse IDE for Java Developers (85 MB)) from
http://www.eclipse.org/downloads/
b. download JDK (Java SE Development Kit (JDK) 6 Update 11 72.9MB) from
http://java.sun.com/javase/downloads/?intcmp=1281
Installing JavaVM (JDK,JRE), and IDE.
The JDK files are placed at C:\Program Files\Java\jdk1.6.0_11\ and the runtime files are placed at C:\Program Files\Java\jdk1.6.0_11\. Ensure the System Variable "path" (held in My Computer->properties->Advanced->Environment Varables->System Variables) includes ";C:\Program Files\Java\jdk1.6.0_11\bin" at the end.
"C:\Program Files\Java\jre6" have JRE installed.
2. Download 'RXTX-2.1-7r2(stable) Binary rxtx-2.1-7-bins-r2.zip ' zip file from
http://www.rxtx.org/ wiki
a. Install RXTX
This involves placing rxtxSerial.dll and rxtxParallell.dll in both C:\Program Files\Java\jdk1.6.0_11\jre\bin and C:\Program Files\Java\jre6\bin. It also involves placing RXTXcomm.jar in both C:\Program Files\Java\jdk1.6.0_11\jre\lib\ext and C:\Program Files\Java\jre6\lib\ext.
b. Example is in link path: usage(Using RXTX)->Code Examples->Writing "Hello World" to a USB to serial converter
This example shows how write a Java program to write out "Hello World" to a serial port or to a USB to serial converter. Before you start you will need to ensure that a suitable Java VM is installed, along with the RXTX Libraries (see platform specifc instructions below).
These instructions all make use of the SimpleWrite.java example file, which you will need to download.
This Java program can be compiled and run by typing the following from the command line:
D:\MyDocXp\MyJavaEclipse\HelloWorld\src> javac SimpleWrite.java
D:\MyDocXp\MyJavaEclipse\HelloWorld\src>java SimpleWrite
"Hello World" should then appear on the device connected to the serial port, assuming that it has been set up to receive a 19200 baud rate, 8 data bits, 1 stop bit, no parity and no handshaking.
c. SimpleWrite.java
import java.io.*;
import java.util.*;
//import javax.comm.*;
import gnu.io.*;
/** * Class declaration * * * @author * @version 1.10, 08/04/00 */public class SimpleWrite { static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!";
static SerialPort serialPort;
static OutputStream outputStream;
static boolean outputBufferEmptyFlag = false;
/** * Method declaration * * * @param args * * @see */ public static void main(String[] args) { boolean portFound = false;
//String defaultPort = "/dev/term/a";
String defaultPort = "COM4";
if (args.length > 0) { defaultPort = args[0];
}
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) { System.out.println("Found port " + defaultPort);
portFound = true;
try { serialPort = (SerialPort) portId.open("SimpleWrite", 2000);
} catch (PortInUseException e) { System.out.println("Port in use.");
continue;
}
try { outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try { serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try { serialPort.notifyOnOutputEmpty(true);
} catch (Exception e) { System.out.println("Error setting event notification");
System.out.println(e.toString());
System.exit(-1);
}
System.out.println( "Writing \""+messageString+"\" to " +serialPort.getName());
try { outputStream.write(messageString.getBytes());
} catch (IOException e) {}
try { Thread.sleep(2000); // Be sure data is xferred before closing } catch (Exception e) {} serialPort.close();
System.exit(1);
} } }
if (!portFound) { System.out.println("port " + defaultPort + " not found.");
} }
}
a. download Eclipse IDE (Eclipse IDE for Java Developers (85 MB)) from
http://www.eclipse.org/downloads/
b. download JDK (Java SE Development Kit (JDK) 6 Update 11 72.9MB) from
http://java.sun.com/javase/downloads/?intcmp=1281
Installing JavaVM (JDK,JRE), and IDE.
The JDK files are placed at C:\Program Files\Java\jdk1.6.0_11\ and the runtime files are placed at C:\Program Files\Java\jdk1.6.0_11\. Ensure the System Variable "path" (held in My Computer->properties->Advanced->Environment Varables->System Variables) includes ";C:\Program Files\Java\jdk1.6.0_11\bin" at the end.
"C:\Program Files\Java\jre6" have JRE installed.
2. Download 'RXTX-2.1-7r2(stable) Binary rxtx-2.1-7-bins-r2.zip ' zip file from
http://www.rxtx.org/ wiki
a. Install RXTX
This involves placing rxtxSerial.dll and rxtxParallell.dll in both C:\Program Files\Java\jdk1.6.0_11\jre\bin and C:\Program Files\Java\jre6\bin. It also involves placing RXTXcomm.jar in both C:\Program Files\Java\jdk1.6.0_11\jre\lib\ext and C:\Program Files\Java\jre6\lib\ext.
b. Example is in link path: usage(Using RXTX)->Code Examples->Writing "Hello World" to a USB to serial converter
This example shows how write a Java program to write out "Hello World" to a serial port or to a USB to serial converter. Before you start you will need to ensure that a suitable Java VM is installed, along with the RXTX Libraries (see platform specifc instructions below).
These instructions all make use of the SimpleWrite.java example file, which you will need to download.
This Java program can be compiled and run by typing the following from the command line:
D:\MyDocXp\MyJavaEclipse\HelloWorld\src> javac SimpleWrite.java
D:\MyDocXp\MyJavaEclipse\HelloWorld\src>java SimpleWrite
"Hello World" should then appear on the device connected to the serial port, assuming that it has been set up to receive a 19200 baud rate, 8 data bits, 1 stop bit, no parity and no handshaking.
c. SimpleWrite.java
import java.io.*;
import java.util.*;
//import javax.comm.*;
import gnu.io.*;
/** * Class declaration * * * @author * @version 1.10, 08/04/00 */public class SimpleWrite { static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!";
static SerialPort serialPort;
static OutputStream outputStream;
static boolean outputBufferEmptyFlag = false;
/** * Method declaration * * * @param args * * @see */ public static void main(String[] args) { boolean portFound = false;
//String defaultPort = "/dev/term/a";
String defaultPort = "COM4";
if (args.length > 0) { defaultPort = args[0];
}
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) { System.out.println("Found port " + defaultPort);
portFound = true;
try { serialPort = (SerialPort) portId.open("SimpleWrite", 2000);
} catch (PortInUseException e) { System.out.println("Port in use.");
continue;
}
try { outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try { serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try { serialPort.notifyOnOutputEmpty(true);
} catch (Exception e) { System.out.println("Error setting event notification");
System.out.println(e.toString());
System.exit(-1);
}
System.out.println( "Writing \""+messageString+"\" to " +serialPort.getName());
try { outputStream.write(messageString.getBytes());
} catch (IOException e) {}
try { Thread.sleep(2000); // Be sure data is xferred before closing } catch (Exception e) {} serialPort.close();
System.exit(1);
} } }
if (!portFound) { System.out.println("port " + defaultPort + " not found.");
} }
}
struts开发实践—曲线图实例
From: http://www.7880.com/Info/Article-456d7000.html
本案主要功能是完成曲线图的绘制,并将曲线图生成jpg图形并显示。
1。画图的主要函数说明
Graphics g
g.drawRect(x_top,x_bottom,width,height):画矩形
g.setColor(color):指定颜色;
g.fillRect(x_top,x_bottom,width,height):画填充的矩形//
g.drawRoundRect(x_top,x_bottom,width,height):画圆边矩形
g.fillRoundRect(x_top,x_bottom,width,height):画一个填充的圆边矩形
g.drawArc(beg_x,beg_y,width,height,beg_tangle,end_tangle):画弧线
g.fillArc(beg_x,beg_y,width,height,beg_tangle,end_tangle):填充弧
g.drawLine(beg_x,beg_y,end_x,end_y):画一条直线
g.drawString(theString,stringTopLeft_x,StringTopLeft_y):画字
g.setFont(font):设置画笔的字体
g.setPaint(color):设置画笔的颜色
2。曲线图绘制文件
/*****************program CurveFrame begin************************/
package test;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.JFrame;
import java.lang.Math;
/** *曲线图绘制 */
public class CurveFrame
extends JFrame {
/**数据*/
private double[] result;
/**数据项名称*/
private String[] title;
/**参数:结果集,名称集*/
public CurveFrame(double[] result, String[] title) {
this.result = result;
this.title = title;
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Dimension dim = this.getSize();
g2.setColor(Color.white);
g2.fillRect(0, 0, dim.width, dim.height);
//写title;
Font font = g2.getFont().deriveFont(12.0f);
g2.setFont(font);
FontMetrics metrics = g2.getFontMetrics();
g2.setPaint(Color.black);
g2.drawString(title[0], (dim.width - title[0].length() * 5) / 2, 10);
// draw the x and y axis
g2.setStroke(new BasicStroke(2.0f));
g2.draw(new Line2D.Double(40, 30, 40, dim.height - 30));
g2.draw(new Line2D.Double(40, dim.height - 30,
dim.width - 20, dim.height - 30));
long unit=(Math.round((result[0]+750)/1500))*50;
long yMax = result[0] == 0 ? unit : Math.round((result[0]+unit/2)/unit) * unit;
int widthPer = (dim.width - 40) / result.length;
long heightPer = (dim.height - 60) / (yMax / unit);
//draw the y axis scale;
g2.setPaint(Color.lightGray);
g2.setStroke(new BasicStroke(1.0f));
for (int i = 0; i<=yMax / unit; i++) {
g2.draw(new Line2D.Double(40, dim.height - 30 - i * heightPer,
dim.width - 40, dim.height - 30 - i * heightPer));
String ylabel = String.valueOf(i * unit);
g2.drawString(ylabel, 35 - metrics.stringWidth(ylabel),
dim.height - 30 - (i * heightPer));
}
//draw x title;
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD,
result.length - 2);
for (int i = 1; i < result.length; i++) {
//draw x scale;
g2.setPaint(Color.lightGray);
g2.setStroke(new BasicStroke(1.0f));
g2.draw(new Line2D.Double(40 + (i - 1) * widthPer, dim.height - 30,
40 + (i - 1) * widthPer,30));
font = g2.getFont().deriveFont(10.0f);
g2.setFont(font);
g2.setPaint(Color.black);
g2.drawString(title[i], 40 + widthPer * (i - 1)-metrics.stringWidth(title[i])/2, dim.height - 10);
g2.setPaint(Color.red);
g2.setStroke(new BasicStroke(2.0f));
if (i == 1) {
path.moveTo(40,
Math.round(dim.height - 30 -
(result[i] / unit) * heightPer));
}
else {
path.lineTo(Math.round(widthPer * (i - 1)) + 40,
Math.round(dim.height - 30 -
(result[i] / unit) * heightPer));
}
}
g2.draw(path);
}
}
/*****************program end************************/
3。生成jpg图形并显示
/*****************program begin************************/
package test;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
/**
* 变化曲线
*/
public class WageChangeCurveAction
extends Action {
private static final String CONTENT_TYPE = "image/gif";
private static final int WIDTH = 700;
private static final int HEIGHT = 500;
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException {
response.setContentType(CONTENT_TYPE);
ServletOutputStream out = response.getOutputStream();
double[] result=。。。String[] title = 。。。//获得图形数据
try {
CurveFrame dummy = new CurveFrame(result,title);
dummy.setSize(new Dimension(WIDTH, HEIGHT));
BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
dummy.paint(g2);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.flush();
}
catch (Throwable e) {
e.printStackTrace();
}
return mapping.findForward("success");
}
}
/*****************program end************************/
本案主要功能是完成曲线图的绘制,并将曲线图生成jpg图形并显示。
1。画图的主要函数说明
Graphics g
g.drawRect(x_top,x_bottom,width,height):画矩形
g.setColor(color):指定颜色;
g.fillRect(x_top,x_bottom,width,height):画填充的矩形//
g.drawRoundRect(x_top,x_bottom,width,height):画圆边矩形
g.fillRoundRect(x_top,x_bottom,width,height):画一个填充的圆边矩形
g.drawArc(beg_x,beg_y,width,height,beg_tangle,end_tangle):画弧线
g.fillArc(beg_x,beg_y,width,height,beg_tangle,end_tangle):填充弧
g.drawLine(beg_x,beg_y,end_x,end_y):画一条直线
g.drawString(theString,stringTopLeft_x,StringTopLeft_y):画字
g.setFont(font):设置画笔的字体
g.setPaint(color):设置画笔的颜色
2。曲线图绘制文件
/*****************program CurveFrame begin************************/
package test;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.JFrame;
import java.lang.Math;
/** *曲线图绘制 */
public class CurveFrame
extends JFrame {
/**数据*/
private double[] result;
/**数据项名称*/
private String[] title;
/**参数:结果集,名称集*/
public CurveFrame(double[] result, String[] title) {
this.result = result;
this.title = title;
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Dimension dim = this.getSize();
g2.setColor(Color.white);
g2.fillRect(0, 0, dim.width, dim.height);
//写title;
Font font = g2.getFont().deriveFont(12.0f);
g2.setFont(font);
FontMetrics metrics = g2.getFontMetrics();
g2.setPaint(Color.black);
g2.drawString(title[0], (dim.width - title[0].length() * 5) / 2, 10);
// draw the x and y axis
g2.setStroke(new BasicStroke(2.0f));
g2.draw(new Line2D.Double(40, 30, 40, dim.height - 30));
g2.draw(new Line2D.Double(40, dim.height - 30,
dim.width - 20, dim.height - 30));
long unit=(Math.round((result[0]+750)/1500))*50;
long yMax = result[0] == 0 ? unit : Math.round((result[0]+unit/2)/unit) * unit;
int widthPer = (dim.width - 40) / result.length;
long heightPer = (dim.height - 60) / (yMax / unit);
//draw the y axis scale;
g2.setPaint(Color.lightGray);
g2.setStroke(new BasicStroke(1.0f));
for (int i = 0; i<=yMax / unit; i++) {
g2.draw(new Line2D.Double(40, dim.height - 30 - i * heightPer,
dim.width - 40, dim.height - 30 - i * heightPer));
String ylabel = String.valueOf(i * unit);
g2.drawString(ylabel, 35 - metrics.stringWidth(ylabel),
dim.height - 30 - (i * heightPer));
}
//draw x title;
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD,
result.length - 2);
for (int i = 1; i < result.length; i++) {
//draw x scale;
g2.setPaint(Color.lightGray);
g2.setStroke(new BasicStroke(1.0f));
g2.draw(new Line2D.Double(40 + (i - 1) * widthPer, dim.height - 30,
40 + (i - 1) * widthPer,30));
font = g2.getFont().deriveFont(10.0f);
g2.setFont(font);
g2.setPaint(Color.black);
g2.drawString(title[i], 40 + widthPer * (i - 1)-metrics.stringWidth(title[i])/2, dim.height - 10);
g2.setPaint(Color.red);
g2.setStroke(new BasicStroke(2.0f));
if (i == 1) {
path.moveTo(40,
Math.round(dim.height - 30 -
(result[i] / unit) * heightPer));
}
else {
path.lineTo(Math.round(widthPer * (i - 1)) + 40,
Math.round(dim.height - 30 -
(result[i] / unit) * heightPer));
}
}
g2.draw(path);
}
}
/*****************program end************************/
3。生成jpg图形并显示
/*****************program begin************************/
package test;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
/**
* 变化曲线
*/
public class WageChangeCurveAction
extends Action {
private static final String CONTENT_TYPE = "image/gif";
private static final int WIDTH = 700;
private static final int HEIGHT = 500;
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException {
response.setContentType(CONTENT_TYPE);
ServletOutputStream out = response.getOutputStream();
double[] result=。。。String[] title = 。。。//获得图形数据
try {
CurveFrame dummy = new CurveFrame(result,title);
dummy.setSize(new Dimension(WIDTH, HEIGHT));
BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
dummy.paint(g2);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.flush();
}
catch (Throwable e) {
e.printStackTrace();
}
return mapping.findForward("success");
}
}
/*****************program end************************/
Tuesday, January 6, 2009
Java IDE选择
From: http://www.knowsky.com/362256.html
随着Java应用程序越做越大、越做越复杂。Java IDE在其中所起的作用也日益显著。有了Java IDE,使软件的生产率倍增。但目前Java IDE的种类繁多,功能也各不相同。这就给我们的选择带来了诸多不便。因此,本文就目前比较流行的几种Java IDE做了一个深入的对比。主要比较4种Java IDE,它们是Eclipse、Netbeans、Jbuilder和Jcreator。本文将从以下8个方面进行探讨。 一、 Java IDE介绍 1. Eclipse Eclipse是一个非常成功的开源项目。在世纪之交的时候,IBM为了对抗微软越来越强的垄断地位,投入了10亿美元进行Linux、pc、笔记本电脑以及服务器等产品的研发。在这一系列举措中,影响最深远的就是Eclipse。 Eclipse是IBM“日独计划”的产物。在2001年6月,IBM将价值4000万美元的Eclipse捐给了开源组织。Eclipse由四个计划组成:Eclipse Project、Eclipse Tools Project、Eclipse Technology Project和Eclipse Web Tools Platform Project。每一个计划都遵照CPL1.0协议发布。经过几年的发展,Eclipse已经成为目前最流行的Java IDE。并且拥有了很多的Eclipse社区和新闻组。目前,Eclipse已经成为开发Java程序的首选IDE。 2. Netbeans Netbeans是Sun自己的开源Java IDE。随着Eclipse逐渐兴起,Sun也在试探性地向Eclipse靠拢。但同时又在不移余力地开发自己的Java IDE:Netbeans。Netbeans在功能上和Eclipse类似。但和Eclipse也有一此区别。如Netbeans集成了Web开发以及最近流行的ajax,而Eclipse要想达到这一点,必须得安装其它的第三方插件。还有Eclipse鼓励使用SWT做为Java的GUI库,而Netbeans使用的是更纯正的Java GUI库:Swing/AWT。 3.Jbuilder Jbuilder是Borland开发的Java IDE。它在Eclipse和Netbeans出现之前是非常流行了。原因很简单,因为那时Jbuilder是唯一能够真正称得上IDE的产品。但在 Eclipse和Netbeans出现之后Jbuilder就每况愈下。发生这种情况的原因很多。可能是因为Jbuilder是收费的,而Eclipse 和Netbeans是免费的;也可能是因为Borland的产品有一个最大的缺点。就是不管功能多强,而它的代码编辑器和其它辅助书写代码的工具差不多未发生什么变化。从Jbuilder2和Jbuilder9似乎都差不多。 4. Jcreator 以上介绍的都是大家伙。而Jcreator则是一个轻量型的Java IDE。它的功能非常单一。最核心的功能就是可能编写Java源程序,并且支持代码变色和code complete。但Jcreator有一个最显著的优点。就是运行速度快,并且占用资源少。这主要是因为Eclipse、Netbeans和 Jbuilder本身都是使用Java编写的。在启动时必须得先启动Java虚拟机。而Jcreator使用的是本地代码。因而速度更快。假如你的机器配置不高(如只有64M或128M内存),还是使用Jcreator为好。
二、 Java IDE是否能跨平台 由于Java是跨平台的,因此,它的IDE最好也能跨平台。由于Eclipse、Netbeans和Jbuilder都是使用Java编写的,因此它们也是跨平台的。但由于Eclipse采用的GUI接口是 SWT。而这个库并未加入Sun JCP。因此,Eclipse的跨平台要受到SWT的限制,即SWT所能跨的平台数也就是Eclipse所跨的平台数。而对于Jcreator来说,目前只有Windows版本。这也不能不说是一个遗憾。不过由于大多数的Java开发都是在Windows上,因此。支持Windows平台是几乎是所有的 Java IDE最先考虑的事情。 三、 Java IDE是否收费 这个问题是决定一个IDE是否能够流行的重要原因之一。众所周知,假如一个软件是收费的,那么获得这个软件的方法一般有两种。一种是购买正版的软件。另一种就是使用盗版的软件。而在一些对盗版打击很严厉的国家可能使用正版软件就成为最佳的选择。然而,使用正版软件将会带来很大的成本。所以一但有一种或几种免费的软件,并且在功能上足可以取代收费软件时,人们就会马上转向这些免费的软件。在上述的4种Java IDE中Eclipse和Netbeans不仅是完全免费的,而且是开源的。因此,它们一出现,就对收费Jbuilder产生了很大的威胁。目前 Eclipse和Netbeans的使用率已经超过了Jbuilder。而Jcreator虽然也是收费的。但是费用也并不高。因此,以Jcreator 为首的一些小型的Java IDE以其体积小,占用系统资源少等优点也会占有一定的比例(尽管这个比例并不大)。 四、 Java IDE的界面友好程度 界面是否友好是决定一个IDE是否成功的另一个重要原因。对于界面来说,Eclipse和Netbeans差不多。只是Eclipse是使用SWT开发的。因此,它的界面看起来更像是本地的程序。而Netbeans的界面风格是Java的标准风格。
随着Java应用程序越做越大、越做越复杂。Java IDE在其中所起的作用也日益显著。有了Java IDE,使软件的生产率倍增。但目前Java IDE的种类繁多,功能也各不相同。这就给我们的选择带来了诸多不便。因此,本文就目前比较流行的几种Java IDE做了一个深入的对比。主要比较4种Java IDE,它们是Eclipse、Netbeans、Jbuilder和Jcreator。本文将从以下8个方面进行探讨。 一、 Java IDE介绍 1. Eclipse Eclipse是一个非常成功的开源项目。在世纪之交的时候,IBM为了对抗微软越来越强的垄断地位,投入了10亿美元进行Linux、pc、笔记本电脑以及服务器等产品的研发。在这一系列举措中,影响最深远的就是Eclipse。 Eclipse是IBM“日独计划”的产物。在2001年6月,IBM将价值4000万美元的Eclipse捐给了开源组织。Eclipse由四个计划组成:Eclipse Project、Eclipse Tools Project、Eclipse Technology Project和Eclipse Web Tools Platform Project。每一个计划都遵照CPL1.0协议发布。经过几年的发展,Eclipse已经成为目前最流行的Java IDE。并且拥有了很多的Eclipse社区和新闻组。目前,Eclipse已经成为开发Java程序的首选IDE。 2. Netbeans Netbeans是Sun自己的开源Java IDE。随着Eclipse逐渐兴起,Sun也在试探性地向Eclipse靠拢。但同时又在不移余力地开发自己的Java IDE:Netbeans。Netbeans在功能上和Eclipse类似。但和Eclipse也有一此区别。如Netbeans集成了Web开发以及最近流行的ajax,而Eclipse要想达到这一点,必须得安装其它的第三方插件。还有Eclipse鼓励使用SWT做为Java的GUI库,而Netbeans使用的是更纯正的Java GUI库:Swing/AWT。 3.Jbuilder Jbuilder是Borland开发的Java IDE。它在Eclipse和Netbeans出现之前是非常流行了。原因很简单,因为那时Jbuilder是唯一能够真正称得上IDE的产品。但在 Eclipse和Netbeans出现之后Jbuilder就每况愈下。发生这种情况的原因很多。可能是因为Jbuilder是收费的,而Eclipse 和Netbeans是免费的;也可能是因为Borland的产品有一个最大的缺点。就是不管功能多强,而它的代码编辑器和其它辅助书写代码的工具差不多未发生什么变化。从Jbuilder2和Jbuilder9似乎都差不多。 4. Jcreator 以上介绍的都是大家伙。而Jcreator则是一个轻量型的Java IDE。它的功能非常单一。最核心的功能就是可能编写Java源程序,并且支持代码变色和code complete。但Jcreator有一个最显著的优点。就是运行速度快,并且占用资源少。这主要是因为Eclipse、Netbeans和 Jbuilder本身都是使用Java编写的。在启动时必须得先启动Java虚拟机。而Jcreator使用的是本地代码。因而速度更快。假如你的机器配置不高(如只有64M或128M内存),还是使用Jcreator为好。
二、 Java IDE是否能跨平台 由于Java是跨平台的,因此,它的IDE最好也能跨平台。由于Eclipse、Netbeans和Jbuilder都是使用Java编写的,因此它们也是跨平台的。但由于Eclipse采用的GUI接口是 SWT。而这个库并未加入Sun JCP。因此,Eclipse的跨平台要受到SWT的限制,即SWT所能跨的平台数也就是Eclipse所跨的平台数。而对于Jcreator来说,目前只有Windows版本。这也不能不说是一个遗憾。不过由于大多数的Java开发都是在Windows上,因此。支持Windows平台是几乎是所有的 Java IDE最先考虑的事情。 三、 Java IDE是否收费 这个问题是决定一个IDE是否能够流行的重要原因之一。众所周知,假如一个软件是收费的,那么获得这个软件的方法一般有两种。一种是购买正版的软件。另一种就是使用盗版的软件。而在一些对盗版打击很严厉的国家可能使用正版软件就成为最佳的选择。然而,使用正版软件将会带来很大的成本。所以一但有一种或几种免费的软件,并且在功能上足可以取代收费软件时,人们就会马上转向这些免费的软件。在上述的4种Java IDE中Eclipse和Netbeans不仅是完全免费的,而且是开源的。因此,它们一出现,就对收费Jbuilder产生了很大的威胁。目前 Eclipse和Netbeans的使用率已经超过了Jbuilder。而Jcreator虽然也是收费的。但是费用也并不高。因此,以Jcreator 为首的一些小型的Java IDE以其体积小,占用系统资源少等优点也会占有一定的比例(尽管这个比例并不大)。 四、 Java IDE的界面友好程度 界面是否友好是决定一个IDE是否成功的另一个重要原因。对于界面来说,Eclipse和Netbeans差不多。只是Eclipse是使用SWT开发的。因此,它的界面看起来更像是本地的程序。而Netbeans的界面风格是Java的标准风格。
Tuesday, December 16, 2008
Avoid auto padding by PIC32 compiler for data structure
Using __attribute__((packed)) for variable and structure member.
typedef struct sDaq2ComAggregationRaw001
{
GSNTYPES_BYTE FeederAndPhase; //0x01:Va 0x02:Vb....
GSNTYPES_BYTE TimeStampCycles;
GSNTYPES_ULONG TimeStampSeconds;
GSNTYPES_DOUBLE llDft_Goertzel_Aggregation_SquareSumImgReal[CABLE_TRACKER_MAX_NUM_HARMONICS]; GSNTYPES_DOUBLE llSquareSumForAggregationLog;
GSNTYPES_DOUBLE llSquareSumPerCycleMaxOverLoggingInterval; //Optional to be logged.--advanced feature ToDo
GSNTYPES_DOUBLE llSquareSumPerCycleMinOverLoggingInterval; //Optional to be logged.--advanced feature ToDo
}
__attribute__((packed)) S_DAQ2COM_AGGREGATION_RAW_001;
typedef struct sDaq2ComAggregationRaw002
{
GSNTYPES_BYTE FeederAndPhase; //0x11:Feeder1PhaseA, 0x12:Feeder1PhaseB...0x41:Feeder4PhaseA
GSNTYPES_BYTE TimeStampCycles;
GSNTYPES_ULONG TimeStampSeconds;
GSNTYPES_DOUBLE llDft_Goertzel_Aggregation_SquareSumImgReal[CABLE_TRACKER_MAX_NUM_HARMONICS]; GSNTYPES_DOUBLE llSquareSumForAggregationLog;
GSNTYPES_DOUBLE llSquareSumPerCycleMaxOverLoggingInterval;
GSNTYPES_DOUBLE llSquareSumPerCycleMinOverLoggingInterval;
GSNTYPES_DOUBLE llActivePwrSumForAggregationLog; //
}
__attribute__((packed)) S_DAQ2COM_AGGREGATION_RAW_002;
typedef struct sStructureID
{
GSNTYPES_USHORT variation;
GSNTYPES_BYTE version;
GSNTYPES_BYTE type; //config, log, events. see E_StructType definition.
}__attribute__((packed)) S_StructureID;
typedef struct sRdHeadDataStorage
{
GSNTYPES_USHORT len; //is based on the struct ID,number bytes of record body,exclude record header.
S_StructureID structID;
}S_RecordHeadDataStorage;
typedef union sDataRecordBody
{
//The ptrDataBody could point to following data Structures.
S_COM_CONFIG_BLOCK_001 com_configuration_001;
S_COM_CONFIG_BLOCK_002 com_configuration_002;
S_DAQ_CONFIG_BLOCK_001 daq_configuration_001;
S_DAQ_CONFIG_BLOCK_002 daq_configuration_002;
S_DAQ2COM_AGGREGATION_RAW_001 daq2com_aggregation_raw_001;
S_DAQ2COM_AGGREGATION_RAW_002 daq2com_aggregation_raw_002;
S_DAQ2COM_AGGREGATION_RAW_003 daq2com_aggregation_raw_003;
S_DAQ2COM_EVENTS_RAW_001 daq2com_events_raw_001;
S_DAQ2COM_EVENTS_RAW_002 daq2com_events_raw_002;
S_DAQ2COM_EVENTS_RAW_003 daq2com_events_raw_003;
S_COM2EEP_AGGREGATION_REAL_001 com2eep_aggregation_real_001;
S_COM2EEP_AGGREGATION_REAL_002 com2eep_aggregation_real_002;
S_COM2EEP_AGGREGATION_REAL_003 com2eep_aggregation_real_003;
S_COM2EEP_EVENTS_REAL_001 com2eep_events_real_001;
S_COM2EEP_EVENTS_REAL_002 com2eep_events_real_002;
S_COM2EEP_EVENTS_REAL_003 com2eep_events_real_003;
}U_DataRecordBody;
typedef struct sDataRecord
{
S_RecordHeadDataStorage rdHead;
U_DataRecordBody rdDataBody;
}__attribute__((packed)) S_DataRecord;
typedef struct sDaq2ComAggregationRaw001
{
GSNTYPES_BYTE FeederAndPhase; //0x01:Va 0x02:Vb....
GSNTYPES_BYTE TimeStampCycles;
GSNTYPES_ULONG TimeStampSeconds;
GSNTYPES_DOUBLE llDft_Goertzel_Aggregation_SquareSumImgReal[CABLE_TRACKER_MAX_NUM_HARMONICS]; GSNTYPES_DOUBLE llSquareSumForAggregationLog;
GSNTYPES_DOUBLE llSquareSumPerCycleMaxOverLoggingInterval; //Optional to be logged.--advanced feature ToDo
GSNTYPES_DOUBLE llSquareSumPerCycleMinOverLoggingInterval; //Optional to be logged.--advanced feature ToDo
}
__attribute__((packed)) S_DAQ2COM_AGGREGATION_RAW_001;
typedef struct sDaq2ComAggregationRaw002
{
GSNTYPES_BYTE FeederAndPhase; //0x11:Feeder1PhaseA, 0x12:Feeder1PhaseB...0x41:Feeder4PhaseA
GSNTYPES_BYTE TimeStampCycles;
GSNTYPES_ULONG TimeStampSeconds;
GSNTYPES_DOUBLE llDft_Goertzel_Aggregation_SquareSumImgReal[CABLE_TRACKER_MAX_NUM_HARMONICS]; GSNTYPES_DOUBLE llSquareSumForAggregationLog;
GSNTYPES_DOUBLE llSquareSumPerCycleMaxOverLoggingInterval;
GSNTYPES_DOUBLE llSquareSumPerCycleMinOverLoggingInterval;
GSNTYPES_DOUBLE llActivePwrSumForAggregationLog; //
}
__attribute__((packed)) S_DAQ2COM_AGGREGATION_RAW_002;
typedef struct sStructureID
{
GSNTYPES_USHORT variation;
GSNTYPES_BYTE version;
GSNTYPES_BYTE type; //config, log, events. see E_StructType definition.
}__attribute__((packed)) S_StructureID;
typedef struct sRdHeadDataStorage
{
GSNTYPES_USHORT len; //is based on the struct ID,number bytes of record body,exclude record header.
S_StructureID structID;
}S_RecordHeadDataStorage;
typedef union sDataRecordBody
{
//The ptrDataBody could point to following data Structures.
S_COM_CONFIG_BLOCK_001 com_configuration_001;
S_COM_CONFIG_BLOCK_002 com_configuration_002;
S_DAQ_CONFIG_BLOCK_001 daq_configuration_001;
S_DAQ_CONFIG_BLOCK_002 daq_configuration_002;
S_DAQ2COM_AGGREGATION_RAW_001 daq2com_aggregation_raw_001;
S_DAQ2COM_AGGREGATION_RAW_002 daq2com_aggregation_raw_002;
S_DAQ2COM_AGGREGATION_RAW_003 daq2com_aggregation_raw_003;
S_DAQ2COM_EVENTS_RAW_001 daq2com_events_raw_001;
S_DAQ2COM_EVENTS_RAW_002 daq2com_events_raw_002;
S_DAQ2COM_EVENTS_RAW_003 daq2com_events_raw_003;
S_COM2EEP_AGGREGATION_REAL_001 com2eep_aggregation_real_001;
S_COM2EEP_AGGREGATION_REAL_002 com2eep_aggregation_real_002;
S_COM2EEP_AGGREGATION_REAL_003 com2eep_aggregation_real_003;
S_COM2EEP_EVENTS_REAL_001 com2eep_events_real_001;
S_COM2EEP_EVENTS_REAL_002 com2eep_events_real_002;
S_COM2EEP_EVENTS_REAL_003 com2eep_events_real_003;
}U_DataRecordBody;
typedef struct sDataRecord
{
S_RecordHeadDataStorage rdHead;
U_DataRecordBody rdDataBody;
}__attribute__((packed)) S_DataRecord;
Monday, December 1, 2008
Basic linux command list under Fedora
SHOW PERL VERSION
SHOW LINUX KERNEL VERSION
SHOW WHETHER LINUX KERNEL SOURCE CODE ARE INSTALLED
cscope
[q.yang@localhost lpc3250]$ uname -r
[q.yang@localhost sierra_drv_1.7.32]$ rpm -qa|grep kernel
kerneloops-0.12-1.fc9.i386
kernel-devel-2.6.27.25-78.2.56.fc9.i686
kernel-2.6.25-14.fc9.i686
kernel-headers-2.6.27.25-78.2.56.fc9.i386
kernel-2.6.27.25-78.2.56.fc9.i686
kernel-firmware-2.6.27.25-78.2.56.fc9.noarch
[q.yang@localhost sierra_drv_1.7.32]$ rpm -qa|grep kernel |grep devel
kernel-devel-2.6.27.25-78.2.56.fc9.i686
[q.yang@localhost sierra_drv_1.7.32]$ rpm -qa|grep kernel |grep headers
kernel-headers-2.6.27.25-78.2.56.fc9.i386
[root@localhost sierra_drv_1.7.32]# yum install kernel-devel-2.6.25-14.fc9.i686
Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package kernel-devel.i686 0:2.6.25-14.fc9 set to be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================
Package Arch Version Repository Size
====================================================================================================================
Installing:
kernel-devel i686 2.6.25-14.fc9 fedora 5.1 M
Transaction Summary
====================================================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 5.1 M
Is this ok [y/N]: y
Downloading Packages:
kernel-devel-2.6.25-14.fc9.i686.rpm | 5.1 MB 00:21
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : kernel-devel 1/1
Installed:
kernel-devel.i686 0:2.6.25-14.fc9
Complete!
/*********************************/
/* Vi Relevant */
/* Created: 2007-Aug-16 THU */
/* Update: 2007-Aug-20 MON */
/* */
/* v0.0.0.1 added Yum relevant commands 2008-SEP-26 FRI */
/* v0.0.0.2 added vnc relevant commands 2008-SEP-27 SAT */
/* v0.0.0.3 added svn relevant commands 2008-OCT-01 WED */
/**********************************************************************/
DISPLAY DISK USAGE
------------------------------------------------------------------
[q.yang@localhost ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6063688 5204096 551576 91% /
/dev/sda6 194442 18921 165482 11% /boot
tmpfs 224740 96 224644 1% /dev/shm
gvfs-fuse-daemon 6063688 5204096 551576 91% /home/q.yang/.gvfs
[q.yang@localhost ~]$ su
Password:
[root@localhost q.yang]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6063688 5204100 551572 91% /
/dev/sda6 194442 18921 165482 11% /boot
tmpfs 224740 96 224644 1% /dev/shm
[root@localhost q.yang]#
WHICH LINUX KERNEL TO BOOT
------------------------------------------------------------
[root@localhost kernel]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,5)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=2
timeout=5
splashimage=(hd0,5)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.27.25-78.2.56.fc9.i686)
root (hd0,5)
kernel /vmlinuz-2.6.27.25-78.2.56.fc9.i686 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.27.25-78.2.56.fc9.i686.img
title Linux (2.6.25-14.fc9.i686)
root (hd0,5)
kernel /vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=916c799e-4ae5-4820-8de6-0bbc5b7b8968 rhgb quiet
initrd /initrd-2.6.25-14.fc9.i686.img
title Win2000
rootnoverify (hd0,0)
chainloader +1
[root@localhost kernel]# ll /boot/
total 12767
-rw-r--r-- 1 root root 86348 2008-05-01 20:34 config-2.6.25-14.fc9.i686
-rw-r--r-- 1 root root 90947 2009-06-19 02:57 config-2.6.27.25-78.2.56.fc9.i686
drwxr-xr-x 3 root root 1024 2010-06-04 02:19 efi
drwxr-xr-x 2 root root 1024 2010-06-07 14:42 grub
-rw------- 1 root root 3294836 2010-06-04 02:21 initrd-2.6.25-14.fc9.i686.img
-rw------- 1 root root 3326324 2010-06-07 14:42 initrd-2.6.27.25-78.2.56.fc9.i686.img
drwx------ 2 root root 12288 2010-06-04 02:11 lost+found
-rw-r--r-- 1 root root 892575 2008-05-01 20:34 System.map-2.6.25-14.fc9.i686
-rw-r--r-- 1 root root 976362 2009-06-19 02:57 System.map-2.6.27.25-78.2.56.fc9.i686
-rwxr-xr-x 1 root root 2088288 2008-05-01 20:34 vmlinuz-2.6.25-14.fc9.i686
-rwxr-xr-x 1 root root 2227280 2009-06-19 02:57 vmlinuz-2.6.27.25-78.2.56.fc9.i686
FIND COMMAND USAGE
-----------------------------
Only find current directory without search sub-dir using '-maxdepth 1'
[q.yang@localhost ProjProgrammingTest]$ find ./include/ -maxdepth 1 -name '*' |grep .h
./include/Misc.h
./include/CommsLinkSessionManager.h
./include/Gpio.h
./include/GsnDataTypes.h
./include/DeviceTcpTx.h
./include/CommsMain.h
./include/Stack61850.h
./include/StackSpac.h
./include/StackDnp3.h
./include/StackGserver.h
[qyang@pc6de4 ~/ns-allinone-2.28]$ find . -name "n?.*" -print under tcsh&bash
./tk8.4.5/library/msgs/nl.msg
./lib/tk8.4/msgs/nl.msg
./ns-2.28/ns-tutorial/ns.html
./ns-2.28/diffusion3/lib/nr/nr.cc
./ns-2.28/diffusion3/lib/nr/nr.o
./ns-2.28/diffusion3/lib/nr/nr.hh
./ns-2.28/doc/ns.bib
./ns-2.28/ns.1
find . -wholename './.metadata' -prune -o -print //exclude certain directory
find . ! -name '*.class' //exclude certain file pattern
[q.yang@localhost ProjProgrammingTest]$ find ./include/ -maxdepth 1 -name '*.h' -exec wc {} \;
line words characters
42 87 968 ./include/Misc.h
131 414 4487 ./include/CommsLinkSessionManager.h
DELETE ALL FOLDERS WITH CERTAIN NAME PATTERN
---------------------------------------------------
[q.yang@localhost ltib-qs]$ find . -noleaf -name '.svn' -exec rm -r -f {} \;
FIND STRING IN ALL CERTAIN FILES
------------------------------------------------------------
First one can show line number
[q.yang@localhost ltib-qs]$ fd "*.*con*" -print0 | xargs -0 grep MODLIST -rn
./config/profile/swang.config:301:CONFIG_SYSCFG_MODLIST=""
./config/profile/swang-poc.config:307:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/ChkGsnMake_Config.config:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/GsnMake.config:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/GsnMake.config.old:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/.config:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/RoofsToNAND_Flash.config:455:CONFIG_SYSCFG_MODLIST=""
This cannot show line number but just the string result after search
[q.yang@localhost Documentation]$ grep endpoint . -r *.txt
./MSI-HOWTO.txt:PCI Express endpoints uses INTx emulation (in-band messages) instead
./input/yealink.txt:A: The sysfs files are located on the particular usb endpoint. On most
./sound/alsa/Audiophile-Usb.txt:parse_audio_endpoints function uses a quirk called
./sound/alsa/soc/dapm.txt:An endpoint is a start or end point (widget) of an audio signal within the
./sound/alsa/soc/dapm.txt:snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);
FIND YUM PACKAGE BY KEY WORDS
---------------------------
[root@localhost q.yang]# yum search ppp
CHANGE ALL FOLDERS/FILES OWNERSHIP (user,group)
--------------------------------------------------
[q.yang@localhost ltib-qs]$ chown -c -R q.yang:q.yang .
LIST FILE SORTED BY TIME
------------------------------------------
[q.yang@localhost lpc3250]$ ls -lt ltib-qs/config/platform/phy3250/
//-------------------------------
//php+apache+msql installation
//
[root@QuentinFedoraHome q.yang]# rpm -qa | grep mysql
mysql-connector-java-3.1.12-5.fc9.i386
mysql-libs-5.0.51a-1.fc9.i386
[root@QuentinFedoraHome q.yang]# rpm -qa | grep httpd
httpd-tools-2.2.8-3.i386
httpd-2.2.8-3.i386
[root@QuentinFedoraHome q.yang]# rpm -qa | grep php
[root@QuentinFedoraHome q.yang]#
//------------------------------
//Svn relevant commands
//
Now, you use svn merge to replicate your branch changes back into the trunk.
$ pwd
/home/user/calc-trunk
$ svn update # (make sure the working copy is up to date)
At revision 390.
$ svn merge --reintegrate http://svn.example.com/repos/calc/branches/my-calc-branch
--- Merging differences between repository URLs into '.':
U button.c
U integer.c
U Makefile
U .
$ # build, test, verify, ...
$ svn commit -m "Merge my-calc-branch back into trunk!"
Sending .
Sending button.c
Sending integer.c
Sending Makefile
Transmitting file data ..
Committed revision 391.
[q.yang@QuentinFedoraHome ~]$ ssh-keygen -b 1024 -t dsa -N passphrase -f
keyfileGenerating public/private dsa key pair.
Your identification has been saved in keyfile.
Your public key has been saved in keyfile.pub.
The key fingerprint is:
50:81:da:e8:e9:b1:11:ec:f6:89:ac:3c:cf:a8:bd:05 q.yang@QuentinFedoraHome
[q.yang@QuentinFedoraHome ~]$ ls -l keyfile*
-rw------- 1 q.yang q.yang 744 2008-10-01 17:20 keyfile
-rw-r--r-- 1 q.yang q.yang 614 2008-10-01 17:20 keyfile.pub
http://tortoisesvn.net/ssh_howto
[q.yang@QuentinFedoraHome ~]$ svn list file:///var/svn/repos_personal/Doc_Documents
[q.yang@QuentinFedoraHome ~]$ svn import ~/Doc_Documents file:///var/svn/repos_personal/Doc_Documents -m "Initial import"
[q.yang@QuentinFedoraHome Svn_Repositories]$ svn checkout svn://10.1.1.7/var/svn/repos_personal/
$ svnadmin create /var/svn/newrepos
//-------------------------------------------
//Samba
//
[root@QuentinFedoraHome q.yang]# service smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
[root@QuentinFedoraHome q.yang]# chkconfig smb on
[root@QuentinFedoraHome q.yang]# system-config-users
[root@QuentinFedoraHome q.yang]# yum install system-config-samba
system-config-services gui services management
//-------------------------------------------
// VNC server in linux
//
#chkconfig vncserver on
#service vncserver restart
VNCSERVERS="1:q.yang 2:m.xie"
VNCSERVERARGS[1]="-geometry 1024x768 "
VNCSERVERARGS[2]="-geometry 800x600 "
[root@QuentinFedoraHome q.yang]# vi /etc/sysconfig/vncservers
[q.yang@QuentinFedoraHome Code_Shells]$ vncserver -kill:2
[tchung@tchung101 tchung]$ sudo /sbin/service iptables restart restart firewall
[root@QuentinFedoraHome Code_Shells]# vi /etc/sysconfig/iptables change firewall
#rpm -q vnc vnc-server
//-------------------------------------------
//user management chgrp,chown,useradd,passwd,chmod
//
[root@QuentinFedoraHome q.yang]# groupadd admin
[root@QuentinFedoraHome q.yang]# groupadd master
[root@QuentinFedoraHome q.yang]# groupadd family
[root@QuentinFedoraHome q.yang]# groupadd users
groupadd: group users exists
[root@QuentinFedoraHome q.yang]# vi /etc/default/useradd
[root@QuentinFedoraHome q.yang]# vi /etc/group
CHANGE USER'S GROUP
------------------------
[root@QuentinFedoraHome q.yang]# usermod -g admin -G users,family,master q.yang
[root@QuentinFedoraHome svn]# chmod 711 -R repos_personal/
[root@QuentinFedoraHome svn]# ll repos_personal/db/
total 28
-rwx--x--x 1 root root 6 2008-10-03 09:20 current
-rwx--x--x 1 q.yang root 2 2008-09-28 23:22 format
-rwx--x--x 1 q.yang root 5 2008-09-28 23:22 fs-type
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revprops
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revs
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 transactions
-rwx--x--x 1 q.yang root 37 2008-09-28 23:22 uuid
-rwx--x--x 1 q.yang root 0 2008-09-28 23:22 write-lock
[root@QuentinFedoraHome svn]# man chown
[root@QuentinFedoraHome svn]# man chown
[root@QuentinFedoraHome svn]# chown -R q.yang repos_personal/
[root@QuentinFedoraHome svn]# ll repos_personal/db/
total 28
-rwx--x--x 1 q.yang root 6 2008-10-03 09:20 current
-rwx--x--x 1 q.yang root 2 2008-09-28 23:22 format
-rwx--x--x 1 q.yang root 5 2008-09-28 23:22 fs-type
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revprops
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revs
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 transactions
-rwx--x--x 1 q.yang root 37 2008-09-28 23:22 uuid
-rwx--x--x 1 q.yang root 0 2008-09-28 23:22 write-lock
[root@QuentinFedoraHome svn]# ll
total 8
drwx--x--x 7 q.yang root 4096 2008-09-28 23:22 repos_personal
drwxrwxr-x 7 q.yang root 4096 2008-09-28 22:48 repos_projects
[root@QuentinFedoraHome svn]# chgrp -R 100 repos_projects/
[root@QuentinFedoraHome svn]# ll
total 8
drwx--x--x 7 q.yang root 4096 2008-09-28 23:22 repos_personal
drwxrwxr-x 7 q.yang users 4096 2008-09-28 22:48 repos_projects
[root@bigdog /root]# useradd blarg add account
[root@bigdog /root]# passwd blarg set pwd or change pwd(when user logged in)
yum list updates
yum update update system
yum list selinux-policy*
[root@blackrock .vnc]# yum list selinux-policy*
Loaded plugins: refresh-packagekit
Installed Packages
selinux-policy.noarch 3.3.1-55.fc9 installed
selinux-policy-devel.noarch 3.3.1-55.fc9 installed
selinux-policy-targeted.noarch 3.3.1-51.fc9 installed
Available Packages
selinux-policy-mls.noarch 3.3.1-51.fc9 updates
[root@blackrock /]# more ~topping/.vnc/blackrock.orb.org:1.log
:file ;display current file name
:set wrap ;wrap text
:set nowrap ;don't wrap text when display
:set winwidth ;set where to wrap text when editing file
cp [-drsu] u is used for update of file used for backup
/etc/rc.d/init.d ./smb start ./smb stop ./smb restart
$cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd ; then delete all other password lines
smbpasswd -a QuentinYANG ; add samba password for user QuentinYANG
testparm ;test samba service from smb.conf
smbclient -L localhost ;list samba service on localhost or other ip address
ifconfig eth0 10.0.0.23
df -h list disk occupacy infor
du -s
rpm -q -a > /home/packages.log
rpm -ivf --nodeps --force
grep hp /home/packages.log
grep instance . -R -recursive searching subdirectories
grep -i -r --include=*.txt Q: ~/Doc_PdfTxtHtm/ -i means ignor the case, --include, --exclude=PATTERN means can search only some files with such a PATTER
grep timer . -r *.java (is a simple way to serch some text pattern like "timer" in all *.java files of all subdirectories)
egrep -i 'Average | x ' ~/driver_heartbeat_debug_01.log '|' means, match either pattern, here we have to use egrep for extend searching
egrep "id\(\<$NodeId\>|\<$NodeId2\>|\<$NodeId3\>" temp.log > temp1.log
rpm -e scim scim-tables scim-chewing
rpm -q scim -i
nmap -v 130.130.10.126
/sbin/ifconfig list ip address
route
ps -aux | grep pdf list all process
kill 19862 kill process with pid
ls -D all
ll -cX ./Doc_PdfTxtHtm/ -c means sort by file name, time,-X by file extention
ll -t ./Doc_PdfTxtHtm/ -t sort by file change time
# learn wht is the different of single quotation mark and double quotation mark
# and how to search two types of files with different extention name at the
# same time
echo "fd "*.*" |egrep '*.jpy|*.bsh'" >> ~/Doc_PdfTxtHtm/linux_commandlist.txt
fd *.* |egrep '*.jpy|*.bsh'
echo "fd '"*.*"' |egrep '*.jpy|*.bsh'" >> ~/Doc_PdfTxtHtm/linux_commandlist.txt
fd '*.*' |egrep '*.jpy|*.bsh'
echo "fd \"*.*\" |egrep '*.jpy|*.bsh'" >> ~/Doc_PdfTxtHtm/linux_commandlist.txt
fd "*.*" |egrep '*.jpy|*.bsh'
ln -s ~/Doc_PdfTxtHtm/link_list.txt .
mv -v * ~/MyMac/
fd *.jar -exec jar tvf {} \; |grep InputStreamReader
fd "*.java" -mtime -5
touch eclipseMyMac.tar
fd "*.java" -mtime -5 -exec tar -uvf eclipseMyMac.tar {} \;
grep "found neighbour:" . -r -n *.java // search string pattern in *.java files under all subdirectories and printout line number in that file as well
fd "*.java" -print0 | xargs -0 grep log -rn //search string pattern in files generated from file search result
find . -wholename './.metadata' -prune -o -print //exclude certain directory
find . ! -name '*.class' //exclude certain file pattern
fd "*.java" -mtime -8 -exec ls -all -ct {} \; // search files changed over last 8 days and list their time stamp and sorted by changed time
date +%g%m%d%H //06100123 yymmddhh date shell
#uname -r or #rpm -q kernel //list the kernel version
. logAnalysis.sh 16 ringInfo16135050_appcw1000.log | cut -d" " -f1 //cut -d define what symbole is used to seperate input string. -f define what field to print, 1st or 2nd after cutting.
. logAnalysis.sh 16 ringInfo16135050_appcw1000.log | cut -d" " -f1 | uniq -c | sort -rn
// uniq -c will count number of repeat times of same patten lines. sort -rn
// sort all lines according to the number of repeat times.
cscope -b
cscope -R
ctags -n -f cppcomplete.tags --fields=+ai --C++-types=+p * -L cscope.files
cvs -d /usr/local/newrepos init //create repository in path /usr/local/newrepos
cvs import -d -m "initial import into CVS from eclipse MyMac on Mimir" MyMacProj quentin start //-d option to keep modified time CVS_ROOT already set up, so import to CVS root directory, import files to repository, execute this command on top level of ur project folder which u want to add to repository
cvs checkout MyMacProj //check out one work copy in the folder u want to edit
cvs status ./src/jist/swans/app/AppRingschedule.java
cvs log ./src/jist/swans/app/AppRingschedule.java
cvs ci -m"back to the stage passing growth of tree"
cvs update
cvs -q tag Release-2006_09_30 // add tag to all files at their current version
cvs -q tag Release-2006_10_06-AdditiveRadioSNR
cvs tag Backup-2006_10_11-HalfwayStartScheduling ./src/jist/swans/mac/MacCsmaCa.java
cvs co -r Release-2006_09_30 MyMacProj //check out a work copy based on one tag "Release-2006_09_30"
cvs update -r Release-2006_09_30 // get a snapshot of one version with tag, without checkout all the files
cvs update -d // run update with the -d flag, telling it to bring down any new directories from the repository.
cvs update -P // prune useless directiories
cvs status ./src/driver/ringschedule.java //check on file status, u can see the Sticky Tag: Release-2006_09_30 (revision: 1.1.1.1)
cvs -q update -A ./src/driver/ringschedule.java // release the sticky state of one file so that get the latest version of this file
cvs -d:pserver:anon@jist.ece.cornell.edu:/cvs-jist login
cvs -d:ext:quentin@mimir.snrc.uow.edu.au:/home/quentin/CvsMyMac login
cvs -Q update -p -r 1.3 hello.c > hello.c //reverse to previous version
yarkon$ cvs add newfile.c //add files
yarkon$ cvs ci -m "added newfile.c" newfile.c
yarkon$ mkdir c-subdir
yarkon$ cvs add c-subdir
yarkon$ rm newfile.c //remove files
yarkon$ cvs remove newfile.c
yarkon$ cvs ci -m "removed newfile.c" newfile.c
yarkon$ rm file1 file2 file3 //remove directories
yarkon$ cvs remove file1 file2 file3
yarkon$ cvs ci -m "removed all files" file1 file2 file3
yarkon$ cd ..
yarkon$ cvs update -P
yarkon$ mv oldname newname //rename files
yarkon$ cvs remove oldname
yarkon$ cvs add newname
yarkon$ cvs ci -m "renamed oldname to newname" oldname newname
yarkon$ mkdir newdir //rename directories
yarkon$ cvs add newdir
yarkon$ mv olddir/* newdir
yarkon$ cd olddir
yarkon$ cvs rm foo.c bar.txt
yarkon$ cd ../newdir
yarkon$ cvs add foo.c bar.txt
yarkon$ cd ..
yarkon$ cvs commit -m "moved foo.c and bar.txt from olddir to newdir"
yarkon$ cvs update -P
ls . -R -D | grep /CVS | cut -d ":" -f1
////////////////////////////////////////////////////////////////////////
// Quentin study notes for unix
// focus on the command list in unix
// time History Author
// 6/9/2004 Created Quentin.YANG
// 17/8/2005 update in UOW Quentin.YANG
add vi guide;
// 18/8/2005 add web resource section Quentin.YANG
looking for LaTax-article
editing tool
// 25/8/2005 add linux config guide(CN)
// add Bash section
// add emacs section
// 20/6/2006 how to create own shell
//
//
// 29/6/2006 command combination list
///////////////////////////////////////////////////////////////////////
[root @test /root ]# cp [-drsu] [来源档] [目的档]
参数说明:
-d :在进行 copy 的时候,如果是 copy 到 link 档案,若不加任何参数,则预设情
况中会将 link 到的源文件copy 到目的地,若加 -d 时,则 link 档案可原封不动的将 link 这个
快捷方式其拷贝到目的地!
-r :可以进行目录的 copy 呦!
-s :做成连结档,而不 copy 之意!与 ln 指令相同功能!
-u, --update:如果来源档比较新,或者是没有目的档,那么才会进行 copy 的动作!可用于备
份的动作中
q: Rename directory? --wht unix command? A: just use mv
Q: wht is the difference between gzip and zip/unzip? //gzip -v -d abcd.gz
Alias? alias is set up in ~/.bashr
Q: How to recover files in Linux? How do use trash in linux?
如何查看硬件的芯片??
[root@linuxsir01 root]# lspci -v
要说明系统、版本以及内核的版本,用下面的命令来测试,
#uname –a
linux version:
/etc/redhat-release
新手有时对vi vim emacs 不太熟悉,这需要更适合新手用的文本编辑器。比如GNOME中的 gedit ,KDE中的kwrite或者kate等。
如果您用KDE或者GNOME,发行版中都有 gedit 或者kwrite,也应该有xedit 。
如果您是初学Linux,只是想找一些象Windows写字板那样简单功能的编辑器,leafpad 和mousepad足够用。如果在linux text模式下操作,不会用vi或者vim的情况下,用nano修改文件也是足够了。
本帖专为新手准备,希望能对初学Linux的弟兄有所帮助。
rpm -qa | grep vnc
把上面那些rpm都DOWN下来到一个文件夹。。。然后在控制台下输入:
#cd [你DOWN下RPM的文件夹]
#rpm -ivh *.rpm
rpm install, pacage management, refer to man rpm
这样全都OK了。。。。
兄弟,请看!
ftp://ftp.gtk.org/pub/gtk/v2.0/binary/old/RedHat-7.2/RPMS/i386/
rpm安装最简单。。。。。试一下吧。。有问题再发帖。。。
不要急,这就是学习。。。
--------------------------------------------------------------------------------
qepafrps02-06-21, 21:35
是呀,这里都是.rpm,不过很多呀,是不是还是把gtk,atk,glib,pango,这几个下了,一个一个的安呀,难道没有一个总的.rpm的那种吗?
========================= command combination list ===========================
$ls -all | less
$ls -all | grep .jar
$ls -all -R | grep .jar
$su temporary change user, default change to root so that having right to install software
=========== how to create own shell to backup personal files================
# fgrep bball etc/passwd
bball : x : 100 : 100 : William H. Ball , , , , : /home/bball : /bin/bash
==========Bash============================
bash的内建叁数很多,你可以自行"man bash"查一查。这里我只说明一些常用
及重要的。
PPID : 该bash的呼叫者process ID.
PWD : 目前的工作目录。
OLDPWD : 上一个工作目录。
HOSTTYPE : 机器种类。
OSTYPE : 作业系统名称。
PATH : 命令搜寻路径。
PATH="/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:."
发帖时间: 02-12-15, 02:58
查看系统环境变量的方法是用set,这是在bash下的。
[root@linuxsir01 root]# set
大熊宝宝说的也是一个方法,这个方法写入后,就不会使变量设置重新启动后丢失。
也可以这样做。。
改用户目录下的.bashrc
加入
PATH="$PATH:/tmp"
_____________________________________
请弟兄们发帖时要写个好标题,多谢!
签名不支持html和bbcode,请弟兄为了版面的整洁,请更改签名档,谢谢!
请各版版主及初学Linux的弟兄,请在您的签名写上机器的配置,以及您所用的系统(包装版本号,内核),谢谢。
Slackintosh 10.1+kernel-2.6.11.8+xfce-4.2.1.1
=====================================
帮助那些需要帮助的人── 吾师语录
世上没有踏不平的山,只有走不完的路!── 师兄语录
HOME : 目前使用者的home directory
Section=========emacs,==============================
C means Ctl key, M means Alt key;
control cursor C-p,C-n,C-b,C-f;M-f;(move by words) C-l center the text to your cursor;
C-a,C-e; move the start and end of one line;
C-h w command - to check which key bind to the command
;; C-h k key - to check which command the key bind to
;; C-j - run the lisp command(put the cursor at end)
;;
;; C-c C-t - change mode to hungry-state and auto-state
;; C-c C-a - change mode to auto-state
;; C-c C-d - change mode to hungry-state
;; C-c C-e - expand macro
;; C-c C-\ - add '\' at then end of the line
;; C-u C-s - regular expression search
;; C-x 5 2 - open new frame
;; C-x 5 0 - close new frame
;;
;; M-; - insert a comment
;; M-\ - fixup whitespace
;; M-/ - auto complete the word
;; M-l - downcase-word
;;
;; Mark the region, then
;;
;; C-x r k - kill rectangle
;; C-x r t - insert word in columns
C-x C-f :打开/新建文件
C-x S :保存所有缓冲区文件
C-x C-v:在当前缓冲区打开文件
C-x k :关闭当前缓冲区
C-x i : 在当前光标位置插入文件
M-x replace-string: 一次性替换字符串
M-x % : 循环替换。
C-s
C-r :查询
C-@ :设置标记,然后选取
C-w :相当于剪切。
M-w :相当于复制
C-y :粘贴
M-y : 循环粘贴。
C-o:开新行
C-f, C-b, C-p, C-n, M-f, M-b, C-v , M-v , C-l, M-< 移动。M->,
C - !, 一次性执行shell, M-x shell, 启动shell外壳。
M-x compile:编译程序。
Under cygwin, C-x,C-c does not work to exit emacs; have to press F10, then f,e to exit emacs; Also, C-h,C-t does not enter tutorial, Try to use F1 and then option ? then "t", emacs tutorial;
Section ======unix=========================================================
after ns2 install
----------------------------------------------------------------------------------
Please put /home/qyang/ns-allinone-2.28/bin:/home/qyang/ns-allinone-2.28/tcl8.4.5/unix:/home/qyang/ns-allinone-2.28/tk8.4.5/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put /home/qyang/ns-allinone-2.28/otcl-1.9, /home/qyang/ns-allinone-2.28/lib,
into your LD_LIBRARY_PATH environment variable.
If it complains about X libraries, add path to your X libraries
into LD_LIBRARY_PATH.
If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH
If you are using sh, you can set it like:
export LD_LIBRARY_PATH=
(2) You MUST put /home/qyang/ns-allinone-2.28/tcl8.4.5/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.
(3) [OPTIONAL] To save disk space, you can now delete directories tcl8.4.5
and tk8.4.5. They are now installed under /home/qyang/ns-allinone-2.28/{bin,include,lib}
After these steps, you can now run the ns validation suite with
cd ns-2.28; ./validate
For trouble shooting, please first read ns problems page
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.
gunzip,unzip,tar;if forget the option can use "$tar --help"
Ctr+C;terminate process;
edit ~/.bashrc,set your ENV;
try to find the path of some command by "where" only availabe under Tcsh
[qyang@pc6de4 ~]$ where is tcsh
---/bin/tcsh
[qyang@pc6de4 ~]$ pwd
/home/qyang
[qyang@pc6de4 ~]$ ls /
bin dev home lib misc opt root selinux tmp var
boot etc initrd lost+found mnt proc sbin sys usr
[qyang@pc6de4 ~]$ ls /bin
arch cpio env kill netstat sed traceroute
ash csh ex link nice setfont traceroute6
ash.static cut false ln nisdomainname setserial true
aumix-minimal date fgrep loadkeys pgawk sh umount
awk dd gawk login ping sleep uname
basename df gettext ls ping6 sort unicode_start
bash dmesg grep mail ps stty unicode_stop
bash2 dnsdomainname gtar mkdir pwd su unlink
bsh doexec gunzip mknod red sync usleep
cat domainname gzip mktemp rm tar vi
chgrp dumpkeys hostname more rmdir tcsh view
chmod echo igawk mount rpm touch ypdomainname
chown ed ipcalc mt rvi tracepath zcat
cp egrep kbd_mode mv rview tracepath6
[qyang@pc6de4 ~]$ emacs
[qyang@pc6de4 ~]$ wher is emacs
wher: Command not found.
[qyang@pc6de4 ~]$ where is emacs
---/usr/bin/emacs
Section--from /for_unix_beginner/-----
--% echo $OSTYPE
USER (your login name)
HOME (the path name of your home directory)
HOST (the name of the computer you are using)
ARCH (the architecture of the computers processor)
DISPLAY (the name of the computer screen to display X windows)
PRINTER (the default printer to send print jobs)
PATH (the directories the shell should search to find a command)
setenv; printenv or env; unsetenv; ENVIRONMENT variables are set using the command, displayed using the commands, and unset using the command
--% printenv | less show all values of these variables, type |less can not work in Cygwin
--% set | less To show all values of these variables, type |less can not work in Cygwin
--The C and TC shells uses two files called .login and .cshrc (note that both file names begin with a dot).Information in these files is used to set up your working environment.
% set history = 200
% echo $history
To PERMANENTLY set the value of history, you will need to add the set command to the .cshrc file
% nedit ~/.cshrc
% source .cshrc Save the file and force the shell to reread its .cshrc file buy using the shell source command
% "set path = ($path ~/units174/bin)" add it to the end of your existing path (the $path represents this) by issuing the command can't work under unix bash; can work after chang it to "export PATH=($PATH ~/units174/bin)"
% cd; pwd HINT: You can run multiple commands on one line by separating them with a semicolon.
Section----shortcut key--------
right click to paste;
Section=================----vi------------------
一、Unix编辑器概述
编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件。Unix及其相似的ix操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编辑器,包括 ex, edit,ed 和vi.其中ex,edit,ed都是行编辑器,现在已很少有人使用,Unix提供他们的原因是考虑到满足各种用户特别是某些终端用户的需要。
值得庆幸的是,Unix提供了全屏幕的Vi编辑器,这使我们的工作轻松不少。不少DOS用户抱怨Vi编辑器不象DOS下的编辑器如edit那么好用,这是因为Vi考虑到各种用户的需要,没有使用某些通用的编辑键(在各个不同的终端机上他们的定义是不同的,在某些终端机上甚至没有这些键)。而是采用状态切换的方法,但这只是习惯的问题,一旦你熟练的使用上了vi你就会觉得它其实也很好用。虽然 Vi采用了状态切换的方法,但电脑的硬件及操作系统多种多样,某些电脑的键盘上没有特定的几个功能键!那麽不就有某些功能不能用了?这个问题在 Unix 系统上也一样,几乎各大电脑厂商都有自己的Unix 系统,而 vi 的操作方法也会随之有点出入。这里我们采用 PC 的键盘来说明 vi 的操作,但在具体的环境中还要参考相应的资料,这一点是值得注意的。
二、Vi入门
(一)、进入vi
在系统提示字符(如$、#)下敲入vi <档案名称>,vi 可以自动帮你载入所要编辑的文件或是开启一个新文件(如果该文件不存在或缺少文件名)。进入 vi 后萤幕左方会出现波浪符号,凡是列首有该符号就代表此列目前是空的。
(二)、两种模式
如上所述,vi存在两种模式:指令模式和输入模式。在指令模式下输入的按键将做为指令来处理:如输入a,vi即认为是在当前位置插入字符。而在输入模式下,vi则把输入的按键当作插入的字符来处理。指令模式切换到输入模式只需键入相应的输入命令即可(如a,A),而要从输入模式切换到指令模式,则需在输入模式下键入ESC键,如果不晓得现在是处於什麽模式,可以多按几次 [ESC],系统如发出哔哔声就表示已处于指令模式下了。
付:有指令模式进入输入模式的指令:
新增 (append)
a :从光标所在位置後面开始新增资料,光标後的资料随新增资料向後移动。
A: 从光标所在列最後面的地方开始新增资料。
插入 (insert)
i: 从光标所在位置前面开始插入资料,光标後的资料随新增资料向後移动。
I :从光标所在列的第一个非空白字元前面开始插入资料。
开始 (open)
o :在光标所在列下新增一列并进入输入模式。
O: 在光标所在列上方新增一列并进入输入模式。
(三)、退出vi
在指令模式下键入:q,:q!,:wq或:x(注意:号),就会退出vi。其中:wq和:x是存盘退出,而:q是直接退出,如果文件已有新的变化,vi会提示你保存文件而:q命令也会失效,这时你可以用:w命令保存文件后再用:q退出,或用:wq或:x命令退出,如果你不想保存改变后的文件,你就需要用:q!命令,这个命令将不保存文件而直接退出vi。
(四)、基本编辑
配合一般键盘上的功能键,像是方向键、[Insert] 、[Delete] 等等,现在你应该已经可以利用 vi 来编辑文件了。当然 vi 还提供其他许许多多功能让文字的处理更为方便。
何谓编辑?一般认为是文字的新增、修改以及删除,甚至包括文字区块的搬移、复制等等。先这里介绍 vi的如何做删除与修改。(注意:在 vi 的原始观念里,输入跟编辑是两码子事。编辑是在指令模式下操作的,先利用指令移动光标来定位要进行编辑的地方,然後才下指令做编辑。)
删除与修改文件的命令:
x: 删除光标所在字符。
dd :删除光标所在的列。
r :修改光标所在字元,r 後接著要修正的字符。
R: 进入取替换状态,新增文字会覆盖原先文字,直到按 [ESC] 回到指令模式下为止。
s: 删除光标所在字元,并进入输入模式。
S: 删除光标所在的列,并进入输入模式
其实呢,在PC上根本没有这麽麻烦!输入跟编辑都可以在输入模式下完成。例如要删除字元,直接按[Delete] 不就得了。而插入状态与取代状态可以直接用 [Insert] 切换,犯不著用什麽指令模式的编辑指令。不过就如前面所提到的,这些指令几乎是每台终端机都能用,而不是仅仅在 PC 上。
在指令模式下移动光标的基本指令是 h, j, k, l 。想来各位现在也应该能猜到只要直接用 PC 的方向键就可以了,而且无论在指令模式或输入模式下都可以。多容易不是。
当然 PC 键盘也有不足之处。有个很好用的指令 u 可以恢复被删除的文字,而 U 指令则可以恢复光标所在列的所有改变。这与某些电脑上的 [Undo] 按键功能相同。
三、附件:vi详细指令表
(一)、基本编辑指令:
新增 (append)
a :从光标所在位置後面开始新增资料,光标後的资料随新增资料向後移动。
A: 从光标所在列最後面的地方开始新增资料。
插入 (insert)
i: 从光标所在位置前面开始插入资料,光标後的资料随新增资料向後移动。
I :从光标所在列的第一个非空白字元前面开始插入资料。
开始 (open)
o :在光标所在列下新增一列并进入输入模式。
O: 在光标所在列上方新增一列并进入输入模式。
x: 删除光标所在字符。
dd :删除光标所在的列。
r :修改光标所在字元,r 後接著要修正的字符。
R: 进入取替换状态,新增文字会覆盖原先文字,直到按 [ESC] 回到指令模式下为止。
s: 删除光标所在字元,并进入输入模式。
S: 删除光标所在的列,并进入输入模式。
(二)、光标移动指令:
由於许多编辑工作是藉由光标来定位,所以 vi 提供许多移动光标的方式,这个我们列
几张简表来说明(这些当然是指令模式下的指令):
指令 说明 功能键
0 移动到光标所在列的最前面 [Home]
$ 移动到光标所在列的最後面 [End]
[CTRL][d] 向下半页 [PageDown]
[CTRL][f] 向下一页
[CTRL][u] 向上半页
[CTRL][b] 向上一页 [PageUp]
指令 说明
H 移动到视窗的第一列
M 移动到视窗的中间列
L 移动到视窗的最後列
b 移动到下个字的第一个字母
w 移缴细鲎值牡谝桓鲎帜?nbsp;
e 移动到下个字的最後一个字母
^ 移动到光标所在列的第一个非空白字元
指令 说明
n- 减号移动到上一列的第一个非空白字元前面加上数字可以指定移动到以上 n 列
n+ 加号移动到下一列的第一个非空白字元前面加上数字可以指定移动到以下 n 列
nG 直接用数字 n 加上大写 G 移动到第 n 列
指令 说明
fx
往右移动到 x 字元上
Fx 往左移动到 x 字元上
tx 往右移动到 x 字元前
Tx 往左移动到 x 字元前
; 配合 f&t 使用,重复一次
, 配合 f&t 使用,反方向重复一次
/string 往右移动到有 string 的地方
?string 往左移动到有 string 的地方
n 配合 /&? 使用,重复一次
N 配合 /&? 使用,反方向重复一次
指令 说明 备注
n(
左括号移动到句子的最前面句子是以前面加上数字可以指定往前移动 n 个句子 ! . ? 三种符号来界定
n) 右括号移动到下个句子的最前面前面加上数字可以指定往後移动 n 个句子 ! . ? 三种符号来界定
n{ 左括弧移动到段落的最前面 段落是以段落间的空白列界定
n} 前面加上数字可以指定往前移动 n 个段落右括弧移动到下个段落的最前面前面加上数字可以指定往後移动 n 个段落 段落是以段落间的空白列界定
(三)、更多的编辑指令
这些编辑指令非常有弹性,基本上可以说是由指令与范围所构成。例如 dw 怯缮境噶?nbsp;d 与范围 w 所组成,代表删除一个字 d(elete) w(ord) 。
指令列表如下:
d 删除(delete)
y 复制(yank)
p 放置(put)
c 修改(change)
范围可以是下列几个:
e 光晁谖恢玫礁米值淖钺嵋桓鲎帜?br> w 光标所在位置到下个字的第一个字母
b 光标所在位置到上个字的第一个字母
$ 光标所在位置到该列的最後一个字母
0 光标所在位置到该列的第一个字母
) 光标所在位置到下个句子的第一个字母
( 光标所在位置到该句子的第一个字母
} 光标所在位置到该段落的最後一个字母
{ 光标所在位置到该段落的第一个字母
说实在的,组合这些指令来编辑文件有一点点艺术气息。不管怎麽样,它们提供更多编辑文字的能力。值得注意的一点是删除与复制都会将指定范围的内容放到暂存区里,然後就可以用指令 p 贴到其它地方去,这是 vi 用来处理区段拷贝与搬移的办法。
某些 vi 版本,例如 Linux 所用的 elvis 可以大幅简化这一坨指令。如果稍微观察一下这些编辑指令就会发现问题其实是定范围的方式有点杂,实际上只有四个指令罢了。指令 v 非常好用,只要按下 v 键,光标所在的位置就会反白,然後就可以移动光标来设定范围,接著再直接下指令进行编辑即可。对於整列操作, vi 另外提供了更方便的编辑指令。前面曾经提到过删除整列文字的指令 dd 就是其中一个;cc 可以修改整列文字;而 yy 则是复制整列文字;指令 D 则可以删除光标到该列结束为止所有的文字。
(四)、文件操作指令
文件操作指令多以 : 开头,这跟编辑指令有点区别。
:q 结束编辑(quit)
:q! 不存档而要放弃编辑过的文件。
:w 保存文件(write)其後可加所要存档的档名。
:wq 即存档後离开。
zz 功能与 :wq 相同。
:x 与:wq相同
-----------------------
========cygwin=================
发帖时间: 05-05-08, 23:53
谢谢,楼上指点。
1楼说的那个没有看到
2楼的方法试过了。最快的是ftp://ftp.cise.ufl.edu
当然我不是全部试过,不过ping了20个肯定不只。这个最快只有200多ms的延时。我是电信的。
大家以后可以试试。
度我也试过了爽,我2M带宽下载速度达到100K接近。^_^~!!!!大家试试吧。
~~~~5分钟后,我又来了。装好了。^_^
这里的热情让我激动不已。
uname -a returns following output:
CYGWIN_NT-5.0 PCS734 1.3.5(0.47/3/2) 2001-11-13 23:16 i686 unknown
--install the ns under cygwin must under bash;
Please put /home/ns2/ns-allinone-2.28/bin:/home/ns2/ns-allinone-2.28/tcl8.4.5/unix:/home/ns2/ns-allinone-2.28/tk8.4.5/unix into your PATH; so that u will be able to run itm/tclsh/wish/xgraph.
important notices:
1. must put /home/ns2/ns-allinone-2.28/otcl-1.9, /home/ns2/ns-allinone-2.28/lib into your LD_LIBRARY_PATH variable;if it complains about X libraries, add path to your X libraries into LD_LIBRARY_PATH.
using csh, can set it like: setenv LD_LIBRARY_PATH
using sh, set like this: export LD_LIBRARY_PATH=
2. must put /home/ns2/ns-allinone-2.28/tcl8.4.5/library into ur TCL_LIBRARY env variable. otherwise, ns/nam will complain during startup
3. optional, to save disk space, u can delete directories tcl8.4.5 and tk8.4.5 installed under /home/ns2/ns-allinone-2.28/{bin,include,lib}
after this u can run ns validation suite with cd ns-2.28; ./validate
---set path for ns2----------------------
PATH="$PATH:/home/qyang/ns-allinone-2.28/bin:/home/qyang/ns-allinone-2.28/tcl8.4
.5/unix:/home/qyang/ns-allinone-2.28/tk8.4.5/unix"
#set env LD_LIBRARY_PATH /home/ns2/ns-allinone-2.28/otcl-1.9 wrong
#set env /home/ns2/ns-allinone-2.28/lib wrong
#no command setenv
#set LD_LIBRARY_PATH=/home/qyang/ns-allinone-2.28/otcl-1.9 wrong
#set env LD_LIBRARY_PATH /home/qyang/ns-allinone-2.28/lib wrong
#export LD_LIBRARY_PATH=/home/qyang/ns-allinone-2.28/otcl-1.9
#export LD_LIBRARY_PATH=/home/qyang/ns-allinone-2.28/lib
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/qyang/ns-allinone-2.28/otcl-1.9:/home/qy
ang/ns-allinone-2.28/lib"
u user
g group
o other
a all
r read
w write (and delete)
x execute (and access directory)
+ add permission
- take away permission
% chmod go-rwx biglist
% chmod a+rw biglist
cp file1 file2 copy file1 and call it file2
mv file1 file2 move or rename file1 to file2
rm file remove a file
rmdir directory remove a directory
cat file display a file
more file display a file a page at a time
head file display the first few lines of a file
tail file display the last few lines of a file
grep 'keyword' file search a file for keywords
wc file count number of lines/words/characters in file
还可以通过使用- R选项连同子目录下的文件一起设置:
chmod -R 664 /usr/local/home/dave/*
有相当一些U N I X命令也设置了s u i d和g u i d。如果想找出这些命令,可以进入/ b i n或/ s b i n目
录,执行下面的命令:
$ ls -l | grep '^...s'
上面的命令是用来查找s u i d文件的;
$ ls -l | grep '^...s..s'
u m a s k命令来改变文件创建的缺省权限
软链接实际上就是一个指向文件的指针。你将会发现这种软链接使用起来非常方便。你可以在每一位用户的$ H O M E目录下建立一个指向该文件的链接,而不是在每个目录下拷贝一份。这样当需要更改这一文
件时,只需改变一个源文件即可
$ find . -perm 755 -print
$ find ~ -user dave -print
$ find . -newer age.awk ! -newer belts.awk -exec ls -l {} \;
$touch -t 05042140 dstamp
在当前的文件系统中查找文件(不进入其他文件系统),可以使用f i n d命令的m o u n t选项
$ find . -name "*.XC" -mount -print
% echo $history
% set | less
.cshrc or .login
% nedit ~/.cshrc
% source .cshrc
% set path = ($path ~/units174/bin) //add to variable path
% cd; units //HINT: You can run multiple commands on one line by separating them with a semicolon.
$0$1$2$3$$$?$# --014.pdf-p143 shell编程和unix命令
使用u n s e t命令清除环境变量:
Section===============新手入门循序渐进学习LINUX之软件配置=======================
LINUX配置
在这里,配置的对象并非内核,而是软件。至于网络的配置,主要在安装系统是已经基本完成;也可以进入GUI界面从菜单选择liloconf来配置。
与WINDOWS一样,在LINUX系统可以从光盘、软盘安装应用软件;但不同的是,它需要用命令mount来登录光驱、软驱。而且,软件大多是经过压缩的,所以还需要懂得如何解压。最后必须配置、编译才能运行。下面分四个方面进行介绍:
一、mount登录
LINUX的软驱设备用特殊文件/dev/fd0,文件系统是msdos,因此用以下命令登录,读取软盘内容:
# mount -t msdos /dev/fd0 /mnt/floppy
# cd /mnt/floppy
同理,键入以下命令读光盘:
# mount -t iso9660 /dev/hdb /mnt/cdrom
# cd /mnt/cdrom
然后,用cp命令将所需的软件拷贝到系统中。
退出软驱、光驱用umount命令。注意,不能在其目录中使用此命令,而应先cd到其他目录,再使用:umount /mnt/cdrom。
二、安装软件
for
LINUX的软件一般是以.gz或.tar或者.tar.gz结尾的。前者是由gzip压缩的,后者是先用tar归档,在用gzip压缩而成的。
1、以.gz结尾的为压缩文件,用命令:gzip -d filename来解压,得到的文件在当前目录中,但已没有了.gz。
2、以.tar结尾的为归档文件,用命令:tar -xvf filename来展开,生成的文件与源文件在同一目录中,只是少了.tar。
3、以.tar.gz结尾的文件最常见,可直接用命令:gzip -cd filename | tar xfv -来安装。
一般情况下,这类文件的第一项是一个目录,所以用上面的命令时会创建出这一个目录,并把所有的文件都存在此目录之下。如果是特殊情况,可先用命令:tar
-tvf filename | more 来查看文件的第一项。倘若它并不是目录,则先创建一个目录,把文件放在此目录之下,在用命令:tar
-xvf filename来安装。
经过以上步骤,会生成README及INSTALL等文件。用vi来仔细阅读这些文件造处于LINUX有关的部分,更具体是进行配置。一般的步骤是:(1)./config,(2)make
install,(3)make。主要的变化在第一步,其后面需要参数,可见入命令来选择:./config --help。
三、实践举例笔者曾配置了apache(阿帕其服务器)、php3两个软件。
先从网上下载for LINUX的软件apache.tar.gz、php3.tar.gz。
1、由于apache.tar.gz大于1.44M,所以笔者在center_5的MSDOS上用telnet命令登录LINUX,通过put将其上传。
2、笔者将这两个软件放在/usr/src目录之下,用命令gzip -cd apache.tar.gz(php3.tar.gz)|
tar xfv -来安装。这样会看到两个目录:apache_1.3.6和php-3.0.7。
3、在第一个目录之下,会看到非常重要的文件:README、INSTALL。如果此时是在GUI界面,则可以打开两个xterm,一个用于仔细阅读,一个则用于根据文件的提示进行配置。
4、在第二个目录中,也会很快的找到文件:INSTALL、INSTALL.DSO、README.QNX。步骤与3相似。由于这两个文件相互关联,必须先配置前者。
5、配置完后,进入/apache_1.3.6/conf/httpd.conf。在文件里面,理解其注释,删除或增加一些选项前的"#"。保存文件后,执行命令/usr/src/apache_1.3.6/bin/apachectl
start,即打开http,然后可以在Netscape Communication来浏览网页。
心得体会在学习的一个多月来,笔者面对的是一个全新的操作系统,绝大多数操作是通过自己键入命令来实现的,从而能够深入到一定层次的了解操作系统内核。
1、懂得了UNIX的一些基本命令;
2、熟悉vi文本编辑;
3、知道如何在LINUX、UNIX上编写、编译C、C++、JAVA程序;
4、进一步了解了网络原理,动手配置了网络应用软件,从而也清楚了软件安装的一般步骤。
5、毕竟现今for LINUX的应用软件少,而且RedHat
LINUX不支持中文,因而还不能完全脱离WINDOWS。因此,应发挥LINUX是一个非常优秀的网络服务器操作系统的优点,扬长避短。
=================from linuxsir bbs ==============
用dos的引导盘使用fdisk /mbr清除引导区信息!
然后用redhat的第一张光盘引导,进入linux rescue模式!
重新安装grub!
发帖时间: 05-03-31, 00:05
在GRUB中用单用户模式进去~~
然后vi /etc/shadow 找到ROOT把ROOT后一个MD5格式的字符串"干掉".保存~然后重启重新用单用户模式进入passwd root 自己输入需要的密码就好了~
--this can work by quentin, root:xxxxx:19333:....., just delete the xxx between colon. verified under red hat linux.
类似这样的,然后把键盘移动到该句,再按一下[e]键,在类似的语句后面加上 linux single。然后就按回车[enter]。然后出现另外一个界面,按一个[b]键。这样GRUB就把系统引入单用户模式了。
可能出现的是这样的。。。 just add linux single, can enter single mode, verified by quentin under red hat.
http://www.linuxsir.org/bbs/showthread.php?s=&threadid=16998 在GRUB系统引导程序下进入单用户模式的办法
http://www.linuxsir.org/bbs/showthread.php?s=&threadid=8721
http://www.linuxsir.org/bbs/showthread.php?s=&threadid=3393
发帖时间: 02-07-28, 00:48
让系统自动加载FAT32
用下面这个命令来判断我们的windows分区,这个命令能把所有硬盘上的分区都能列出来。这个命令比较强,哈。。最适合不知道自己的硬盘情况的弟兄。。。
[root@LinuxSir root]# fdisk -l
如果只列一个硬盘的可用下面这个命令,下面这两条命令,第一条是列第一个硬盘的,第二个是列第二个硬盘的,这两条命令和 fdisk -l结合起来,配合来用,效果最佳。我以我的硬盘来说。。。。也能用第一个命令。。这个比较简单,试一下就知道了
#fdisk -l /dev/hda
#fdisk -l /dev/hdb
Disk /dev/hda: 255 heads, 63 sectors, 4865 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 1147 9213246 7 HPFS/NTFS
/dev/hda2 1148 4864 29856802+ f Win95 Ext'd (LBA)
/dev/hda5 1148 2039 7164958+ 7 HPFS/NTFS
/dev/hda6 2040 2804 6144831 b Win95 FAT32
/dev/hda7 2805 3824 8193118+ b Win95 FAT32
/dev/hda8 3825 3830 48163+ 83 Linux
/dev/hda9 3831 4799 7783461 83 Linux
/dev/hda10 4800 4864 522081 82 Linux swap
从这上面,我们可以看来,/dev/hda6和/dev/hda7就是win下的fat32分区。
第二;我们加载windows的分区,是不是在linux下有个文件夹可以放下去?这样理解就对了。我们可以用下面的方法来操作。我在这个例子中,把/hda6的内容,我想放到WinE这个文件夹。另一个则是WinF,这个文件夹的命名,可以用你喜欢的。但修改/etc/fstab的内容时,也要用这个文件夹,也就是统一起来。。
#mkdir /mnt/WinE
#mkdir /mnt/WinF
注意大小写。。
或用鼠标点kde自带的浏览器在地址栏上输入:
/mnt
就能进入/mnt这个目录了。。
然后就按鼠标的右键来建目录,这个简单吧。。。哈。。
然后,我们来修改/etc目录下的fstab
/dev/hda6 /mnt/WinE vfat rw,codepage=936,iocharset=cp936 0 0
如果加E盘就是:
/dev/hda7 /mnt/WinF vfat rw,codepage=936,iocharset=cp936 0 0
然后在/mnt/下建立目录WinD和WinE
对于Redhat 8.0,应该把codepage=936去掉
然后在KDE桌面上用右键点击[新建]-》硬 盘-》然后就点几下鼠标就OK了。。。
如果手工mount分区如何做呢?
事前要建好目录,比如在/mnt目录下建一个tmp目录
#mkdir /mnt/tmp
然后就是mount了,mount也应该有个目的地吧,那我们就把目的地定为/mnt/tmp
比如我们mount /dev/hda1
如下:
#mount -o iocharset=cp936 /dev/hda1 /mnt/tmp
北南老大,我只在/etc/fstab中添加,另一个文件etc/mtab好像已经自动添加了.
是不是RH73有这个功能的?
哈哈。。兄弟,这个mtab是系统关机时umount时要用到的。。。
在mnt目录下建立你想要的分区名称如WinD,然后用下面的指令格式加载.
当然你可以在etc中修改fstab文件.这样可以自动加载
/dev/hda9 /mnt/F vfat default,codepage=936,iocharset=gb2312 0 0
******************************************************
我的fstab文件格式,参考一下
/dev/hda1 /mnt/C vfat default,codepage=936,iocharset=gb2312 0 0
/dev/hda7 /mnt/D vfat default,codepage=936,iocharset=gb2312 0 0
/dev/hda8 /mnt/E vfat default,codepage=936,iocharset=gb2312 0 0
/dev/hda9 /mnt/F vfat default,codepage=936,iocharset=gb2312 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu,codepage=936,iocharset=gb2312 0 0
这样可以显示中文的.你试一下
[root@localhost root]# fdisk -l
Disk /dev/hdc: 255 heads, 63 sectors, 4865 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdc1 * 1 1217 9775521 c Win95 FAT32 (LBA)
/dev/hdc2 1218 4865 29302560 f Win95 Ext'd (LBA)
/dev/hdc5 1218 3046 14691411 b Win95 FAT32
/dev/hdc6 3047 3569 4200966 b Win95 FAT32
/dev/hdc7 3570 4092 4200966 b Win95 FAT32
/dev/hdc8 4093 4829 5919921 83 Linux
/dev/hdc9 4830 4865 289138+ 82 Linux swap
[root@localhost root]#
就是这个样子的 你帮我看看吧
mount -t vfat /dev/hdc5 /mnt/winD
Section==============Web Resources==============================
CN-------------www.linuxeden.com
CN-------------www.linuxforum.net
CN-------------www.linuxfans.org
CN-------------www.linuxsir.org/bbs
CN-------------http://bbs.chinaunix.net/viewthread.php?tid=746147
CN-------------http://fedora.linuxsir.org/main/?q=aggregator/sources/1
CN-------------http://linux.chinaunix.net/
CN-------------http://slack.linuxsir.org/main/?q=node/145
CN-------------http://www.math.zju.edu.cn/ligangliu/LaTeXForum/tex_edit.htm
CN-------------ftp://ftp.ctex.org/pub/tex/systems/ctex/ --download CTeX package
EN-------------ctan.tug.org/starter.html ---the comprehensive ReX Archive Network
EN-------------www.winedt.com ---winedit download
EN-------------www.tug.org/begin.html
EN-------------www.gnu.org/software/emacs/manual/---GNU Emacs Manual
EN---------http://rpmfind.net/linux/RPM 去这里找一下这几个包吧!
EN------http://grub4dos.sourceforge.net/ http://sourceforge.net/projects/grub4dos
EN-------------http://www.slackworld.net/01/tips.html
EN-------------http://gurus.com.au/JobSeeker/Default.aspx ----IT career
EN-----java--------http://forum.java.sun.com/thread.jspa?threadID=568603&messageID=2810271
EN-----java--------http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html
CN-----.Net--------http://www.chinaaspx.com/archive/Java/20906.htm China .net club/ is used for search a certain word, C-s is used for searching as well when reading info help ? to get command list for reading info
SHOW LINUX KERNEL VERSION
SHOW WHETHER LINUX KERNEL SOURCE CODE ARE INSTALLED
cscope
SHOW PERL VERSION
[q.yang@localhost lpc3250]$ perl -vSHOW LINUX KERNEL VERSION
[q.yang@localhost lpc3250]$ uname -r
SHOW WHETHER LINUX KERNEL SOURCE CODE ARE INSTALLED
[q.yang@localhost sierra_drv_1.7.32]$ rpm -qa|grep kernel
kerneloops-0.12-1.fc9.i386
kernel-devel-2.6.27.25-78.2.56.fc9.i686
kernel-2.6.25-14.fc9.i686
kernel-headers-2.6.27.25-78.2.56.fc9.i386
kernel-2.6.27.25-78.2.56.fc9.i686
kernel-firmware-2.6.27.25-78.2.56.fc9.noarch
[q.yang@localhost sierra_drv_1.7.32]$ rpm -qa|grep kernel |grep devel
kernel-devel-2.6.27.25-78.2.56.fc9.i686
[q.yang@localhost sierra_drv_1.7.32]$ rpm -qa|grep kernel |grep headers
kernel-headers-2.6.27.25-78.2.56.fc9.i386
[root@localhost sierra_drv_1.7.32]# yum install kernel-devel-2.6.25-14.fc9.i686
Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package kernel-devel.i686 0:2.6.25-14.fc9 set to be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================
Package Arch Version Repository Size
====================================================================================================================
Installing:
kernel-devel i686 2.6.25-14.fc9 fedora 5.1 M
Transaction Summary
====================================================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 5.1 M
Is this ok [y/N]: y
Downloading Packages:
kernel-devel-2.6.25-14.fc9.i686.rpm | 5.1 MB 00:21
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : kernel-devel 1/1
Installed:
kernel-devel.i686 0:2.6.25-14.fc9
Complete!
/*********************************/
/* Vi Relevant */
/* Created: 2007-Aug-16 THU */
/* Update: 2007-Aug-20 MON */
/* */
/* v0.0.0.1 added Yum relevant commands 2008-SEP-26 FRI */
/* v0.0.0.2 added vnc relevant commands 2008-SEP-27 SAT */
/* v0.0.0.3 added svn relevant commands 2008-OCT-01 WED */
/**********************************************************************/
DISPLAY DISK USAGE
------------------------------------------------------------------
[q.yang@localhost ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6063688 5204096 551576 91% /
/dev/sda6 194442 18921 165482 11% /boot
tmpfs 224740 96 224644 1% /dev/shm
gvfs-fuse-daemon 6063688 5204096 551576 91% /home/q.yang/.gvfs
[q.yang@localhost ~]$ su
Password:
[root@localhost q.yang]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6063688 5204100 551572 91% /
/dev/sda6 194442 18921 165482 11% /boot
tmpfs 224740 96 224644 1% /dev/shm
[root@localhost q.yang]#
WHICH LINUX KERNEL TO BOOT
------------------------------------------------------------
[root@localhost kernel]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,5)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=2
timeout=5
splashimage=(hd0,5)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.27.25-78.2.56.fc9.i686)
root (hd0,5)
kernel /vmlinuz-2.6.27.25-78.2.56.fc9.i686 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.27.25-78.2.56.fc9.i686.img
title Linux (2.6.25-14.fc9.i686)
root (hd0,5)
kernel /vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=916c799e-4ae5-4820-8de6-0bbc5b7b8968 rhgb quiet
initrd /initrd-2.6.25-14.fc9.i686.img
title Win2000
rootnoverify (hd0,0)
chainloader +1
[root@localhost kernel]# ll /boot/
total 12767
-rw-r--r-- 1 root root 86348 2008-05-01 20:34 config-2.6.25-14.fc9.i686
-rw-r--r-- 1 root root 90947 2009-06-19 02:57 config-2.6.27.25-78.2.56.fc9.i686
drwxr-xr-x 3 root root 1024 2010-06-04 02:19 efi
drwxr-xr-x 2 root root 1024 2010-06-07 14:42 grub
-rw------- 1 root root 3294836 2010-06-04 02:21 initrd-2.6.25-14.fc9.i686.img
-rw------- 1 root root 3326324 2010-06-07 14:42 initrd-2.6.27.25-78.2.56.fc9.i686.img
drwx------ 2 root root 12288 2010-06-04 02:11 lost+found
-rw-r--r-- 1 root root 892575 2008-05-01 20:34 System.map-2.6.25-14.fc9.i686
-rw-r--r-- 1 root root 976362 2009-06-19 02:57 System.map-2.6.27.25-78.2.56.fc9.i686
-rwxr-xr-x 1 root root 2088288 2008-05-01 20:34 vmlinuz-2.6.25-14.fc9.i686
-rwxr-xr-x 1 root root 2227280 2009-06-19 02:57 vmlinuz-2.6.27.25-78.2.56.fc9.i686
FIND COMMAND USAGE
-----------------------------
Only find current directory without search sub-dir using '-maxdepth 1'
[q.yang@localhost ProjProgrammingTest]$ find ./include/ -maxdepth 1 -name '*' |grep .h
./include/Misc.h
./include/CommsLinkSessionManager.h
./include/Gpio.h
./include/GsnDataTypes.h
./include/DeviceTcpTx.h
./include/CommsMain.h
./include/Stack61850.h
./include/StackSpac.h
./include/StackDnp3.h
./include/StackGserver.h
[qyang@pc6de4 ~/ns-allinone-2.28]$ find . -name "n?.*" -print under tcsh&bash
./tk8.4.5/library/msgs/nl.msg
./lib/tk8.4/msgs/nl.msg
./ns-2.28/ns-tutorial/ns.html
./ns-2.28/diffusion3/lib/nr/nr.cc
./ns-2.28/diffusion3/lib/nr/nr.o
./ns-2.28/diffusion3/lib/nr/nr.hh
./ns-2.28/doc/ns.bib
./ns-2.28/ns.1
find . -wholename './.metadata' -prune -o -print //exclude certain directory
find . ! -name '*.class' //exclude certain file pattern
[q.yang@localhost ProjProgrammingTest]$ find ./include/ -maxdepth 1 -name '*.h' -exec wc {} \;
line words characters
42 87 968 ./include/Misc.h
131 414 4487 ./include/CommsLinkSessionManager.h
DELETE ALL FOLDERS WITH CERTAIN NAME PATTERN
---------------------------------------------------
[q.yang@localhost ltib-qs]$ find . -noleaf -name '.svn' -exec rm -r -f {} \;
FIND STRING IN ALL CERTAIN FILES
------------------------------------------------------------
First one can show line number
[q.yang@localhost ltib-qs]$ fd "*.*con*" -print0 | xargs -0 grep MODLIST -rn
./config/profile/swang.config:301:CONFIG_SYSCFG_MODLIST=""
./config/profile/swang-poc.config:307:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/ChkGsnMake_Config.config:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/GsnMake.config:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/GsnMake.config.old:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/.config:455:CONFIG_SYSCFG_MODLIST=""
./config/platform/phy3250/RoofsToNAND_Flash.config:455:CONFIG_SYSCFG_MODLIST=""
This cannot show line number but just the string result after search
[q.yang@localhost Documentation]$ grep endpoint . -r *.txt
./MSI-HOWTO.txt:PCI Express endpoints uses INTx emulation (in-band messages) instead
./input/yealink.txt:A: The sysfs files are located on the particular usb endpoint. On most
./sound/alsa/Audiophile-Usb.txt:parse_audio_endpoints function uses a quirk called
./sound/alsa/soc/dapm.txt:An endpoint is a start or end point (widget) of an audio signal within the
./sound/alsa/soc/dapm.txt:snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);
FIND YUM PACKAGE BY KEY WORDS
---------------------------
[root@localhost q.yang]# yum search ppp
CHANGE ALL FOLDERS/FILES OWNERSHIP (user,group)
--------------------------------------------------
[q.yang@localhost ltib-qs]$ chown -c -R q.yang:q.yang .
LIST FILE SORTED BY TIME
------------------------------------------
[q.yang@localhost lpc3250]$ ls -lt ltib-qs/config/platform/phy3250/
//-------------------------------
//php+apache+msql installation
//
[root@QuentinFedoraHome q.yang]# rpm -qa | grep mysql
mysql-connector-java-3.1.12-5.fc9.i386
mysql-libs-5.0.51a-1.fc9.i386
[root@QuentinFedoraHome q.yang]# rpm -qa | grep httpd
httpd-tools-2.2.8-3.i386
httpd-2.2.8-3.i386
[root@QuentinFedoraHome q.yang]# rpm -qa | grep php
[root@QuentinFedoraHome q.yang]#
//------------------------------
//Svn relevant commands
//
Now, you use svn merge to replicate your branch changes back into the trunk.
$ pwd
/home/user/calc-trunk
$ svn update # (make sure the working copy is up to date)
At revision 390.
$ svn merge --reintegrate http://svn.example.com/repos/calc/branches/my-calc-branch
--- Merging differences between repository URLs into '.':
U button.c
U integer.c
U Makefile
U .
$ # build, test, verify, ...
$ svn commit -m "Merge my-calc-branch back into trunk!"
Sending .
Sending button.c
Sending integer.c
Sending Makefile
Transmitting file data ..
Committed revision 391.
[q.yang@QuentinFedoraHome ~]$ ssh-keygen -b 1024 -t dsa -N passphrase -f
keyfileGenerating public/private dsa key pair.
Your identification has been saved in keyfile.
Your public key has been saved in keyfile.pub.
The key fingerprint is:
50:81:da:e8:e9:b1:11:ec:f6:89:ac:3c:cf:a8:bd:05 q.yang@QuentinFedoraHome
[q.yang@QuentinFedoraHome ~]$ ls -l keyfile*
-rw------- 1 q.yang q.yang 744 2008-10-01 17:20 keyfile
-rw-r--r-- 1 q.yang q.yang 614 2008-10-01 17:20 keyfile.pub
http://tortoisesvn.net/ssh_howto
[q.yang@QuentinFedoraHome ~]$ svn list file:///var/svn/repos_personal/Doc_Documents
[q.yang@QuentinFedoraHome ~]$ svn import ~/Doc_Documents file:///var/svn/repos_personal/Doc_Documents -m "Initial import"
[q.yang@QuentinFedoraHome Svn_Repositories]$ svn checkout svn://10.1.1.7/var/svn/repos_personal/
$ svnadmin create /var/svn/newrepos
//-------------------------------------------
//Samba
//
[root@QuentinFedoraHome q.yang]# service smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
[root@QuentinFedoraHome q.yang]# chkconfig smb on
[root@QuentinFedoraHome q.yang]# system-config-users
[root@QuentinFedoraHome q.yang]# yum install system-config-samba
system-config-services gui services management
//-------------------------------------------
// VNC server in linux
//
#chkconfig vncserver on
#service vncserver restart
VNCSERVERS="1:q.yang 2:m.xie"
VNCSERVERARGS[1]="-geometry 1024x768 "
VNCSERVERARGS[2]="-geometry 800x600 "
[root@QuentinFedoraHome q.yang]# vi /etc/sysconfig/vncservers
[q.yang@QuentinFedoraHome Code_Shells]$ vncserver -kill:2
[tchung@tchung101 tchung]$ sudo /sbin/service iptables restart restart firewall
[root@QuentinFedoraHome Code_Shells]# vi /etc/sysconfig/iptables change firewall
#rpm -q vnc vnc-server
//-------------------------------------------
//user management chgrp,chown,useradd,passwd,chmod
//
[root@QuentinFedoraHome q.yang]# groupadd admin
[root@QuentinFedoraHome q.yang]# groupadd master
[root@QuentinFedoraHome q.yang]# groupadd family
[root@QuentinFedoraHome q.yang]# groupadd users
groupadd: group users exists
[root@QuentinFedoraHome q.yang]# vi /etc/default/useradd
[root@QuentinFedoraHome q.yang]# vi /etc/group
CHANGE USER'S GROUP
------------------------
[root@QuentinFedoraHome q.yang]# usermod -g admin -G users,family,master q.yang
[root@QuentinFedoraHome svn]# chmod 711 -R repos_personal/
[root@QuentinFedoraHome svn]# ll repos_personal/db/
total 28
-rwx--x--x 1 root root 6 2008-10-03 09:20 current
-rwx--x--x 1 q.yang root 2 2008-09-28 23:22 format
-rwx--x--x 1 q.yang root 5 2008-09-28 23:22 fs-type
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revprops
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revs
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 transactions
-rwx--x--x 1 q.yang root 37 2008-09-28 23:22 uuid
-rwx--x--x 1 q.yang root 0 2008-09-28 23:22 write-lock
[root@QuentinFedoraHome svn]# man chown
[root@QuentinFedoraHome svn]# man chown
[root@QuentinFedoraHome svn]# chown -R q.yang repos_personal/
[root@QuentinFedoraHome svn]# ll repos_personal/db/
total 28
-rwx--x--x 1 q.yang root 6 2008-10-03 09:20 current
-rwx--x--x 1 q.yang root 2 2008-09-28 23:22 format
-rwx--x--x 1 q.yang root 5 2008-09-28 23:22 fs-type
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revprops
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 revs
drwx--x--x 2 q.yang root 4096 2008-10-03 09:20 transactions
-rwx--x--x 1 q.yang root 37 2008-09-28 23:22 uuid
-rwx--x--x 1 q.yang root 0 2008-09-28 23:22 write-lock
[root@QuentinFedoraHome svn]# ll
total 8
drwx--x--x 7 q.yang root 4096 2008-09-28 23:22 repos_personal
drwxrwxr-x 7 q.yang root 4096 2008-09-28 22:48 repos_projects
[root@QuentinFedoraHome svn]# chgrp -R 100 repos_projects/
[root@QuentinFedoraHome svn]# ll
total 8
drwx--x--x 7 q.yang root 4096 2008-09-28 23:22 repos_personal
drwxrwxr-x 7 q.yang users 4096 2008-09-28 22:48 repos_projects
[root@bigdog /root]# useradd blarg add account
[root@bigdog /root]# passwd blarg set pwd or change pwd(when user logged in)
yum list updates
yum update update system
yum list selinux-policy*
[root@blackrock .vnc]# yum list selinux-policy*
Loaded plugins: refresh-packagekit
Installed Packages
selinux-policy.noarch 3.3.1-55.fc9 installed
selinux-policy-devel.noarch 3.3.1-55.fc9 installed
selinux-policy-targeted.noarch 3.3.1-51.fc9 installed
Available Packages
selinux-policy-mls.noarch 3.3.1-51.fc9 updates
[root@blackrock /]# more ~topping/.vnc/blackrock.orb.org:1.log
:file ;display current file name
:set wrap ;wrap text
:set nowrap ;don't wrap text when display
:set winwidth ;set where to wrap text when editing file
cp [-drsu] u is used for update of file used for backup
/etc/rc.d/init.d ./smb start ./smb stop ./smb restart
$cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd ; then delete all other password lines
smbpasswd -a QuentinYANG ; add samba password for user QuentinYANG
testparm ;test samba service from smb.conf
smbclient -L localhost ;list samba service on localhost or other ip address
ifconfig eth0 10.0.0.23
df -h list disk occupacy infor
du -s
rpm -q -a > /home/packages.log
rpm -ivf --nodeps --force
grep hp /home/packages.log
grep instance . -R -recursive searching subdirectories
grep -i -r --include=*.txt Q: ~/Doc_PdfTxtHtm/ -i means ignor the case, --include, --exclude=PATTERN means can search only some files with such a PATTER
grep timer . -r *.java (is a simple way to serch some text pattern like "timer" in all *.java files of all subdirectories)
egrep -i 'Average | x ' ~/driver_heartbeat_debug_01.log '|' means, match either pattern, here we have to use egrep for extend searching
egrep "id\(\<$NodeId\>|\<$NodeId2\>|\<$NodeId3\>" temp.log > temp1.log
rpm -e scim scim-tables scim-chewing
rpm -q scim -i
nmap -v 130.130.10.126
/sbin/ifconfig list ip address
route
ps -aux | grep pdf list all process
kill 19862 kill process with pid
ls -D all
ll -cX ./Doc_PdfTxtHtm/ -c means sort by file name, time,-X by file extention
ll -t ./Doc_PdfTxtHtm/ -t sort by file change time
# learn wht is the different of single quotation mark and double quotation mark
# and how to search two types of files with different extention name at the
# same time
echo "fd "*.*" |egrep '*.jpy|*.bsh'" >> ~/Doc_PdfTxtHtm/linux_commandlist.txt
fd *.* |egrep '*.jpy|*.bsh'
echo "fd '"*.*"' |egrep '*.jpy|*.bsh'" >> ~/Doc_PdfTxtHtm/linux_commandlist.txt
fd '*.*' |egrep '*.jpy|*.bsh'
echo "fd \"*.*\" |egrep '*.jpy|*.bsh'" >> ~/Doc_PdfTxtHtm/linux_commandlist.txt
fd "*.*" |egrep '*.jpy|*.bsh'
ln -s ~/Doc_PdfTxtHtm/link_list.txt .
mv -v * ~/MyMac/
fd *.jar -exec jar tvf {} \; |grep InputStreamReader
fd "*.java" -mtime -5
touch eclipseMyMac.tar
fd "*.java" -mtime -5 -exec tar -uvf eclipseMyMac.tar {} \;
grep "found neighbour:" . -r -n *.java // search string pattern in *.java files under all subdirectories and printout line number in that file as well
fd "*.java" -print0 | xargs -0 grep log -rn //search string pattern in files generated from file search result
find . -wholename './.metadata' -prune -o -print //exclude certain directory
find . ! -name '*.class' //exclude certain file pattern
fd "*.java" -mtime -8 -exec ls -all -ct {} \; // search files changed over last 8 days and list their time stamp and sorted by changed time
date +%g%m%d%H //06100123 yymmddhh date shell
#uname -r or #rpm -q kernel //list the kernel version
. logAnalysis.sh 16 ringInfo16135050_appcw1000.log | cut -d" " -f1 //cut -d define what symbole is used to seperate input string. -f define what field to print, 1st or 2nd after cutting.
. logAnalysis.sh 16 ringInfo16135050_appcw1000.log | cut -d" " -f1 | uniq -c | sort -rn
// uniq -c will count number of repeat times of same patten lines. sort -rn
// sort all lines according to the number of repeat times.
cscope
find /home/quentin/eclipse_workspace/MyMac/src/ -name "*.java" > ~/eclipse_workspace/MyMac/src/cscope.filescscope -b
cscope -R
ctags -n -f cppcomplete.tags --fields=+ai --C++-types=+p * -L cscope.files
cvs -d /usr/local/newrepos init //create repository in path /usr/local/newrepos
cvs import -d -m "initial import into CVS from eclipse MyMac on Mimir" MyMacProj quentin start //-d option to keep modified time CVS_ROOT already set up, so import to CVS root directory, import files to repository, execute this command on top level of ur project folder which u want to add to repository
cvs checkout MyMacProj //check out one work copy in the folder u want to edit
cvs status ./src/jist/swans/app/AppRingschedule.java
cvs log ./src/jist/swans/app/AppRingschedule.java
cvs ci -m"back to the stage passing growth of tree"
cvs update
cvs -q tag Release-2006_09_30 // add tag to all files at their current version
cvs -q tag Release-2006_10_06-AdditiveRadioSNR
cvs tag Backup-2006_10_11-HalfwayStartScheduling ./src/jist/swans/mac/MacCsmaCa.java
cvs co -r Release-2006_09_30 MyMacProj //check out a work copy based on one tag "Release-2006_09_30"
cvs update -r Release-2006_09_30 // get a snapshot of one version with tag, without checkout all the files
cvs update -d // run update with the -d flag, telling it to bring down any new directories from the repository.
cvs update -P // prune useless directiories
cvs status ./src/driver/ringschedule.java //check on file status, u can see the Sticky Tag: Release-2006_09_30 (revision: 1.1.1.1)
cvs -q update -A ./src/driver/ringschedule.java // release the sticky state of one file so that get the latest version of this file
cvs -d:pserver:anon@jist.ece.cornell.edu:/cvs-jist login
cvs -d:ext:quentin@mimir.snrc.uow.edu.au:/home/quentin/CvsMyMac login
cvs -Q update -p -r 1.3 hello.c > hello.c //reverse to previous version
yarkon$ cvs add newfile.c //add files
yarkon$ cvs ci -m "added newfile.c" newfile.c
yarkon$ mkdir c-subdir
yarkon$ cvs add c-subdir
yarkon$ rm newfile.c //remove files
yarkon$ cvs remove newfile.c
yarkon$ cvs ci -m "removed newfile.c" newfile.c
yarkon$ rm file1 file2 file3 //remove directories
yarkon$ cvs remove file1 file2 file3
yarkon$ cvs ci -m "removed all files" file1 file2 file3
yarkon$ cd ..
yarkon$ cvs update -P
yarkon$ mv oldname newname //rename files
yarkon$ cvs remove oldname
yarkon$ cvs add newname
yarkon$ cvs ci -m "renamed oldname to newname" oldname newname
yarkon$ mkdir newdir //rename directories
yarkon$ cvs add newdir
yarkon$ mv olddir/* newdir
yarkon$ cd olddir
yarkon$ cvs rm foo.c bar.txt
yarkon$ cd ../newdir
yarkon$ cvs add foo.c bar.txt
yarkon$ cd ..
yarkon$ cvs commit -m "moved foo.c and bar.txt from olddir to newdir"
yarkon$ cvs update -P
ls . -R -D | grep /CVS | cut -d ":" -f1
////////////////////////////////////////////////////////////////////////
// Quentin study notes for unix
// focus on the command list in unix
// time History Author
// 6/9/2004 Created Quentin.YANG
// 17/8/2005 update in UOW Quentin.YANG
add vi guide;
// 18/8/2005 add web resource section Quentin.YANG
looking for LaTax-article
editing tool
// 25/8/2005 add linux config guide(CN)
// add Bash section
// add emacs section
// 20/6/2006 how to create own shell
//
//
// 29/6/2006 command combination list
///////////////////////////////////////////////////////////////////////
[root @test /root ]# cp [-drsu] [来源档] [目的档]
参数说明:
-d :在进行 copy 的时候,如果是 copy 到 link 档案,若不加任何参数,则预设情
况中会将 link 到的源文件copy 到目的地,若加 -d 时,则 link 档案可原封不动的将 link 这个
快捷方式其拷贝到目的地!
-r :可以进行目录的 copy 呦!
-s :做成连结档,而不 copy 之意!与 ln 指令相同功能!
-u, --update:如果来源档比较新,或者是没有目的档,那么才会进行 copy 的动作!可用于备
份的动作中
q: Rename directory? --wht unix command? A: just use mv
Q: wht is the difference between gzip and zip/unzip? //gzip -v -d abcd.gz
Alias? alias is set up in ~/.bashr
Q: How to recover files in Linux? How do use trash in linux?
如何查看硬件的芯片??
[root@linuxsir01 root]# lspci -v
要说明系统、版本以及内核的版本,用下面的命令来测试,
#uname –a
linux version:
/etc/redhat-release
新手有时对vi vim emacs 不太熟悉,这需要更适合新手用的文本编辑器。比如GNOME中的 gedit ,KDE中的kwrite或者kate等。
如果您用KDE或者GNOME,发行版中都有 gedit 或者kwrite,也应该有xedit 。
如果您是初学Linux,只是想找一些象Windows写字板那样简单功能的编辑器,leafpad 和mousepad足够用。如果在linux text模式下操作,不会用vi或者vim的情况下,用nano修改文件也是足够了。
本帖专为新手准备,希望能对初学Linux的弟兄有所帮助。
rpm -qa | grep vnc
把上面那些rpm都DOWN下来到一个文件夹。。。然后在控制台下输入:
#cd [你DOWN下RPM的文件夹]
#rpm -ivh *.rpm
rpm install, pacage management, refer to man rpm
这样全都OK了。。。。
兄弟,请看!
ftp://ftp.gtk.org/pub/gtk/v2.0/binary/old/RedHat-7.2/RPMS/i386/
rpm安装最简单。。。。。试一下吧。。有问题再发帖。。。
不要急,这就是学习。。。
--------------------------------------------------------------------------------
qepafrps02-06-21, 21:35
是呀,这里都是.rpm,不过很多呀,是不是还是把gtk,atk,glib,pango,这几个下了,一个一个的安呀,难道没有一个总的.rpm的那种吗?
========================= command combination list ===========================
$ls -all | less
$ls -all | grep .jar
$ls -all -R | grep .jar
$su temporary change user, default change to root so that having right to install software
=========== how to create own shell to backup personal files================
# fgrep bball etc/passwd
bball : x : 100 : 100 : William H. Ball , , , , : /home/bball : /bin/bash
==========Bash============================
bash的内建叁数很多,你可以自行"man bash"查一查。这里我只说明一些常用
及重要的。
PPID : 该bash的呼叫者process ID.
PWD : 目前的工作目录。
OLDPWD : 上一个工作目录。
HOSTTYPE : 机器种类。
OSTYPE : 作业系统名称。
PATH : 命令搜寻路径。
PATH="/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:."
发帖时间: 02-12-15, 02:58
查看系统环境变量的方法是用set,这是在bash下的。
[root@linuxsir01 root]# set
大熊宝宝说的也是一个方法,这个方法写入后,就不会使变量设置重新启动后丢失。
也可以这样做。。
改用户目录下的.bashrc
加入
PATH="$PATH:/tmp"
_____________________________________
请弟兄们发帖时要写个好标题,多谢!
签名不支持html和bbcode,请弟兄为了版面的整洁,请更改签名档,谢谢!
请各版版主及初学Linux的弟兄,请在您的签名写上机器的配置,以及您所用的系统(包装版本号,内核),谢谢。
Slackintosh 10.1+kernel-2.6.11.8+xfce-4.2.1.1
=====================================
帮助那些需要帮助的人── 吾师语录
世上没有踏不平的山,只有走不完的路!── 师兄语录
HOME : 目前使用者的home directory
Section=========emacs,==============================
C means Ctl key, M means Alt key;
control cursor C-p,C-n,C-b,C-f;M-f;(move by words) C-l center the text to your cursor;
C-a,C-e; move the start and end of one line;
C-h w command - to check which key bind to the command
;; C-h k key - to check which command the key bind to
;; C-j - run the lisp command(put the cursor at end)
;;
;; C-c C-t - change mode to hungry-state and auto-state
;; C-c C-a - change mode to auto-state
;; C-c C-d - change mode to hungry-state
;; C-c C-e - expand macro
;; C-c C-\ - add '\' at then end of the line
;; C-u C-s - regular expression search
;; C-x 5 2 - open new frame
;; C-x 5 0 - close new frame
;;
;; M-; - insert a comment
;; M-\ - fixup whitespace
;; M-/ - auto complete the word
;; M-l - downcase-word
;;
;; Mark the region, then
;;
;; C-x r k - kill rectangle
;; C-x r t
C-x C-f :打开/新建文件
C-x S :保存所有缓冲区文件
C-x C-v:在当前缓冲区打开文件
C-x k :关闭当前缓冲区
C-x i : 在当前光标位置插入文件
M-x replace-string: 一次性替换字符串
M-x % : 循环替换。
C-s
C-r :查询
C-@ :设置标记,然后选取
C-w :相当于剪切。
M-w :相当于复制
C-y :粘贴
M-y : 循环粘贴。
C-o:开新行
C-f, C-b, C-p, C-n, M-f, M-b, C-v , M-v , C-l, M-< 移动。M->,
C - !, 一次性执行shell, M-x shell, 启动shell外壳。
M-x compile:编译程序。
Under cygwin, C-x,C-c does not work to exit emacs; have to press F10, then f,e to exit emacs; Also, C-h,C-t does not enter tutorial, Try to use F1 and then option ? then "t", emacs tutorial;
Section ======unix=========================================================
after ns2 install
----------------------------------------------------------------------------------
Please put /home/qyang/ns-allinone-2.28/bin:/home/qyang/ns-allinone-2.28/tcl8.4.5/unix:/home/qyang/ns-allinone-2.28/tk8.4.5/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put /home/qyang/ns-allinone-2.28/otcl-1.9, /home/qyang/ns-allinone-2.28/lib,
into your LD_LIBRARY_PATH environment variable.
If it complains about X libraries, add path to your X libraries
into LD_LIBRARY_PATH.
If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH
If you are using sh, you can set it like:
export LD_LIBRARY_PATH=
(2) You MUST put /home/qyang/ns-allinone-2.28/tcl8.4.5/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.
(3) [OPTIONAL] To save disk space, you can now delete directories tcl8.4.5
and tk8.4.5. They are now installed under /home/qyang/ns-allinone-2.28/{bin,include,lib}
After these steps, you can now run the ns validation suite with
cd ns-2.28; ./validate
For trouble shooting, please first read ns problems page
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.
gunzip,unzip,tar;if forget the option can use "$tar --help"
Ctr+C;terminate process;
edit ~/.bashrc,set your ENV;
try to find the path of some command by "where" only availabe under Tcsh
[qyang@pc6de4 ~]$ where is tcsh
---/bin/tcsh
[qyang@pc6de4 ~]$ pwd
/home/qyang
[qyang@pc6de4 ~]$ ls /
bin dev home lib misc opt root selinux tmp var
boot etc initrd lost+found mnt proc sbin sys usr
[qyang@pc6de4 ~]$ ls /bin
arch cpio env kill netstat sed traceroute
ash csh ex link nice setfont traceroute6
ash.static cut false ln nisdomainname setserial true
aumix-minimal date fgrep loadkeys pgawk sh umount
awk dd gawk login ping sleep uname
basename df gettext ls ping6 sort unicode_start
bash dmesg grep mail ps stty unicode_stop
bash2 dnsdomainname gtar mkdir pwd su unlink
bsh doexec gunzip mknod red sync usleep
cat domainname gzip mktemp rm tar vi
chgrp dumpkeys hostname more rmdir tcsh view
chmod echo igawk mount rpm touch ypdomainname
chown ed ipcalc mt rvi tracepath zcat
cp egrep kbd_mode mv rview tracepath6
[qyang@pc6de4 ~]$ emacs
[qyang@pc6de4 ~]$ wher is emacs
wher: Command not found.
[qyang@pc6de4 ~]$ where is emacs
---/usr/bin/emacs
Section--from /for_unix_beginner/-----
--% echo $OSTYPE
USER (your login name)
HOME (the path name of your home directory)
HOST (the name of the computer you are using)
ARCH (the architecture of the computers processor)
DISPLAY (the name of the computer screen to display X windows)
PRINTER (the default printer to send print jobs)
PATH (the directories the shell should search to find a command)
setenv; printenv or env; unsetenv; ENVIRONMENT variables are set using the command, displayed using the commands, and unset using the command
--% printenv | less show all values of these variables, type |less can not work in Cygwin
--% set | less To show all values of these variables, type |less can not work in Cygwin
--The C and TC shells uses two files called .login and .cshrc (note that both file names begin with a dot).Information in these files is used to set up your working environment.
% set history = 200
% echo $history
To PERMANENTLY set the value of history, you will need to add the set command to the .cshrc file
% nedit ~/.cshrc
% source .cshrc Save the file and force the shell to reread its .cshrc file buy using the shell source command
% "set path = ($path ~/units174/bin)" add it to the end of your existing path (the $path represents this) by issuing the command can't work under unix bash; can work after chang it to "export PATH=($PATH ~/units174/bin)"
% cd; pwd HINT: You can run multiple commands on one line by separating them with a semicolon.
Section----shortcut key--------
right click to paste;
Section=================----vi------------------
一、Unix编辑器概述
编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件。Unix及其相似的ix操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编辑器,包括 ex, edit,ed 和vi.其中ex,edit,ed都是行编辑器,现在已很少有人使用,Unix提供他们的原因是考虑到满足各种用户特别是某些终端用户的需要。
值得庆幸的是,Unix提供了全屏幕的Vi编辑器,这使我们的工作轻松不少。不少DOS用户抱怨Vi编辑器不象DOS下的编辑器如edit那么好用,这是因为Vi考虑到各种用户的需要,没有使用某些通用的编辑键(在各个不同的终端机上他们的定义是不同的,在某些终端机上甚至没有这些键)。而是采用状态切换的方法,但这只是习惯的问题,一旦你熟练的使用上了vi你就会觉得它其实也很好用。虽然 Vi采用了状态切换的方法,但电脑的硬件及操作系统多种多样,某些电脑的键盘上没有特定的几个功能键!那麽不就有某些功能不能用了?这个问题在 Unix 系统上也一样,几乎各大电脑厂商都有自己的Unix 系统,而 vi 的操作方法也会随之有点出入。这里我们采用 PC 的键盘来说明 vi 的操作,但在具体的环境中还要参考相应的资料,这一点是值得注意的。
二、Vi入门
(一)、进入vi
在系统提示字符(如$、#)下敲入vi <档案名称>,vi 可以自动帮你载入所要编辑的文件或是开启一个新文件(如果该文件不存在或缺少文件名)。进入 vi 后萤幕左方会出现波浪符号,凡是列首有该符号就代表此列目前是空的。
(二)、两种模式
如上所述,vi存在两种模式:指令模式和输入模式。在指令模式下输入的按键将做为指令来处理:如输入a,vi即认为是在当前位置插入字符。而在输入模式下,vi则把输入的按键当作插入的字符来处理。指令模式切换到输入模式只需键入相应的输入命令即可(如a,A),而要从输入模式切换到指令模式,则需在输入模式下键入ESC键,如果不晓得现在是处於什麽模式,可以多按几次 [ESC],系统如发出哔哔声就表示已处于指令模式下了。
付:有指令模式进入输入模式的指令:
新增 (append)
a :从光标所在位置後面开始新增资料,光标後的资料随新增资料向後移动。
A: 从光标所在列最後面的地方开始新增资料。
插入 (insert)
i: 从光标所在位置前面开始插入资料,光标後的资料随新增资料向後移动。
I :从光标所在列的第一个非空白字元前面开始插入资料。
开始 (open)
o :在光标所在列下新增一列并进入输入模式。
O: 在光标所在列上方新增一列并进入输入模式。
(三)、退出vi
在指令模式下键入:q,:q!,:wq或:x(注意:号),就会退出vi。其中:wq和:x是存盘退出,而:q是直接退出,如果文件已有新的变化,vi会提示你保存文件而:q命令也会失效,这时你可以用:w命令保存文件后再用:q退出,或用:wq或:x命令退出,如果你不想保存改变后的文件,你就需要用:q!命令,这个命令将不保存文件而直接退出vi。
(四)、基本编辑
配合一般键盘上的功能键,像是方向键、[Insert] 、[Delete] 等等,现在你应该已经可以利用 vi 来编辑文件了。当然 vi 还提供其他许许多多功能让文字的处理更为方便。
何谓编辑?一般认为是文字的新增、修改以及删除,甚至包括文字区块的搬移、复制等等。先这里介绍 vi的如何做删除与修改。(注意:在 vi 的原始观念里,输入跟编辑是两码子事。编辑是在指令模式下操作的,先利用指令移动光标来定位要进行编辑的地方,然後才下指令做编辑。)
删除与修改文件的命令:
x: 删除光标所在字符。
dd :删除光标所在的列。
r :修改光标所在字元,r 後接著要修正的字符。
R: 进入取替换状态,新增文字会覆盖原先文字,直到按 [ESC] 回到指令模式下为止。
s: 删除光标所在字元,并进入输入模式。
S: 删除光标所在的列,并进入输入模式
其实呢,在PC上根本没有这麽麻烦!输入跟编辑都可以在输入模式下完成。例如要删除字元,直接按[Delete] 不就得了。而插入状态与取代状态可以直接用 [Insert] 切换,犯不著用什麽指令模式的编辑指令。不过就如前面所提到的,这些指令几乎是每台终端机都能用,而不是仅仅在 PC 上。
在指令模式下移动光标的基本指令是 h, j, k, l 。想来各位现在也应该能猜到只要直接用 PC 的方向键就可以了,而且无论在指令模式或输入模式下都可以。多容易不是。
当然 PC 键盘也有不足之处。有个很好用的指令 u 可以恢复被删除的文字,而 U 指令则可以恢复光标所在列的所有改变。这与某些电脑上的 [Undo] 按键功能相同。
三、附件:vi详细指令表
(一)、基本编辑指令:
新增 (append)
a :从光标所在位置後面开始新增资料,光标後的资料随新增资料向後移动。
A: 从光标所在列最後面的地方开始新增资料。
插入 (insert)
i: 从光标所在位置前面开始插入资料,光标後的资料随新增资料向後移动。
I :从光标所在列的第一个非空白字元前面开始插入资料。
开始 (open)
o :在光标所在列下新增一列并进入输入模式。
O: 在光标所在列上方新增一列并进入输入模式。
x: 删除光标所在字符。
dd :删除光标所在的列。
r :修改光标所在字元,r 後接著要修正的字符。
R: 进入取替换状态,新增文字会覆盖原先文字,直到按 [ESC] 回到指令模式下为止。
s: 删除光标所在字元,并进入输入模式。
S: 删除光标所在的列,并进入输入模式。
(二)、光标移动指令:
由於许多编辑工作是藉由光标来定位,所以 vi 提供许多移动光标的方式,这个我们列
几张简表来说明(这些当然是指令模式下的指令):
指令 说明 功能键
0 移动到光标所在列的最前面 [Home]
$ 移动到光标所在列的最後面 [End]
[CTRL][d] 向下半页 [PageDown]
[CTRL][f] 向下一页
[CTRL][u] 向上半页
[CTRL][b] 向上一页 [PageUp]
指令 说明
H 移动到视窗的第一列
M 移动到视窗的中间列
L 移动到视窗的最後列
b 移动到下个字的第一个字母
w 移缴细鲎值牡谝桓鲎帜?nbsp;
e 移动到下个字的最後一个字母
^ 移动到光标所在列的第一个非空白字元
指令 说明
n- 减号移动到上一列的第一个非空白字元前面加上数字可以指定移动到以上 n 列
n+ 加号移动到下一列的第一个非空白字元前面加上数字可以指定移动到以下 n 列
nG 直接用数字 n 加上大写 G 移动到第 n 列
指令 说明
fx
往右移动到 x 字元上
Fx 往左移动到 x 字元上
tx 往右移动到 x 字元前
Tx 往左移动到 x 字元前
; 配合 f&t 使用,重复一次
, 配合 f&t 使用,反方向重复一次
/string 往右移动到有 string 的地方
?string 往左移动到有 string 的地方
n 配合 /&? 使用,重复一次
N 配合 /&? 使用,反方向重复一次
指令 说明 备注
n(
左括号移动到句子的最前面句子是以前面加上数字可以指定往前移动 n 个句子 ! . ? 三种符号来界定
n) 右括号移动到下个句子的最前面前面加上数字可以指定往後移动 n 个句子 ! . ? 三种符号来界定
n{ 左括弧移动到段落的最前面 段落是以段落间的空白列界定
n} 前面加上数字可以指定往前移动 n 个段落右括弧移动到下个段落的最前面前面加上数字可以指定往後移动 n 个段落 段落是以段落间的空白列界定
(三)、更多的编辑指令
这些编辑指令非常有弹性,基本上可以说是由指令与范围所构成。例如 dw 怯缮境噶?nbsp;d 与范围 w 所组成,代表删除一个字 d(elete) w(ord) 。
指令列表如下:
d 删除(delete)
y 复制(yank)
p 放置(put)
c 修改(change)
范围可以是下列几个:
e 光晁谖恢玫礁米值淖钺嵋桓鲎帜?br> w 光标所在位置到下个字的第一个字母
b 光标所在位置到上个字的第一个字母
$ 光标所在位置到该列的最後一个字母
0 光标所在位置到该列的第一个字母
) 光标所在位置到下个句子的第一个字母
( 光标所在位置到该句子的第一个字母
} 光标所在位置到该段落的最後一个字母
{ 光标所在位置到该段落的第一个字母
说实在的,组合这些指令来编辑文件有一点点艺术气息。不管怎麽样,它们提供更多编辑文字的能力。值得注意的一点是删除与复制都会将指定范围的内容放到暂存区里,然後就可以用指令 p 贴到其它地方去,这是 vi 用来处理区段拷贝与搬移的办法。
某些 vi 版本,例如 Linux 所用的 elvis 可以大幅简化这一坨指令。如果稍微观察一下这些编辑指令就会发现问题其实是定范围的方式有点杂,实际上只有四个指令罢了。指令 v 非常好用,只要按下 v 键,光标所在的位置就会反白,然後就可以移动光标来设定范围,接著再直接下指令进行编辑即可。对於整列操作, vi 另外提供了更方便的编辑指令。前面曾经提到过删除整列文字的指令 dd 就是其中一个;cc 可以修改整列文字;而 yy 则是复制整列文字;指令 D 则可以删除光标到该列结束为止所有的文字。
(四)、文件操作指令
文件操作指令多以 : 开头,这跟编辑指令有点区别。
:q 结束编辑(quit)
:q! 不存档而要放弃编辑过的文件。
:w 保存文件(write)其後可加所要存档的档名。
:wq 即存档後离开。
zz 功能与 :wq 相同。
:x 与:wq相同
-----------------------
========cygwin=================
发帖时间: 05-05-08, 23:53
谢谢,楼上指点。
1楼说的那个没有看到
2楼的方法试过了。最快的是ftp://ftp.cise.ufl.edu
当然我不是全部试过,不过ping了20个肯定不只。这个最快只有200多ms的延时。我是电信的。
大家以后可以试试。
度我也试过了爽,我2M带宽下载速度达到100K接近。^_^~!!!!大家试试吧。
~~~~5分钟后,我又来了。装好了。^_^
这里的热情让我激动不已。
uname -a returns following output:
CYGWIN_NT-5.0 PCS734 1.3.5(0.47/3/2) 2001-11-13 23:16 i686 unknown
--install the ns under cygwin must under bash;
Please put /home/ns2/ns-allinone-2.28/bin:/home/ns2/ns-allinone-2.28/tcl8.4.5/unix:/home/ns2/ns-allinone-2.28/tk8.4.5/unix into your PATH; so that u will be able to run itm/tclsh/wish/xgraph.
important notices:
1. must put /home/ns2/ns-allinone-2.28/otcl-1.9, /home/ns2/ns-allinone-2.28/lib into your LD_LIBRARY_PATH variable;if it complains about X libraries, add path to your X libraries into LD_LIBRARY_PATH.
using csh, can set it like: setenv LD_LIBRARY_PATH
using sh, set like this: export LD_LIBRARY_PATH=
2. must put /home/ns2/ns-allinone-2.28/tcl8.4.5/library into ur TCL_LIBRARY env variable. otherwise, ns/nam will complain during startup
3. optional, to save disk space, u can delete directories tcl8.4.5 and tk8.4.5 installed under /home/ns2/ns-allinone-2.28/{bin,include,lib}
after this u can run ns validation suite with cd ns-2.28; ./validate
---set path for ns2----------------------
PATH="$PATH:/home/qyang/ns-allinone-2.28/bin:/home/qyang/ns-allinone-2.28/tcl8.4
.5/unix:/home/qyang/ns-allinone-2.28/tk8.4.5/unix"
#set env LD_LIBRARY_PATH /home/ns2/ns-allinone-2.28/otcl-1.9 wrong
#set env /home/ns2/ns-allinone-2.28/lib wrong
#no command setenv
#set LD_LIBRARY_PATH=/home/qyang/ns-allinone-2.28/otcl-1.9 wrong
#set env LD_LIBRARY_PATH /home/qyang/ns-allinone-2.28/lib wrong
#export LD_LIBRARY_PATH=/home/qyang/ns-allinone-2.28/otcl-1.9
#export LD_LIBRARY_PATH=/home/qyang/ns-allinone-2.28/lib
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/qyang/ns-allinone-2.28/otcl-1.9:/home/qy
ang/ns-allinone-2.28/lib"
u user
g group
o other
a all
r read
w write (and delete)
x execute (and access directory)
+ add permission
- take away permission
% chmod go-rwx biglist
% chmod a+rw biglist
cp file1 file2 copy file1 and call it file2
mv file1 file2 move or rename file1 to file2
rm file remove a file
rmdir directory remove a directory
cat file display a file
more file display a file a page at a time
head file display the first few lines of a file
tail file display the last few lines of a file
grep 'keyword' file search a file for keywords
wc file count number of lines/words/characters in file
还可以通过使用- R选项连同子目录下的文件一起设置:
chmod -R 664 /usr/local/home/dave/*
有相当一些U N I X命令也设置了s u i d和g u i d。如果想找出这些命令,可以进入/ b i n或/ s b i n目
录,执行下面的命令:
$ ls -l | grep '^...s'
上面的命令是用来查找s u i d文件的;
$ ls -l | grep '^...s..s'
u m a s k命令来改变文件创建的缺省权限
软链接实际上就是一个指向文件的指针。你将会发现这种软链接使用起来非常方便。你可以在每一位用户的$ H O M E目录下建立一个指向该文件的链接,而不是在每个目录下拷贝一份。这样当需要更改这一文
件时,只需改变一个源文件即可
$ find . -perm 755 -print
$ find ~ -user dave -print
$ find . -newer age.awk ! -newer belts.awk -exec ls -l {} \;
$touch -t 05042140 dstamp
在当前的文件系统中查找文件(不进入其他文件系统),可以使用f i n d命令的m o u n t选项
$ find . -name "*.XC" -mount -print
% echo $history
% set | less
.cshrc or .login
% nedit ~/.cshrc
% source .cshrc
% set path = ($path ~/units174/bin) //add to variable path
% cd; units //HINT: You can run multiple commands on one line by separating them with a semicolon.
$0$1$2$3$$$?$# --014.pdf-p143 shell编程和unix命令
使用u n s e t命令清除环境变量:
Section===============新手入门循序渐进学习LINUX之软件配置=======================
LINUX配置
在这里,配置的对象并非内核,而是软件。至于网络的配置,主要在安装系统是已经基本完成;也可以进入GUI界面从菜单选择liloconf来配置。
与WINDOWS一样,在LINUX系统可以从光盘、软盘安装应用软件;但不同的是,它需要用命令mount来登录光驱、软驱。而且,软件大多是经过压缩的,所以还需要懂得如何解压。最后必须配置、编译才能运行。下面分四个方面进行介绍:
一、mount登录
LINUX的软驱设备用特殊文件/dev/fd0,文件系统是msdos,因此用以下命令登录,读取软盘内容:
# mount -t msdos /dev/fd0 /mnt/floppy
# cd /mnt/floppy
同理,键入以下命令读光盘:
# mount -t iso9660 /dev/hdb /mnt/cdrom
# cd /mnt/cdrom
然后,用cp命令将所需的软件拷贝到系统中。
退出软驱、光驱用umount命令。注意,不能在其目录中使用此命令,而应先cd到其他目录,再使用:umount /mnt/cdrom。
二、安装软件
for
LINUX的软件一般是以.gz或.tar或者.tar.gz结尾的。前者是由gzip压缩的,后者是先用tar归档,在用gzip压缩而成的。
1、以.gz结尾的为压缩文件,用命令:gzip -d filename来解压,得到的文件在当前目录中,但已没有了.gz。
2、以.tar结尾的为归档文件,用命令:tar -xvf filename来展开,生成的文件与源文件在同一目录中,只是少了.tar。
3、以.tar.gz结尾的文件最常见,可直接用命令:gzip -cd filename | tar xfv -来安装。
一般情况下,这类文件的第一项是一个目录,所以用上面的命令时会创建出这一个目录,并把所有的文件都存在此目录之下。如果是特殊情况,可先用命令:tar
-tvf filename | more 来查看文件的第一项。倘若它并不是目录,则先创建一个目录,把文件放在此目录之下,在用命令:tar
-xvf filename来安装。
经过以上步骤,会生成README及INSTALL等文件。用vi来仔细阅读这些文件造处于LINUX有关的部分,更具体是进行配置。一般的步骤是:(1)./config,(2)make
install,(3)make。主要的变化在第一步,其后面需要参数,可见入命令来选择:./config --help。
三、实践举例笔者曾配置了apache(阿帕其服务器)、php3两个软件。
先从网上下载for LINUX的软件apache.tar.gz、php3.tar.gz。
1、由于apache.tar.gz大于1.44M,所以笔者在center_5的MSDOS上用telnet命令登录LINUX,通过put将其上传。
2、笔者将这两个软件放在/usr/src目录之下,用命令gzip -cd apache.tar.gz(php3.tar.gz)|
tar xfv -来安装。这样会看到两个目录:apache_1.3.6和php-3.0.7。
3、在第一个目录之下,会看到非常重要的文件:README、INSTALL。如果此时是在GUI界面,则可以打开两个xterm,一个用于仔细阅读,一个则用于根据文件的提示进行配置。
4、在第二个目录中,也会很快的找到文件:INSTALL、INSTALL.DSO、README.QNX。步骤与3相似。由于这两个文件相互关联,必须先配置前者。
5、配置完后,进入/apache_1.3.6/conf/httpd.conf。在文件里面,理解其注释,删除或增加一些选项前的"#"。保存文件后,执行命令/usr/src/apache_1.3.6/bin/apachectl
start,即打开http,然后可以在Netscape Communication来浏览网页。
心得体会在学习的一个多月来,笔者面对的是一个全新的操作系统,绝大多数操作是通过自己键入命令来实现的,从而能够深入到一定层次的了解操作系统内核。
1、懂得了UNIX的一些基本命令;
2、熟悉vi文本编辑;
3、知道如何在LINUX、UNIX上编写、编译C、C++、JAVA程序;
4、进一步了解了网络原理,动手配置了网络应用软件,从而也清楚了软件安装的一般步骤。
5、毕竟现今for LINUX的应用软件少,而且RedHat
LINUX不支持中文,因而还不能完全脱离WINDOWS。因此,应发挥LINUX是一个非常优秀的网络服务器操作系统的优点,扬长避短。
=================from linuxsir bbs ==============
用dos的引导盘使用fdisk /mbr清除引导区信息!
然后用redhat的第一张光盘引导,进入linux rescue模式!
重新安装grub!
发帖时间: 05-03-31, 00:05
在GRUB中用单用户模式进去~~
然后vi /etc/shadow 找到ROOT把ROOT后一个MD5格式的字符串"干掉".保存~然后重启重新用单用户模式进入passwd root 自己输入需要的密码就好了~
--this can work by quentin, root:xxxxx:19333:....., just delete the xxx between colon. verified under red hat linux.
类似这样的,然后把键盘移动到该句,再按一下[e]键,在类似的语句后面加上 linux single。然后就按回车[enter]。然后出现另外一个界面,按一个[b]键。这样GRUB就把系统引入单用户模式了。
可能出现的是这样的。。。 just add linux single, can enter single mode, verified by quentin under red hat.
http://www.linuxsir.org/bbs/showthread.php?s=&threadid=16998 在GRUB系统引导程序下进入单用户模式的办法
http://www.linuxsir.org/bbs/showthread.php?s=&threadid=8721
http://www.linuxsir.org/bbs/showthread.php?s=&threadid=3393
发帖时间: 02-07-28, 00:48
让系统自动加载FAT32
用下面这个命令来判断我们的windows分区,这个命令能把所有硬盘上的分区都能列出来。这个命令比较强,哈。。最适合不知道自己的硬盘情况的弟兄。。。
[root@LinuxSir root]# fdisk -l
如果只列一个硬盘的可用下面这个命令,下面这两条命令,第一条是列第一个硬盘的,第二个是列第二个硬盘的,这两条命令和 fdisk -l结合起来,配合来用,效果最佳。我以我的硬盘来说。。。。也能用第一个命令。。这个比较简单,试一下就知道了
#fdisk -l /dev/hda
#fdisk -l /dev/hdb
Disk /dev/hda: 255 heads, 63 sectors, 4865 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 1147 9213246 7 HPFS/NTFS
/dev/hda2 1148 4864 29856802+ f Win95 Ext'd (LBA)
/dev/hda5 1148 2039 7164958+ 7 HPFS/NTFS
/dev/hda6 2040 2804 6144831 b Win95 FAT32
/dev/hda7 2805 3824 8193118+ b Win95 FAT32
/dev/hda8 3825 3830 48163+ 83 Linux
/dev/hda9 3831 4799 7783461 83 Linux
/dev/hda10 4800 4864 522081 82 Linux swap
从这上面,我们可以看来,/dev/hda6和/dev/hda7就是win下的fat32分区。
第二;我们加载windows的分区,是不是在linux下有个文件夹可以放下去?这样理解就对了。我们可以用下面的方法来操作。我在这个例子中,把/hda6的内容,我想放到WinE这个文件夹。另一个则是WinF,这个文件夹的命名,可以用你喜欢的。但修改/etc/fstab的内容时,也要用这个文件夹,也就是统一起来。。
#mkdir /mnt/WinE
#mkdir /mnt/WinF
注意大小写。。
或用鼠标点kde自带的浏览器在地址栏上输入:
/mnt
就能进入/mnt这个目录了。。
然后就按鼠标的右键来建目录,这个简单吧。。。哈。。
然后,我们来修改/etc目录下的fstab
/dev/hda6 /mnt/WinE vfat rw,codepage=936,iocharset=cp936 0 0
如果加E盘就是:
/dev/hda7 /mnt/WinF vfat rw,codepage=936,iocharset=cp936 0 0
然后在/mnt/下建立目录WinD和WinE
对于Redhat 8.0,应该把codepage=936去掉
然后在KDE桌面上用右键点击[新建]-》硬 盘-》然后就点几下鼠标就OK了。。。
如果手工mount分区如何做呢?
事前要建好目录,比如在/mnt目录下建一个tmp目录
#mkdir /mnt/tmp
然后就是mount了,mount也应该有个目的地吧,那我们就把目的地定为/mnt/tmp
比如我们mount /dev/hda1
如下:
#mount -o iocharset=cp936 /dev/hda1 /mnt/tmp
北南老大,我只在/etc/fstab中添加,另一个文件etc/mtab好像已经自动添加了.
是不是RH73有这个功能的?
哈哈。。兄弟,这个mtab是系统关机时umount时要用到的。。。
在mnt目录下建立你想要的分区名称如WinD,然后用下面的指令格式加载.
当然你可以在etc中修改fstab文件.这样可以自动加载
/dev/hda9 /mnt/F vfat default,codepage=936,iocharset=gb2312 0 0
******************************************************
我的fstab文件格式,参考一下
/dev/hda1 /mnt/C vfat default,codepage=936,iocharset=gb2312 0 0
/dev/hda7 /mnt/D vfat default,codepage=936,iocharset=gb2312 0 0
/dev/hda8 /mnt/E vfat default,codepage=936,iocharset=gb2312 0 0
/dev/hda9 /mnt/F vfat default,codepage=936,iocharset=gb2312 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu,codepage=936,iocharset=gb2312 0 0
这样可以显示中文的.你试一下
[root@localhost root]# fdisk -l
Disk /dev/hdc: 255 heads, 63 sectors, 4865 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdc1 * 1 1217 9775521 c Win95 FAT32 (LBA)
/dev/hdc2 1218 4865 29302560 f Win95 Ext'd (LBA)
/dev/hdc5 1218 3046 14691411 b Win95 FAT32
/dev/hdc6 3047 3569 4200966 b Win95 FAT32
/dev/hdc7 3570 4092 4200966 b Win95 FAT32
/dev/hdc8 4093 4829 5919921 83 Linux
/dev/hdc9 4830 4865 289138+ 82 Linux swap
[root@localhost root]#
就是这个样子的 你帮我看看吧
mount -t vfat /dev/hdc5 /mnt/winD
Section==============Web Resources==============================
CN-------------www.linuxeden.com
CN-------------www.linuxforum.net
CN-------------www.linuxfans.org
CN-------------www.linuxsir.org/bbs
CN-------------http://bbs.chinaunix.net/viewthread.php?tid=746147
CN-------------http://fedora.linuxsir.org/main/?q=aggregator/sources/1
CN-------------http://linux.chinaunix.net/
CN-------------http://slack.linuxsir.org/main/?q=node/145
CN-------------http://www.math.zju.edu.cn/ligangliu/LaTeXForum/tex_edit.htm
CN-------------ftp://ftp.ctex.org/pub/tex/systems/ctex/ --download CTeX package
EN-------------ctan.tug.org/starter.html ---the comprehensive ReX Archive Network
EN-------------www.winedt.com ---winedit download
EN-------------www.tug.org/begin.html
EN-------------www.gnu.org/software/emacs/manual/---GNU Emacs Manual
EN---------http://rpmfind.net/linux/RPM 去这里找一下这几个包吧!
EN------http://grub4dos.sourceforge.net/ http://sourceforge.net/projects/grub4dos
EN-------------http://www.slackworld.net/01/tips.html
EN-------------http://gurus.com.au/JobSeeker/Default.aspx ----IT career
EN-----java--------http://forum.java.sun.com/thread.jspa?threadID=568603&messageID=2810271
EN-----java--------http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html
CN-----.Net--------http://www.chinaaspx.com/archive/Java/20906.htm China .net club/ is used for search a certain word, C-s is used for searching as well when reading info help ? to get command list for reading info
#uname //list system information, like kernel version.
#df -a -h
man: list hard disk space usage under linux.
# chown -R q.yang repos_personal/
man: change access right
#chgrp admin -R /opt/mysql/var/
man: change group
# chmod 771 -R /opt/mysql/var
man: change access right
Subscribe to:
Posts (Atom)