自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(0)
  • 资源 (7)
  • 收藏
  • 关注

空空如也

整理后java开发全套达内学习笔记(含练习)

abstract (关键字) 抽象 ['æbstrækt] access vt.访问,存取 ['ækses]'(n.入口,使用权) algorithm n.算法 ['ælgәriðm] Annotation [java] 代码注释 [ænәu'teiʃәn] anonymous adj.匿名的[ә'nɒnimәs]'(反义:directly adv.直接地,立即[di'rektli, dai'rektli]) apply v.应用,适用 [ә'plai] application n.应用,应用程序 [,æpli'keiʃәn]' (application crash 程序崩溃) arbitrary a.任意的 ['ɑ:bitrәri] argument n.参数;争论,论据 ['ɑ:gjumәnt]'(缩写 args) assert (关键字) 断言 [ә'sә:t] ' (java 1.4 之后成为关键字) associate n.关联(同伴,伙伴) [ә'sәuʃieit] attribute n.属性(品质,特征) [ә'tribju:t] boolean (关键字) 逻辑的, 布尔型 call n.v.调用; 呼叫; [kɒ:l] circumstance n.事件(环境,状况) ['sә:kәmstәns] crash n.崩溃,破碎 [kræʃ] cohesion 内聚,黏聚,结合 [kәu'hi:ʒәn] (a class is designed with a single, well-focoused purpose. 应该不止这点) command n. 命令,指令 [kә'mɑ:nd](指挥, 控制) (command-line 命令行) Comments [java] 文本注释 ['kɒments] compile [java] v.编译 [kәm'pail]' Compilation n.编辑[,kɒmpi'leiʃәn] const (保留字) constant n. 常量, 常数, 恒量 ['kɒnstәnt] continue (关键字) coupling 耦合,联结 ['kʌpliŋ] making sure that classes know about other classes only through their APIs. declare [java] 声明 [di'klєә] default (关键字) 默认值; 缺省值 [di'fɒ:lt] delimiter 定义符; 定界符 Encapsulation[java] 封装 (hiding implementation details) Exception [java] 例外; 异常 [ik'sepʃәn] entry n.登录项, 输入项, 条目['entri] enum (关键字) execute vt.执行 ['eksikju:t] exhibit v.显示, 陈列 [ig'zibit] exist 存在, 发生 [ig'zist] '(SQL关键字 exists) extends (关键字) 继承、扩展 [ik'stend] false (关键字) final (关键字) finally (关键字) fragments 段落; 代码块 ['frægmәnt] FrameWork [java] 结构,框架 ['freimwә:k] Generic [java] 泛型 [dʒi'nerik] goto (保留字) 跳转 heap n.堆 [hi:p] implements (关键字) 实现 ['implim

2011-06-06

EditPlus 免注册版本

EditPlus 免注册版本EditPlus 免注册版本

2010-03-14

myeclipse+hibernate项目配置包

myeclipse+hibernate项目配置包 把包解压后倒入项目后 实现hibernate配置

2010-03-14

php+ Apache +mysql服务套件

php+ Apache +mysql服务套件

2010-03-05

达内 coreJava 习题答案

1,编写程序,判断给定的某个年份是否是闰年。 闰年的判断规则如下: (1)若某个年份能被4整除但不能被100整除,则是闰年。 (2)若某个年份能被400整除,则也是闰年。 import java.util.Scanner; class Bissextile{ public static void main(String[] arge){ System.out.print("请输入年份"); int year; //定义输入的年份名字为“year” Scanner scanner = new Scanner(System.in); year = scanner.nextInt(); if (year<0||year>3000){ System.out.println("年份有误,程序退出!"); System.exit(0); } if ((year%4==0)&&(year%100!=0)||(year%400==0)) System.out.println(year+" is bissextile"); else System.out.println(year+" is not bissextile "); } } 2,给定一个百分制的分数,输出相应的等级。 90分以上 A级 80~89 B级 70~79 C级 60~69 D级 60分以下 E级 import java.util.Scanner; class Mark{ public static void main(String[] args){ System.out.println("请输入一个分数"); //定义输入的分数为“mark”,且分数会有小数 double mark; Scanner scanner = new Scanner(System.in); mark = scanner.nextDouble(); //判断是否有输入错误。 if(mark<0||mark>100){ System.out.println("输入有误! "); System.exit(0); } /*判断分数的等级 90分以上者A级, 80~89分者 B级,70~79分者 C级, 60~69者 D级,60分以下 E级 */ if (mark>=90) System.out.println("this mark is grade \'A\' "); else if (mark>=80) System.out.println("this mark is grade \'B\' "); else if (mark>=70) System.out.println("this mark is grade \'C\' "); else if (mark>=60) System.out.println("this mark is grade \'D\' "); else System.out.println("this mark is grade \'E\' "); } } 3,编写程序求 1+3+5+7+……+99 的和值。 class he{ public static void main(String[] args){ int number = 1; //初始值1,以后再+2递增上去 int sum = 0; for ( ; number <100; number+=2 ){ sum += number; } System.out.println("1+3+5+7+……+99= " +sum); } } 4、利用for循环打印 9*9 表? 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 //循环嵌套,打印九九乘法表 public class NineNine{ public static void main(String[]args){ System.out.println(); for (int j=1;j<10;j++){ for(int k=1;k<10;k++) { //老师的做法,判断语句里的 k<=j,省去下列的if语句。 if (k>j) break; //此处用 continue也可以,只是效率低一点 System.out.print(" "+k+"X"+j+"="+j*k); } System.out.println(); } } } 6、输出所有的水仙花数,把谓水仙花数是指一个数3位数,其各各位数字立方和等于其本身, 例如: 153 = 1*1*1 + 3*3*3 + 5*5*5 class DafodilNumber{ public static void main(String[] args){ System.out.println("以下是所有的水仙花数"); int number = 100; // 由于水仙花数是三位数,故由100开始算起 int i, j, k; // i j k 分别为number 的百位、十位、个位 for (int sum; number<1000; number++){ i=number/100; j=(number-i*100)/10; k=number-i*100-j*10; sum=i*i*i+j*j*j+k*k*k; if (sum==number) System.out.println(number+" is a dafodil number! "); } } } 7、求 a+aa+aaa+.......+aaaaaaaaa=? 其中a为1至9之中的一个数,项数也要可以指定。 import java.util.Scanner; class Multinomial{ public static void main(String[] args){ int a; //定义输入的 a int howMany; //定义最后的一项有多少个数字 Scanner scanner = new Scanner(System.in); System.out.println("请输入一个 1~9 的 a 值"); a = scanner.nextInt(); System.out.println("请问要相加多少项?"); howMany = scanner.nextInt(); int sum=0; int a1=a; // 用来保存 a 的初始值 for (int i=1; i<=howMany; i++){ sum+= a; a = 10*a +a1; // 这表示a 的下一项 // 每次 a 的下一项都等于前一项*10,再加上刚输入时的 a ;注意,这时的 a 已经变化了。 } System.out.println("sum="+sum); } } 8、求 2/1+3/2+5/3+8/5+13/8.....前20项之和? class Sum{ public static void main(Sting[] args){ double sum=0; double fenZi=2.0, fenMu=1.0; //初始的分子 (fenZi)=2,分母(fenMu)=1 for(int i=1; i<=20; i++){ sum += fenZi / fenMu ; fenMu = fenZi; //下一项的分母 = 上一项的分子 fenZi += fenMu; //下一项的分子 = 上一项的分子加分母 } System.out.println("sum= "sum); } } 9、利用程序输出如下图形: * * * * * * * * * * * * * * * * * * * * * * * * * class Asterisk{ public static void main(String[] args){ for (int i=1; i<=13; i+=2){ for(int j=1; j<=i && i+j<= 14; j++){System.out.print("* ");} System.out.println(); // 换行 } } } 11、计算圆周率 PI=4-4/3+4/5-4/7....... 打印出第一个大于 3.1415小于 3.1416的值 class Pi { public static void main(String[] args){ double pi =0; //定义初始值 double fenZi = 4; //分子为4 double fenMu = 1; //第一个4,可看作分母为1 的分式,以后的分母每次递增2 for (int i = 0; i < 1000000000; i++){ //运行老久,减少循环次数会快很多,只是精确度小些 pi += (fenZi/fenMu) ; fenZi *= -1.0; //每项分子的变化是+4,-4,+4,-4 .... fenMu += 2.0; //分母的变化是1,3,5,7, .... 每项递加2 } System.out.println(pi); } } 输出结果为pi = 3.1415926525880504,应该不精确 12、输入一个数据n,计算斐波那契数列(Fibonacci)的第n个值 1 1 2 3 5 8 13 21 34 规律:一个数等于前两个数之和 //计算斐波那契数列(Fibonacci)的第n个值 public class Fibonacci{ public static void main(String args[]){ int n = Integer.parseInt(args[0]); int n1 = 1;//第一个数 int n2 = 1;//第二个数 int sum = 0;//和 if(n<=0){ System.out.println("参数错误!"); return; } if(n<=2){ sum = 1; }else{ for(int i=3;i<=n;i++){ sum = n1+n2; n1 = n2; n2 = sum; } } System.out.println(sum); } } //计算斐波那契数列(Fibonacci)的第n个值 //并把整个数列打印出来 public class FibonacciPrint{ public static void main(String args[]){ int n = Integer.parseInt(args[0]); FibonacciPrint t = new FibonacciPrint(); for(int i=1;i<=n;i++){ t.print(i); } } public void print(int n){ int n1 = 1;//第一个数 int n2 = 1;//第二个数 int sum = 0;//和 if(n<=0){ System.out.println("参数错误!"); return; } if(n<=2){ sum = 1; }else{ for(int i=3;i<=n;i++){ sum = n1+n2; n1 = n2; n2 = sum; } } System.out.println(sum); } } 13、求1-1/3+1/5-1/7+1/9......的值。 a,求出前50项和值。 b,求出最后一项绝对值小于1e-5的和值。 15、在屏幕上打印出n行的金字塔图案,如,若n=5,则图案如下: * *** ***** ******* ********* //打印金字塔图案 public class PrintStar{ public static void main(String args[]){ int col = Integer.parseInt(args[0]); for(int i=1;i<=col;i++){//i表示行数 //打印空格 for(int k=0;k<col-i;k++){ System.out.print(" "); } //打印星星 for(int m=0;m<2*i-1;m++){ System.out.print("*"); } System.out.println(); } } } 16、歌德巴赫猜想,任何一个大于六的偶数可以拆分成两个质数的和 打印出所有的可能 //任何一个大于六的偶数可以拆分成两个质数的和 //打印出所有的可能 public class Gedebahe{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); if(num<=6){ System.out.println("参数错误!"); return; } if(num%2!=0){ System.out.println("参数错误!"); return; } Gedebahe g = new Gedebahe(); //1不是质数,2是偶数,因此从3开始循环 for(int i=3;i<=num/2;i++){ if(i%2==0){//如果为偶数,退出本次循环 continue; } //当i与num-i都为质数时,满足条件,打印 if(g.isPrime(i) && g.isPrime(num-i)){ System.out.println(i+" + "+(num-i)+" = "+num); } } } 第4章 数组 1. 定义一个int型的一维数组,包含10个元素,分别赋一些随机整数,然后求出所有元素的最大值, 最小值,平均值,和值,并输出出来。 class ArrayNumber{ public static void main(String[] args){ int[] arrayNumber; arrayNumber = new int[10]; System.out.println("以下是随机的10个整数:"); // 填入随机的 10个整数 for (int i =0; i<arrayNumber.length; i++){ arrayNumber[i] = (int)(100*Math.random()); System.out.print(arrayNumber[i]+" "); } System.out.println(); int max = arrayNumber[0]; int min = arrayNumber[0]; int sum = 0; for (int i =0; i<arrayNumber.length; i++){ if(max < arrayNumber[i]) max = arrayNumber[i]; //求最大值 if(min > arrayNumber[i]) min = arrayNumber[i]; //求最小值 sum += arrayNumber[i]; } System.out.println("其中 Max="+max+",Min="+min+",Sum="+sum+",Avg="+sum/10.0); } } 2.定义一个int型的一维数组,包含10个元素,分别赋值为1~10, 然后将数组中的元素都向前移一个位置, 即,a[0]=a[1],a[1]=a[2],…最后一个元素的值是原来第一个元素的值,然后输出这个数组。 3. 定义一个int型的一维数组,包含40个元素,用来存储每个学员的成绩,循环产生40个0~100之间的随机整数, 将它们存储到一维数组中,然后统计成绩低于平均分的学员的人数,并输出出来。 4. (选做)承上题,将这40个成绩按照从高到低的顺序输出出来。 5,(选做)编写程序,将一个数组中的元素倒排过来。例如原数组为1,2,3,4,5;则倒排后数组中的值 为5,4,3,2,1。 6,要求定义一个int型数组a,包含100个元素,保存100个随机的4位数。再定义一个 int型数组b,包含10个元素。统计a数组中的元素对10求余等于0的个数,保存 到b[0]中;对10求余等于1的个数,保存到b[1]中,……依此类推。 class Remain{ public static void main( String[] args){ int[] a = new int[100]; //保存100个随机4位数到 a 中 for (int i = 0; i < a.length; i++){ a[i] = (int) (1000*Math.random()); } //统计 a 数组中的元素对 10 求余的各个的数目 int[] b = new int[10]; int k,sum; for (int j = 0; j < b.length; j++){ for (k=0,sum=0; k < a.length; k++){ if ((a[k]%10)==j) sum++; } b[j] = sum; System.out.printf("b[%d]=%d\n",j,b[j]); } } } 7,定义一个20*5的二维数组,用来存储某班级20位学员的5门课的成绩;这5门课 按存储顺序依次为:core C++,coreJava,Servlet,JSP和EJB。 (1)循环给二维数组的每一个元素赋0~100之间的随机整数。 (2)按照列表的方式输出这些学员的每门课程的成绩。 (3)要求编写程序求每个学员的总分,将其保留在另外一个一维数组中。 (4)要求编写程序求所有学员的某门课程的平均分。 class Student{ public static void main(String[] args ){ int[][] mark = new int[20][5]; // 给学生赋分数值,随机生成 for ( int i = 0; ) } }//未完成 8,完成九宫格程序 在井字形的格局中(只能是奇数格局),放入数字(数字由),使每行每列以及斜角线的和都相等 经验规则:从 1 开始按顺序逐个填写; 1 放在第一行的中间位置;下一个数往右上角45度处填写; 如果单边越界则按头尾相接地填;如果有填写冲突,则填到刚才位置的底下一格; 如果有两边越界,则填到刚才位置的底下一格。 个人认为,可以先把最中间的数填到九宫格的最中间位置;再按上面的规则逐个填写,而且 填的时候还可以把头尾对应的数填到对应的格子中。(第 n 个值跟倒数第 n 个值对应,格局上以最中 间格为轴心对应) 这样就可以同时填两个数,效率比之前更高;其正确性有待数学论证(但多次实验之后都没发现有错)。 九宫格的 1 至少还可以填在另外的三个位置,只是接下来的填写顺序需要相应改变; 再根据九宫格的对称性,至少可以有8种不同的填写方式 import java.util.Scanner; class NinePalace{ public static void main(String[] args){ // 定义 N 为九宫格的行列数,需要输入 System.out.println("请输入九宫格的行列规模(只能是奇数的)"); Scanner n = new Scanner(System.in); int N; //判断格局是否奇数 (可判断出偶数、负数 及小数) double d; while (true){ d = n.nextDouble(); N = (int)d; if ((d-N)>1.0E-4||N%2==0||N<0) {System.out.println("输入出错,格局只能是正奇数。请重新输入");} else break; } //老师的九宫格填写方法 int[][] result = new int[N][N]; //定义保存九宫格的数组 int row = 0; //行 初始位置 int col = N/2; //列 初始位置,因为列由0开始,故N/2是中间位置 for (int i=1; i<=N*N; i++){ result [row][col] = i; row--; col++; if (row<0&&col>=N){col--;row+=2;} //行列都越界 else if (row<0){ row = N-1;} //行越界 else if (col>=N){col = 0;} //列越界 else if (result[row][col] != 0){col--;row+=2;} //有冲突 } //打印出九宫格 for (int i=0; i<N; i++){ for(int j=0; j<N; j++){System.out.print(result[i][j]+"\t");} System.out.println(); } //我个人的填格方式 int[][] result2 = new int[N][N]; //为免冲突,重新 new 一个数组 result2[N/2][N/2] = (N*N+1)/2; //先把中间值赋予中间位置 row = 0; //定义行及列的初始赋值位置。之前赋值的for对两个值有影响,故需重新定位 col = N/2; for (int i=1; i<=N*N/2; i++){ result2[row][col] = i; //下面这句是把跟 i 对应的值放到格局对应的位置上 result2[N-row-1][N-col-1] = N*N+1-i; row--; col++; if (row<0){ row = N-1;} //行越界 else if (col>=N){col = 0;} //列越界 else if (result2[row][col] != 0){col--;row+=2;} //有冲突 //这方法不可能出现行列两边都越界的情况,详情需要数学论证 } System.out.println(); //再次打印出九宫格,以对比验证 for (int i=0; i<N; i++){ for(int j=0; j<N; j++){System.out.print(result2[i][j]+"\t");} System.out.println(); } } } 9,求一个3*3矩阵对角线元素之和 10,打印杨辉三角 11. 约梭芬杀人法 把犯人围成一圈,每次从固定位置开始算起,杀掉第7个人,直到剩下最后一个。 11_2、用数组实现约瑟夫出圈问题。 n个人排成一圈,从第一个人开始报数,从1开始报,报到m的人出圈,剩下的人继续开始从1报数,直到所有的人都出圈为止。对于给定的n,m,求出所有人的出圈顺序。 12. 判断随机整数是否是素数 产生100个0-999之间的随机整数,然后判断这100个随机整数哪些是素数,哪些不是? public class PrimeTest{ public static void main(String args[]){ for(int i=0;i<100;i++){ int num = (int)(Math.random()*1000); PrimeTest t = new PrimeTest(); if(t.isPrime(num)){ System.out.println(num+" 是素数!"); }else{ System.out.println(num+" 不是素数!"); } System.out.println(); } } public boolean isPrime(int num){ for(int i=2;i<=num/2;i++){ if(num%i==0){ System.out.println(num+"第一个被"+i+"整除!"); return false; } } return true; } } 冒泡排序法: //按从大到小的排序 int tmp = a[0]; for (int i=0; i < a.length; i++){ for (int j=0; j < a.length - i -1; j++){ if (a[j] < a[j+1]) { tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp; } } } day06 练习 某公司的雇员分为以下若干类: Employee:这是所有员工总的父类,属性:员工的姓名和生日月份。 方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日, 则公司会额外奖励100元。 SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪 HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160 小时的部分按照1.5倍工资发放 属性:每小时的工资、每月工作的小时数 SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定 属性:月销售额、提成率 BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员, 工资由底薪加上销售提成部分 属性:底薪。 public class TestEmployee{ public static void main(String[]args){ Employee[] es = new Employee[5]; es[0] = new Employee("赵君",2); es[1] = new SalariedEmployee("宋婕", 1, 8000); es[2] = new HourlyEmployee("王超", 5, 10, 300); es[3] = new SalesEmployee("秋娥", 2, 200000, 0.05); es[4] = new BaseSalarySalesEmployee("郭镫鸿", 1, 1000000, 0.1, 10000); int month = 2;//本月为2月 System.out.println("宇宙集团"+month+"月工资表:"); for(int i=0; i<es.length; i++){ System.out.println(es[i].getName()+":"+es[i].getSalary(month)); } } } class Employee{ private String name; private int birth; public String getName(){ return name; } public Employee(String name, int birth){ this.name = name; this.birth = birth; } public double getSalary(int month){ if(month==birth){ return 100; } return 0; } } class SalariedEmployee extends Employee{ private double salary; public SalariedEmployee(String name, int birth, double salary){ super(name, birth); this.salary = salary; } public double getSalary(int month){ return salary + super.getSalary(month); } } class HourlyEmployee extends Employee{ private double hourSalary; private int hour; public HourlyEmployee(String name, int birth, double hourSalary, int hour){ super(name, birth); this.hourSalary = hourSalary; this.hour = hour; } public double getSalary(int month){ if(hour<=160){ return hourSalary*hour+super.getSalary(month); }else{ return 160*hourSalary+(hour-160)*hourSalary*1.5+super.getSalary(month); } } } class SalesEmployee extends Employee{ private double sales; private double pre; public SalesEmployee(String name, int birth, double sales, double pre){ super(name, birth); this.sales = sales; this.pre = pre; } public double getSalary(int month){ return sales*pre+super.getSalary(month); } } class BaseSalarySalesEmployee extends SalesEmployee{ private double baseSalary; public BaseSalarySalesEmployee(String name, int birth, double sales, double pre, double baseSalary){ super(name, birth, sales, pre); this.baseSalary = baseSalary; } public double getSalary(int month){ return baseSalary+super.getSalary(month); } } /** * 在原有的雇员练习上修改代码 * 公司会给SalaryEmployee每月另外发放2000元加班费,给 * BasePlusSalesEmployee发放1000元加班费 * 改写原有代码,加入以上的逻辑 * 并写一个方法,打印出本月公司总共发放了多少加班费 * @author Administrator * */ public class EmployeeTest { /** * @param args */ public static void main(String[] args) { Employee e[] = new Employee[4]; e[0] = new SalariedEmployee("魏威",10,5000); e[1] = new HourlyEmployee("段利峰",8,80,242); e[2] = new SalesEmployee("林龙",11,300000,0.1); e[3] = new BasedPlusSalesEmployee("华溪",1,100000,0.15,1500); for(int i=0;i<e.length;i++){ System.out.println(e[i].getName()+": "+e[i].getSalary(11)); } //统计加班费 int result = 0; // for(int i=0;i<e.length;i++){ // if(e[i] instanceof SalariedEmployee){ // SalariedEmployee s = (SalariedEmployee)e[i]; // result += s.getAddtionalSalary(); // } // if(e[i] instanceof BasedPlusSalesEmployee){ // BasedPlusSalesEmployee b = (BasedPlusSalesEmployee)e[i]; // result += b.getAddtionalSalary(); // } // } for(int i=0;i<e.length;i++){ result += e[i].getAddtionalSalary(); } System.out.println("加班费: "+result); } } interface AddtionalSalary{ int getAddtionalSalary(); } class Employee implements AddtionalSalary{ private String name;//员工姓名 private int birth;//员工生日月份 public Employee(String name,int birth){ this.name = name; this.birth = birth; } public int getSalary(int month){ int result = 0; if(month==birth) result = 100; return result; } public String getName(){ return name; } public int getAddtionalSalary(){ return 0; } } class SalariedEmployee extends Employee{ private int salaryPerMonth; public SalariedEmployee(String name,int birth,int salaryPerMonth){ super(name,birth); this.salaryPerMonth = salaryPerMonth; } public int getSalary(int month){ return this.salaryPerMonth + super.getSalary(month)+ this.getAddtionalSalary(); } public int getAddtionalSalary(){ return 2000; } } class HourlyEmployee extends Employee{ private int salaryPerHour; private int hoursPerMonth; public HourlyEmployee(String name,int birth,int salaryPerHour,int hoursPerMonth){ super(name,birth); this.salaryPerHour = salaryPerHour; this.hoursPerMonth = hoursPerMonth; } public int getSalary(int month){ int result = 0; if(this.hoursPerMonth<=160){ result = hoursPerMonth*salaryPerHour; }else{ result = 160*salaryPerHour + (int)((hoursPerMonth-160)*1.5*salaryPerHour); } return result+super.getSalary(month); } } class SalesEmployee extends Employee{ private int sales; private double rate; public SalesEmployee(String name,int birth,int sales,double rate){ super(name,birth); this.sales = sales; this.rate = rate; } public int getSalary(int month){ return (int)(sales*rate)+super.getSalary(month); } } class BasedPlusSalesEmployee extends SalesEmployee{ private int basedSalary; public BasedPlusSalesEmployee(String name,int birth,int sales,double rate,int basedSalary){ super(name,birth,sales,rate); this.basedSalary = basedSalary; } public int getSalary(int month){ return this.basedSalary+super.getSalary(month) + this.getAddtionalSalary(); } public int getAddtionalSalary(){ return 1000; } } 经典算法: 1. 某学校为学生分配宿舍,每6个人一间房(不考虑性别差异),问需要多少房? 答案: (x+5)/6 注意理解int类型数值。 2. 让数值在 0~9 之间循环。 public class test{ public static void main(String[] args){ int i=0; while(true){ i = (i+1)%10; System.out.println(i); } } } 作业: 1. 写一个数组类(放对象): 功能包括:添加(添加不限制多少项)、修改、插入、删除、查询 class MyArray{ private Object[] os = new Object[10]; public void add(Object o); public void set(int index, Object o); public void insert(int index, Objecto); public void remove(int index); public void remove(Object o); public Object get(int index); } public class TestMyArray{ public static void main(String[]args){ MyArray ma = new MyArray(); ma.add("aaa"); ma.add("bbb"); ma.add("ccc"); Object o = ma.get(1); Iterator it = ma.iterator(); while(it.hasNext()){ Object o1 = it.next(); System.out.println(o1); } } } 作业 10-08 1. 随机产生 20 个整数(10以内的),放入一个ArrayList中, 用迭代器遍历这个ArrayList 2. 并删除其中为 5 的数 3. 再产生 3 个整数,插入到位置 4 处 4. 把所有值为 1 的数都变成 10 import java.util.ArrayList; class ArrayList{ private Object[] os = new Object[20]; } public class TestArray{ public static void main(String[]args){ ArrayList a = new ArrayList(); ma.add("aaa"); ma.add("bbb"); ma.add("ccc"); Object o = ma.get(1); Iterator it = ma.iterator(); while(it.hasNext()){ Object o1 = it.next(); System.out.println(o1); } } } 1. 产生 3000 个 10 以内的数,放入 hashSet 2. 遍历它,打印每一个值 import java.util.HashSet; import java.util.Iterator; import java.util.Random; public class TestHashSet { public static void main(String[] args) { Random r = new Random(); HashSet hs1 = new HashSet(); for(int i=0; i<3000; i++){ hs1.add(r.nextInt(10)); } Iterator it1 = hs1.iterator(); while(it1.hasNext()){ System.out.print(it1.next()+" "); } } } //由于 HashSet 不能重复,所以只有10个数在里面,按哈希排序 2 4 9 8 6 1 3 7 5 0 /* * 测试TreeSet 的比较器, * 在有自己的比较器的情况下,如何实现Comparable接口 */ import java.util.*; class Teacher{ int id; String name; int age; public Teacher() {} public Teacher(int id, String name, int age) { this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) {this.id = id; } public String getName() { return name;} public void setName(String name) { this.name = name;} public int getAge() {return age;} public void setAge(int age) {this.age = age;} public int TeacherComparator(Object o){ Teacher t1 = (Teacher) o; if(t1.getId() > id){return 1;} else if (t1.getId() < id){return -1;} return 0; } } class TreeSet{ } class Test { public static void main(String[] args) { String s1 = new String("aaa"); String s2 = new String("bbb"); String s3 = new String("aaa"); System.out.println(s1==s3); System.out.println(s1.equals(s3)); HashSet hs = new HashSet(); hs.add(s1); hs.add(s2); hs.add(s3); Iterator it = hs.iterator(); while(it.hasNext()){ System.out.println(it.next()); } System.out.printf("%x\n",s1.hashCode()); System.out.printf("%x\n",s2.hashCode()); System.out.printf("%x\n",s3.hashCode()); } } 1. 在Map中,以name作Key,以Student类 作Velue,写一个HashMap import java.util.*; class Student{ int id; String name; int age; public Student() {} public Student( int id, String name, int age) { this.id = id; this.name = name; this.age = age; } public int getId() {return id;} public void setId(int id) {this.id = id;} public String getName() {return name;} public void setName(String name) {this.name = name;} public int getAge() {return age;} public void setAge(int age) {this.age = age;} } class TestHashMap{ public static void main(String[] args) { HashMap hm = new HashMap(); Student s1 = new Student(1,"jacky",19); hm.put("jacky",s1); hm.put("tom",new Student(2,"tom",21)); hm.put("kitty",new Student(3,"kitty",17)); Iterator it = hm.keySet().iterator(); while(it.hasNext()){ Object key = it.next(); Student value = (Student) hm.get(key); System.out.println(key+":id="+value.id+",age="+value.age); } System.out.println("============================="); //比较 KeySet() 和 entrySet() 两种迭代方式 for(Iterator i1 = hm.entrySet().iterator(); i1.hasNext(); ) { Map.Entry me = (Map.Entry) i1.next(); Student s = (Student) me.getValue(); System.out.println(me.getKey()+": id="+s.id+" age="+s.age); } } } day13 homework 1. /********************************************************************************** 自己写一个栈: ( 先进后出 ) 建议底层用LinkedList实现 参照 java.util.Stack 方法: boolean empty() 测试堆栈是否为空。 E peek() 查看栈顶对象而不移除它。 E pop() 移除栈顶对象并作为此函数的值返回该对象。 E push(E item) 把项压入栈顶。 int search(Object o) 返回对象在栈中的位置,以 1 为基数。 ***************************************************************************************/ //不能用继承,因为它破坏封装。只需调用即可 import java.util.LinkedList; class MyStack<E>{ private LinkedList<E> list = new LinkedList<E>(); public boolean empty() {return list.isEmpty();} public E peek() {return list.peek(); } public E pop() {return list.poll(); } public void push(E o) {list.addFirst(o); } //int indexOf(Object o) 返回此列表中首次出现的指定元素的索引,如果此列表中不包含该元素,则返回 -1。 public int search(Object o){return list.indexOf(o);} } 2. /*************************************************************************************** 定义以下类,完成后面的问题,并验证。 Exam类 考试类 属性: 若干学生 一张考卷 提示:学生采用HashSet存放 Paper类 考卷类 属性:若干试题 提示:试题采用HashMap存放,key为String,表示题号,value为试题对象 Student类 学生类 属性:姓名 一张答卷 一张考卷 考试成绩 Question类 试题类 属性:题号 题目描述 若干选项 正确答案 提示:若干选项用ArrayList AnswerSheet类 答卷类 属性:每道题的答案 提示:答卷中每道题的答案用HashMap存放,key为String,表示题号,value为学生的答案 问题:为Exam类添加一个方法,用来为所有学生判卷,并打印成绩排名(名次、姓名、成绩) ***************************************************************************************/ 3. /*************************************************************************************** 项目:商品管理系统 功能:增删改查 (可按各种属性查) 商品属性:名称、价格(两位小数)、种类 ***************************************************************************************/ day17 图形界面 1. 计算器 /*****************例题 画出计算器的界面***************************** 界面如下: 1 2 3 + 4 5 6 - 7 8 9 * 0 . = / *******************/ import java.awt.*; import javax.swing.*; class Calculator { public static void main(String[] args){ JTextField text = new JTextField(); JFrame f = new JFrame("计算器"); Font font = new Font("宋体", Font.BOLD, 25);//"宋体"想写成默认,则写“null” text.setFont(font); //定义字体 text.setHorizontalAlignment(JTextField.RIGHT);//令text的文字从右边起 text.setEditable(false);//设置文本不可修改,默认可修改(true) f.add(text, BorderLayout.NORTH);//Frame和Dialog的默认布局管理器是Border Layout ButtonActionListener listener = new ButtonActionListener(text);//事件反应在text中 JPanel buttonPanel = new JPanel();//设法把计算器键盘放到这个Jpanel按钮上 String op = "123+456-789*0.=/"; GridLayout gridlayout = new GridLayout(4,4,10,10); buttonPanel.setLayout(gridlayout);//把计算器键盘放到buttonPanel按钮上 for(int i=0; i<op.length(); i++){ char c = op.charAt(i); //拿到字符串的第i个字符 JButton b = new JButton(c+"");//把字符放到按钮上 b.addActionListener(listener);//在按钮上放置监听器,每次按都会有反应 buttonPanel.add(b);//把按钮放到buttonPanel上 }//这个循环很值得学习,很常用 f.add(buttonPanel/*, BorderLayout.CENTER*/); //默认添加到CENTER位置 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(300, 250); f.setVisible(true);//这句要放到最后,等事件完成后再显示 }} //监听者 class ButtonActionListener implements ActionListener{ private JTextField textField; public ButtonActionListener(JTextField textField) { this.textField = textField; } public void actionPerformed(ActionEvent e) {//必须覆盖它的actionPerformed() textField.append("哈哈,放了几个字\n"); }} /*********************未实现计算器的具体功能*******************************/ 2. 扫雷游戏 3. 俄罗斯方块 day19 多线程 写两个线程,一个线程打印 1~52,另一个线程打印字母A-Z。打印顺序为12A34B56C……5152Z。要求用线程间的通信。 注:分别给两个对象构造一个对象o,数字每打印两个或字母每打印一个就执行o.wait()。 在o.wait()之前不要忘了写o.notify()。 class Test{ public static void main(String[] args) { Printer p = new Printer(); Thread t1 = new NumberPrinter(p); Thread t2 = new LetterPrinter(p); t1.start(); t2.start(); } } class Printer{ private int index = 1;//设为1,方便计算3的倍数 //打印数字的构造方法,每打印两个数字,等待打印一个字母 public synchronized void print(int i){ while(index%3==0){try{wait();}catch(Exception e){}} System.out.print(" "+i); index++; notifyAll(); } //打印字母,每打印一个字母,等待打印两个数字 public synchronized void print(char c){ while(index%3!=0){try{wait();}catch(Exception e){}} System.out.print(" "+c); index++; notifyAll(); } } //打印数字的线程 class NumberPrinter extends Thread{ private Printer p; public NumberPrinter(Printer p){this.p = p;} public void run(){ for(int i = 1; i<=52; i++){ p.print(i); } } } //打印字母的线程 class LetterPrinter extends Thread{ private Printer p; public LetterPrinter(Printer p){this.p = p;} public void run(){ for(char c='A'; c<='Z'; c++){ p.print(c); } } } /*如果这题中,想保存需要打印的结果,可在Printer类里定义一个成员变量 String s = ""; //不写“”的话是null,null跟没有东西是不一样的,它会把null当成字符 =_= 然后在两个print()方法里面,while循环后分别加上 s = s + " "+i; 以及 s = s +" "+ c;*/

2010-02-10

2009达内SQL学习笔记

先登陆服务器: telnet 192.168.0.23 公帐号: openlab-open123 tarena-tarena 再进入SQL:sqlplus sd0807/sd0807 帐号:sd0807-密码同样 公帐号:openlab-open123 设置环境变量: ORACLE_SID=oral10g\ --变局部变量 export ORACLE_SID --变全局变量 unset ORACLE_SID --卸载环境变量 ORACLE_HOME=... --安装路径;直接用一句语句也可以,如下 export ORACLE_HOME=/oracledata/.../bin: 一、注意事项: 大小写不敏感,即不区分大小写。提倡关键字大写,便于阅读和调式。 “!”在SQL环境下执行Unix命令。 SQL语句是由简单的英语单词构成;这些英语单词称为关键字/保留字,不做它用。SQL由多个关键字构成。 SQL语句由子句构成,有些子句是必须的,有些是可选的。 在处理SQL语句时,其中所有的空格都被忽略(空格只用来分开单词,连续多个空格当一个用)。 SQL语句可以在一行上写出,建议多行写出,便于阅读和调试。 多条SQL语句必须以分号分隔。多数DBMS不需要在单条SQL语句后加分号,但特定的DBMS可能必须在单条SQL语句后加分号。 SQL语句的最后一句要以 “;”号结束 二、写子句顺序 Select column,group_function From table [Where condition] [Group by group_by_expression] [Having group_condition] …… [Order by column]; --最后 三、常用简单语句: clear screen:清屏 edit:编辑刚才的一句。 desc/describe:(列出所有列名称) 用法: DESCRIBE [schema.]object[@db_link] dual:亚表,临时用。如:desc dual;/from dual; rollback:回溯,回溯到上次操作前的状态,把这次事务操作作废,只有一次(DDL和DCL语句会自动提交,不能回溯)。 可以用commit语句提交,这样就回溯不回了。 set pause on\off :设置分屏(设置不分屏) set pause "please put an enter key" 且 set pause on:设置带有提示的分屏 oerr ora 904 :查看错误 set head off :去掉表头 set feed off :去掉表尾 保存在oracle数据库中的所有操作细节: spool oracleday01.txt :开始记录 spool off :开始保存细节 四、SELECT语句:选择操作、投影操作。 select:从一个或多个表中检索一个或多个数据列。包含信息:想选择什么表,从什么地方选择。必须要有From子句。(最常用) 当从多张表里查询的时候,会产生笛卡尔积;可用条件过滤它。 当两个表有相同字段时必须加前缀,列名前需加表名和“.”,如“s_emp.id”。 1、用法:SELECT columns,prod2,prod3<列> FROM Table1,table2<表名> 分号结束 如: select id from s_emp; select last_name,name from s_emp,s_dept where s_emp.dept_id=s_dept.id;--列表每人所在部门 SELECT * FROM Products; --检索所有列。 数据太多时,最好别使用上句,会使DBMS降低检索和应用程序的性能。(*通配符) 2、对数据类型的列可进行运算(如加减乘除)。 3、对列起别名:有直接起别名,加AS起别名,用双引号起别名等三种方法 (单引号,引起字符串;双引号,引起别名。起别名有符号,或者区分大小写时,必须用双引号) 多表查询时,可给表起别名。(给列起别名,列<空格>列别名;给表起别名,表<空格>表别名;)。 如:Select first_name EMPLOYEES, 12*(salary+100) AS MONEY, manager_id "ID1" From s_emp E; 4、字段的拼接,可用双竖线(双竖线只能用于select语句里)。不同的DBMS可能使用不同的操作符;拼接的字段同样可以起别名。 如:Select first_name ||' '|| last_name || ', '|| title "Employees" From s_emp; 排他锁:Select id,salary From s_emp where id=1 For Update; 可以阻止他人并发的修改,直到你解锁。 如果已有锁则自动退出:Select id,salary From s_emp where id=1 For Update NoWait; FOR UPDATE :可以再加 OF 精确到某格。如: ... For Update OF salary ... 注意要解锁。 五、ORDER BY 子句,排序 Order by:按某排序列表(默认升序 asc,由低到高;可加 desc,改成降序由高到低) 检索返回数据的顺序没有特殊意义,为了明确地排序用 SELECT 语句检索出的数据,可使用 ORDER BY 子句。 ORDER BY 子句取一个或多个列的名字。 对空值,按无穷大处理(升序中,空值排最后;降序中排最前)。 1、用法:Select prod_id,prod_price,prod_name From Products Order By prod_price,prod_name; (从左到右执行排序,先排price) ORDER BY子句中使用的列将是为显示所选择的列,但是实际上并不一定要这样,用非检索的列排序数据是完全合法的。 为了按多个列排序,列名之间用逗号分开。 2、支持按相对列位置进行排序。 输入 SELECT prod_id,prod_price,prod_name FROM Products ORDER BY 2,3 --(2指price,3指name) 3、升序、降序。默认是升序(asc,从小到大排序),想降序时用desc。 如:SELECT prod_id,prod_price,prod_name FROM Products ORDER BY prod_price DESC; 注意:DESC 关键字只应用到直接位于其前面的列名。如果想在多个列上进行排序,必须对每个列指定DESC关键字。 升序是默认的,可不写,但降序必须写。 六、WHERE子句,选择、过滤 其后只能跟逻辑语句,返回值只有ture或false 如: select last_name,salary from s_emp where salary=1000;--找出工资1000的人 WHERE子句操作符: 1、逻辑比较运算符 = 等于 != 不等于,还有(<> ^= 这两个同样表示不等于) > 大于 >= 大于等于 < 小于 <= 小于等于 2、SQL 比较运算符 between…and… :在两者之间。(BETWEEN 小值 AND 大值) 如:select last_name,salary from s_emp where salary between 1000 and 1500; --工资1000到1500的人,包括1000和1500。 in(列表):在列表里面的。 如:select last_name,dept_id from s_emp where dept_id in(41,42);第41、42部门的人 like : 包含某内容的。模糊查询 可以利用通配符创建比较特定数据的搜索模式,通配符只能用于文本,非文本数据类型不能使用通配符。 通配符在搜索模式中任意位置使用,并且可以使用多个通配符。 通配符%表示任何字符出现任意次数;还能代表搜索模式中给定位置的0个或多个字符。下划线匹配单个任意字符。 如:select table_name from user_tables where table_name like 'S\_%' escape'\'; ' 找出“S_“开头的,由于下划线有任意字符的含义,故需另外定义转移符。 但习惯用“\”,为方便其他程序员阅读和检测,一般不改用其他的。 like 'M%':M开头的 like '_a%':第二个字符是a的 like '%a%'所有含a的 (“_”表示一个任意字符;“%”表示任意多个任意字符。) 单引号里面的内容,大小写敏感。单引号用来限定字符串, 如果将值与串类型的列进行比较,则需要限定引号;用来与数值列进行比较时,不用引号。 is null:是空。(NULL表示不包含值。与空格、0是不同的。) 如:SELECT prod_name,prod_price FROM Products WHERE prod_price IS NULL; 七、高级检索(逻辑运算符): 通常我们需要根据多个条件检索数据。可以使用AND或OR、NOT等连接相关的条件 计算次序可以通过圆括号()来明确地分组。不要过分依赖默认计算次序,使用圆括号()没有坏处,它能消除二义性。 and:条件与 如 SELECT prod_id,prod_price,prod_name FROM Products WHERE prod_price<4 AND vend_id=‘DELL’ or:条件或 (注: and 的优先级比 or 更高,改变优先级可用括号) 如 SELECT prod_id,prod_price,prod_name FROM Products WHERE prod_price<4 OR vend_id=‘DELL’ not:条件非。否定它之后所跟的任何条件 否定的SQL 比较运算符: NOT BETWEEN; NOT IN; NOT LIKE; IS NOT NULL: (注意,按英语习惯用 is not,而不是 not is) NOT 与 IN 在一起使用时,NOT 是找出与条件列表不匹配的行。 IN 列表里有 NULL 时不处理,不影响结果;用 NOT IN 时,有 NULL 则出错,必须排除空值再运算。 in :选择列表的条件 使用IN操作符的优点: 在长的选项清单时,语法直观; 计算的次序容易管理; 比 OR 操作符清单执行更快;最大优点是可以包含其他 SELECT 语句,使用能够动态地建立 WHERE 子句。 如 SELECT prod_id,prod_price,prod_name FROM Products WHERE vend_id IN(‘DELL’,’RBER’,’TTSR’); 八、单行函数: 函数一般在数据上执行,它给数据的转换和处理提供了方便。不同的DBMS提供的函数不同。 函数可能会带来系统的不可移植性(可移植性:所编写的代码可以在多个系统上运行)。 加入注释是一个使用函数的好习惯。 大多数SQL实现支持以下类型的函数: 文本处理, 算术运算, 日期和时间, 数值处理。 Null:空值 空值当成无穷大处理,所有空值参与的运算皆为空。 空值与空值并不相等,因为空值不能直接运算。 如:prod_price="" 这种写法是错的(不要受到corejava的影响) prod_price=NULL 这种写法是错的(不要受到corejava的影响) prod_price IS NULL 这种写法才是对的 NVL:处理空值,把空值转化为指定值。可转化为日期、字符、数值等三种(注意:转化时,两参数必须要同类型) 如:NVL(date, '01-JAN-95') NVL(title,'NO Title Yet') NVL(salary,0) 错误写法: Select last_name,title,salary*commission_pct/100 COMM From s_emp;--没提成的人没法显示工资 正确写法: Select last_name,title,salary*NVL(commission_pct,0)/100 COMM From s_emp;--把提成是空值的转化为0 DISTINCT:过滤重复 把重复的行过滤掉;多个字段组合时,只排除组合重复的。 DISTINCT必须使用列名,不能使用计算或者表达式。 所有的聚合函数都可以使用。如果指定列名,则DISTINCT只能用于COUNT(列名),DISTINCT不能用于COUNT(*)。 如:Select Distinct name From s_dept; Select Distinct dept_id,title From s_emp; 文本处理: TRIM()/LTRIM()/RTIRM():去空格。只能去掉头和尾的空格,中间的不理。 trim(' heo Are fdou ') --> heo Are fdou 输入:select trim(' heo Are fdou ') from dual; -->:heo Are fdou LOWER:转小写 lower('SQL Course') --> sql course UPPER:转大写 upper(' SQL Course') --->SQL COURSE INITCAP:首字母转大写,其余转小写 initcap(SQL Course') '--> Sql Course CONCAT:合成。双竖线只能在select语句里面用,这个可用于任何语句。 Concat('Good','String') --> GoodString SUBSTR:截取。 Substr('String', 1 ,3) --> Str 第一个数字“1”,表示从第几个开始截取;若要从倒数第几个开始,用负数,如“-2”表示倒数第2个。 上式中第2个数字“3”表示截取多少个。 LENGTH:统计长度。 Length('String') --> 6 NVL:转换空值 日期和时间处理: Oracle日期格式:DD-MMM-YYYY (D代表日期date,M代表月month,Y代表年year) 如:SELECT prod_name (DAY表示完整的星期几,DY显示星期的前三个字母) FROM Products WHERE prod_time BETWEEN to_date(’01-JAN-2008’) AND to_date(’31-DEC-2008’); 日期可以进行加减,默认单位是1天。日期与日期可以相减,得出天数;日期与日期但不能相加。 sysdate -> 系统的当天 Months_Between('01-Sep-95','11-Jan-94') --> 19.774194 相差多少个月,Between里面也可以填函数。 Add_months('11-Jan-94',6) --> 11-Jul-94 增加多少个月 Next_day('01-Sep-95','Friday') --> '08-Sep-95' 下一个星期五。其中的'Friday'可用6替代,因为星期日=1 Last_day('01-Sep-95') --> '30-Sep-95' 这个月的最后一天 数值处理:可以运用于代数,三角,几何 ROUND:四舍五入 Round(45.925,2) -> 45.93 Round(45.925,0) -> 46 Round(45.925,-1) -> 50 逗号前一个数是要处理的数据源,后一个参数表示保留多少位小数。 后一参数是负数时,表示舍去小数点前的几位,例3是舍去个位及其后的。不写后一参数时,默认不保留小数。 TRUNC:舍去末位。直接舍去,不会进位。 Trung(45.925,2) -> 45.92 Trung(45.925,2) -> 45.92 Trung(45.925,2) -> 45.92 日期的舍取: 常用的数值处理函数有: ABS() 绝对值 ABS(-5741.5854) --> 5741.5854 PI() 圆周率 注意:oracle中不支持 PI()函数;MYSql 支持PI()函数。 SIN() 正统值 Oracle还支持COS()、ASIN()、ACOS()函数 SQRT() 平方根 转化: TO_CHAR(number,'fmt'):把数值转换成字符串 显示数字的命令 9:正常显示数字; 0:显示包括0的数值形式,空位强制补0; $:以美元符号显示货币; L:按当前环境显示相关的货币符号; . 和,:在固定位置出现“.”点 和“,”逗号;不够位时,四舍五入。 例题:SQL> select 'Order'||To_char(id)|| 2 'was filled for a total of' 3 ||To_char(total,'fm$9,999,999') 4 from s_ord 5 where ship_date ='21-SEP-92'; TO_NUMBER(char):把字符转换成数字 九、链接 内链接:严格匹配两表的记录。 外链接分左链接和右链接: 会使用一方表中的所有记录去和另一格表中的记录按条件匹配,空值也会匹配,这个表中的所有记录都会显示, 数据库会模拟出记录去和那些不匹配的记录匹配。 左链接 加号在右面 如:有 TABLE1 TABLE2 1的一条记录在2里面没有匹配上,那么1里面的记录保留 2的一条记录在1里面没有匹配上 ,那么2丢弃 右链接正好相反 --例题:哪些人是领导。 select distinct b.id,b.last_name manager from s_emp a,s_emp b where a.manager_id=b.id(+); 左右顺序有区别,这是另外新建一个表,要显示的是第二个表格的内容。 +放在没有匹配行的表一侧,令表格能完整显示出来。 标准写法:内连接用INNER,左连接用LEFT,右连接用RIGHT。 select distinct b.id,b.last_name manager from s_emp a LEFT join s_emp b ON a.manager_id=b.id; 十、组函数: 分组允许将数据分为多个逻辑组,以便能对每个组进行聚集计算。 Group:分组 Group by:分组。(默认按升序对所分的组排序;想要降序要用 order by)可以包括任意数目的列。 如果嵌入了分组,数据将在最后规定的分组上进行汇总。 GROUP BY 子句中列出的每个列都必须是检索列或有效的表达式,但不能是聚集函数。 *如果在SELECT 中使用表达式,则必须在GROUP BY子句中指定相同的表达式,不能使用别名。 除聚合计算语句外,SELECT语句中的每个列都必须在GROUP BY子句中给出。 如果分组列中具有NULL值,则NULL将作为一个分组返回。如果列中有多行NULL,它们将分为一组。 Having:过滤。分组之后,不能再用where,要用having 选择过滤。Having不能单独存在,必须跟在group by后面。 WHERE在数据分组前进行过滤,HAVING在数据分组后过滤。 可以在SQL中同时使用 WHERE和HAVING,先执行WHERE,再执行HAVING。 聚合函数: AVG:平均值 (忽略值为NULL的行,但不能用 AVG(*)) COUNT:计数 (Count(列)不计算空值;但 COUNT(*)表示统计表中所有行数,包含空值) MAX:最大值 (忽略列值为 NULL 的行。但有些DBMS还允许返回文本列中的最大值, 在作用于文本数据时,如果数据按照相应的列排序,则 MAX()返回最后一行。) MIN:最小值 (忽略值为 NULL 的行。不能用 MIN(*)。一般是找出数值或者日期值的最小值。 但有些DBMS还允许返回文本列中的最小值,这时返回文本最前一行) SUM:求和 (忽略值为 NULL 的值。SUM 不能作用于字符串类型,而 MAX(),MIN()函数能。也不能 SUM(*)) 子查询:查询语句的嵌套 可以用于任意select 语句里面,但子查询不能出现 order by。 子查询总是从内向外处理。作为子查询的SELECT 语句只能查询单个列,企图检索多个列,将会错误。 如:找出工资最低的人select min(last_name),min(salary) from s_emp; 或者用子查询select last_name,salary from s_emp where salary=(select min(salary) from s_emp); E-R图:属性: E(Entity) -R(Relationship) * (Mandatory marked 强制的) 强制的非空属性 o (Optional marked 可选的) 可选属性(可以有值也可以没有) #* (Primary marked ) 表示此属性唯一且非空 约束:针对表中的字段进行定义的。 PK:primary key (主键约束,PK=UK+NN)保证实体的完整性,保证记录的唯一 主键约束,唯一且非空,并且每一个表中只能有一个主键,有两个字段联合作为主键, 只有两个字段放在一起唯一标识记录,叫做联合主键(Composite Primary Key)。 FK:foreign key (外建约束)保证引用的完整性,外键约束,外键的取值是受另外一张表中的主键或唯一值的约束,不能够取其他值, 只能够引用主键会唯一键的值,被引用的表,叫做parent table(父表),引用方的表叫做child table(子表); child table(子表),要想创建子表,就要先创建父表,后创建子表,记录的插入也是如此,先父表后子表, 删除记录,要先删除子表记录,后删除父表记录, 要修改记录,如果要修改父表的记录要保证没有被子表引用。要删表时,要先删子表,后删除父表。 U:unique key(唯一键 UK),值为唯一,不能重复。 在有唯一性约束的列,可以有多个空值,因为空值不相等。 NN:NOT NULL,不能为空。 index(索引)是数据库特有的一类对象,实际应用中一定要考虑索引,view(示图) 数量关系: 一对一关系 多对一关系 一对多关系 多对多关系 范式: 好处:降低数据冗余;减少完整性问题;标识实体,关系和表 第一范式(First normal form:1Nf),每一个属性说一件事情。所有的属性都必须是单值,也就是属性只表示单一的意义。 (记录可以重复,会有大量冗余,没有任何限制) 第二范式(2N范式),最少有一个属性要求唯一且非空PK,其他跟他有关联(记录不可重复,但是数据可能会出现冗余)。 第三范式(3N范式),非主属性只能依赖于主属性,不能依赖于其他非主属性。(解决数据冗余问题,不能存在推理能得出的数据) 一般情况会做到第三范式。 创建表: Create Table 表名 (字段名1 类型(数据长度)(default ...) 约束条件, 字段名2 类型(数据长度) 约束条件 ); 建表的名称: 必须字母开头;最多30字符;只能使用“A~Z、a~z、0~9、_、$、#”; 同一目录下不能有同名的表;表名不能跟关键字、特殊含意字符同样。 如:create table number_1 (n1 number(2,4), n2 number(3,-1), n3 number); create table t_sd0808(id number(12) primary key,name varchar(30) not null); MySQL的: create table student (oid int primary key, ACTNO varchar(20) not null unique, BALANCE double); --MySQL的number类型分小类了,Oracle只有number,且MySQL的数值型不用定大小 Oracle的: create table t_ad (oid number(15) primary key, ACTNO varchar(20) not null unique,BALANCE number(20)); INSERT:插入(或添加)行到数据库表中的关键字。 插入方式有以下几种:插入完整的行;插入行的一部分;插入某些查询的结果。 对于INSERT操作,可能需要客户机/服务器的DBMS中的特定的安全权限。 插入行(方式一) INSERT INTO products VALUES(2008,’TV’,222.22,’US’); 依赖于表中定义的顺序,不提倡使用。有空值时需要自己补上。 插入行(方式二) INSERT INTO products(id,name,price,vend_name) VALUES(2008,’TV’,222.22,’US’); 依赖于逻辑顺序,会自动补上空值,提倡使用。 插入检索出的数据:可以插入多条行到数据库表中 INSERT INTO products(*,*,*,*) SELECT *,*,*,* FROM products_copy; 如果这个表为空,则没有行被插入,不会产生错误,因为操作是合法的。 可以使用WHERE加以行过滤。 复制表: 将一个表的内容复制到一个全新的表(在运行中创建,开始可以不存在) CREATE TABLE 新表名 AS SELECT * FROM 表名; INSERT INTO 与 CREATE TABLE AS SELECT 不同,前者是导入数据,而后者是导入表。 任何SELECT选项和子句都可以使用,包括WHERE和GROUP BY。 可利用联接从多个表插入数据。不管从多少个表中检索数据,数据都只能插入到单个表中。 更新数据 UPDATE 语句 需要提供以下信息:要更新的表;列名和新值;确定要更新的哪些行的过滤条件。 UPDATE 表名 SET vend_name = ‘HP’, prod_name = ‘NEWCOMPUTER’ WHERE vend_name = ‘IBM’; --UPDATE 语句中可以使用子查询,使得能用SELECT语句检索出的数据更新列数据。也可以将一个列值更新为 NULL。 删除数据 DELETE 语句 DELETE FROM products WHERE prod_name = ‘COMPUTER’; 全行删除,不要省略WHERE,注意安全。 DELETE不需要列名或通配符。删除整行而不是删除列。DELETE是删除表的内容而不是删除表。 如果想从表中删除所有内容,可以使用TRUNCATE TABLE语句(清空表格),它更快。 数字字典表: Sequence:排列。存储物理地址 Index:索引。依附于表,为提高检索速度。 View:视图。看到表的一部分数据。 限制数据访问。简化查询。数据独立性。本质上是一个sql查询语句。 Create[or Relace][Force|noForce] View 视图名 [(alias[,alias]…)] 别名列表 As subquery [With Check Option [Constraint ……]] [With Read Only] 注意:有些DBMS不允许分组或排序视图,不能有 Order by 语句。可以有 Select 语句。 删除视图: DROP VIEW 视图名 Rownum:纬列。内存里排序的前N个。 在where语句中,可以用=1,和<=N 或 <N;但不能用=N 或 >N。 因为这是内存读取,没有1就丢弃再新建1。只能从1开始。需要从中间开始时,需二重子rownum语句需取别名。 经典应用: Top-n Analysis (求前N名或最后N名) Select [查询列表], Rownum From (Select [查询列表(要对应)] From 表 Order by Top-N_字段) Where Rownum <= N 分页显示: --取工资第5~10名的员工(二重子rownum语句,取别名) select rn,id,last_name,salary From ( select id,last_name,salary,Rownum rn From (Select id,last_name,salary from s_emp order by salary desc) where rownum <= 10) where rn between 5 and 10; Union:合并表 Select … Union Select… 把两个Select语句的表合并。 要求两表的字段数目和类型按顺序对应。合并后的表,自动过滤重复的行。 Intersect:交。 同上例,把两个Select表相交。 Minus:减。 把相交的内容减去。 not exists 除运算。 添加字段(列): Alter Table 表名 Add (column dataype [Default expr][Not Null] [,column datatype]…); 添加有非空限制的字段时,要加Default语句 字段名字不可以直接改名,需要添加新字段,再复制旧字段后删除旧字段。 添加约束: Alter Table 表名 Add [CONSTRAINT constraint] type (column); 添加非空约束时,要用Modify语句。 查看约束名时,可以违反约束再看出错提示;或者查看约束字典desc user_constraints 减少字段: Alter Table 表名 Drop (column [,column]…); 删除约束: Alter Table 表名 Drop CONSTRAINT column; 或: Alter Table 表名 Drop Primary Key Cascade; 暂时关闭约束,并非删除: Alter Table 表名 Disable CONSTRAINT column Cascade; 打开刚才关闭的约束: Alter Table 表名 Enable CONSTRAINTcolumn; 修改字段: Alter Table 表名 Modify (column dataype [Default expr][Not Null] [,column datatype]…); 修改字段的类型、大小、约束、非空限制、空值转换。 删除表: 会删除表的所有数据,所有索引也会删除,约束条件也删除,不可以roll back恢复。 Drop Table 表名 [Cascade Constraints]; 加 [Cascade Constraints] 把子表的约束条件也删除;但只加 [Cascade]会把子表也删除。 改表名: Rename 原表名 To 新表名; 清空表格: TRUNCATE TABLE 表名; 相比Delete,Truncate Table清空很快,但不可恢复。清空后释放内存。 Delete 删除后可以roll back。清空后不释放内存。

2010-02-10

2009 达内Unix学习笔记

集合了 所有的 Unix命令大全 登陆服务器时输入 公帐号 openlab-open123 telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss 老师测评网址 http://172.16.0.198:8080/poll/ 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ 一、注意事项 命令和参数之间必需用空格隔开,参数和参数之间也必需用空格隔开。 一行不能超过256个字符;大小写有区分。 二、特殊字符含义 文件名以“.”开头的都是隐藏文件/目录,只需在文件/目录名前加“.”就可隐藏它。 ~/ 表示主目录。 ./ 当前目录(一个点)。 ../ 上一级目录(两个点)。 ; 多个命令一起用。 > >> 输出重定向 。将一个命令的输出内容写入到一个文件里面。如果该文件存在, 就将该文件的内容覆盖; 如果不存在就先创建该文件, 然后再写入内容。 输出重定向,意思就是说,将原来屏幕输出变为文件输出,即将内容输到文件中。 < << 输入重定向。 本来命令是通过键盘得到输入的,但是用小于号,就能够使命令从文件中得到输入。 \ 表示未写完,回车换行再继续。 * 匹配零个或者多个字符。 ? 匹配一个字符。 [] 匹配中括号里的内容[a-z][A-Z][0-9]。 ! 事件。 $ 取环境变量的值。 | 管道。把前一命令的输出作为后一命令的输入,把几个命令连接起来。 |经常跟tee连用,tee 把内容保存到文档并显示出来。 三、通用后接命令符 -a 所有(all)。 -e 所有(every),比a更详细。 -f 取消保护。 -i 添加提示。 -p 强制执行。 -r 目录管理。 分屏显示的中途操作 空格<space> 继续打开下一屏; 回车<return> 继续打开下一行; b 另外开上一屏; f 另外开下一屏; h 帮助; q或Ctrl+C 退出; /字符串 从上往下查找匹配的字符串; ?字符串 从下往上查找匹配的字符串; n 继续查找。 四、退出命令 exit 退出; DOS内部命令 用于退出当前的命令处理器(COMMAND.COM) 恢复前一个命令处理器。 Ctrl+d 跟exit一样效果,表中止本次操作。 logout 当csh时可用来退出,其他shell不可用。 clear 清屏,清除(之前的内容并未删除,只是没看到,拉回上面可以看回)。 五、目录管理命令 pwd 显示当前所在目录,打印当前目录的绝对路径。 cd 进入某目录,DOS内部命令 显示或改变当前目录。 cd回车/cd ~ 都是回到自己的主目录。 cd . 当前目录(空格再加一个点)。 cd .. 回到上一级目录(空格再加两个点)。 cd ../.. 向上两级。 cd /user/s0807 从绝对路径去到某目录。 cd ~/s0807 直接进入主目录下的某目录(“cd ~"相当于主目录的路径的简写)。 ls 显示当前目录的所有目录和文件。 用法 ls [-aAbcCdeEfFghHilLmnopqrRstux1@] [file...] ls /etc/ 显示某目录下的所有文件和目录,如etc目录下的。 ls -l (list)列表显示文件(默认按文件名排序), 显示文件的权限、硬链接数(即包含文件数,普通文件是1,目录1+)、用户、组名、大小、修改日期、文件名。 ls -t (time)按修改时间排序,显示目录和文件。 ls -lt 是“-l”和“-t”的组合,按时间顺序显示列表。 ls -F 显示文件类型,目录“/ ”结尾;可执行文件“*”结尾;文本文件(none),没有结尾。 ls -R 递归显示目录结构。即该目录下的文件和各个副目录下的文件都一一显示。 ls -a 显示所有文件,包括隐藏文件。 文件权限 r 读权限。对普通文件来说,是读取该文件的权限;对目录来说,是获得该目录下的文件信息。 w 写权限。对文件,是修改;对目录,是增删文件与子目录。 (注 删除没有写权限的文件可以用 rm -f ,这是为了操作方便,是人性化的设计)。 x 执行权限;对目录,是进入该目录 - 表示没有权限 形式 - rw- r-- r-- 其中 第一个是文件类型(-表普通文件,d表目录,l表软链接文件) 第2~4个是属主,生成文件时登录的人,权限最高,用u表示 第5~7个是属组,系统管理员分配的同组的一个或几个人,用g表示 第8~10个是其他人,除属组外的人,用o表示 所有人,包括属主、属组及其他人,用a表示 chmod 更改权限; 用法 chmod [-fR] <绝对模式> 文件 ... chmod [-fR] <符号模式列表> 文件 ... 其中 <符号模式列表> 是一个用逗号分隔的表 [ugoa]{+|-|=}[rwxXlstugo] chmod u+rw 给用户加权限。同理,u-rw也可以减权限。 chmod u=rw 给用户赋权限。与加权限不一样,赋权限有覆盖的效果。 主要形式有如下几种 chmod u+rw chmod u=rw chmod u+r, u+w chmod u+rw,g+w, o+r chmod 777( 用数字的方式设置权限是最常用的) 数字表示权限时,各数位分别表示属主、属组及其他人; 其中,1是执行权(Execute),2是写权限(Write),4是读权限(Read), 具体权限相当于三种权限的数相加,如7=1+2+4,即拥有读写和执行权。 另外,临时文件/目录的权限为rwt,可写却不可删,关机后自动删除;建临时目录:chmod 777 目录名,再chmod +t 目录名。 id 显示用户有效的uid(用户字)和gid(组名) 用法 id [-ap] [user] id 显示自己的。 id root 显示root的。 id -a root 显示用户所在组的所有组名(如root用户,是所有组的组员) df 查看文件系统,查看数据区 用法 df [-F FSType] [-abeghklntVvZ] [-o FSType 特定选项] [目录 | 块设备 | 资源] df -k 以kbytes显示文件大小的查看文件系统方式 六、显示文件内容 more 分屏显示文件的内容。 用法 more [-cdflrsuw] [-行] [+行号] [+/模式] [文件名 ...]。 显示7个信息:用户名 密码 用户id(uid) 组id(gid) 描述信息(一般为空) 用户主目录 login shell(登录shell) cat 显示文件内容,不分屏(一般用在小文件,大文件显示不下);合并文件,仅在屏幕上合并,并不改变原文件。 用法 cat [ -usvtebn ] [-|文件] ... tail 实时监控文件,一般用在日志文件,可以只看其中的几行。 用法 tail [+/-[n][lbc][f]] [文件] tail [+/-[n][l][r|f]] [文件] 七、文件/目录的增删 echo 显示一行内容。 touch 如果文件/目录不存在,则创建新文件/目录;如果文件存在,那么就是更新该文件的最后访问时间, 用法 touch [-acm] [-r ref_file] 文件... touch [-acm] [MMDDhhmm[yy]] 文件... touch [-acm] [-t [[CC]YY]MMDDhhmm[.SS]] file... mkdir 创建目录(必须有创建目录的权限) 用法 mkdir [-m 模式] [-p] dirname ... mkdir dir1/dir2 在dir1下建dir2 mkdir dir13 dir4 dir5 连建多个 mkdir ~/games 用户主目录下建(默认在当前目录下创建) mkdir -p dir6/dir7/dir8 强制创建dir8;若没有前面的目录,会自动创建dir6和dir7。 不用-p时,若没有dir6/dir7,则创建失败。 cp 复制文件/目录 cp 源文件 目标文件 复制文件;若已有文件则覆盖 cp -r 源目录 目标目录 复制目录;若已有目录则把源目录复制到目标目录下, 没有目标目录时,相当于完全复制源目录,只是文件名不同。 cp beans apple dir2 把beans、apple文件复制到dir2目录下 cp -i beans apple 增加是否覆盖的提示 mv 移动或重命名文件/目录 用法 mv [-f] [-i] f1 f2 mv [-f] [-i] f1 ... fn d1 mv [-f] [-i] d1 d2 mv 源文件名 目标文件名 若目标文件名还没有,则是源文件重命名为目标文件;若目标文件已存在,则源文件覆盖目标文件。 mv 源文件名 目标目录 移动文件 mv 源目录 目标目录 若目标目录不存在,则源目录重命名;若目标目录已存在,则源目录移动到目标目录下。 rm 删除文件/目录 用法 rm [-fiRr] 文件 ... rm 文件名 删除文件。 rm -r 目录名 删除目录。 rm –f 文件 只要是该文件或者目录的拥有者,无论是否有权限删除,都可以用这个命令参数强行删除。 rm -rf * 删除所有文件及目录 rmdir 删除空目录。只可以删除空目录。 ln 创建硬链接或软链接,硬链接=同一文件的多个名字;软链接=快捷方式 用法 ln [-f] [-n] [-s] f1 [f2] ln [-f] [-n] [-s] f1 ... fn d1 ln [-f] [-n] -s d1 d2 ln file1 file1.ln 创建硬链接。感觉是同一文件,删除一个,对另一个没有影响;须两个都删除才算删除。 ln -s file1 file1.sln 创建软链接。可跨系统操作,冲破操作权限;也是快捷方式。 八、时间显示 date 显示时间,精确到秒 用法 date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff] cal 显示日历 cal 9 2008 显示2008年9月的日历; cal 显示当月的 用法 cal [ [月] 年 ] 九、帮助 man 帮助( format and display the on-line manual pages) 用法 man [-] [-adFlrt] [-M 路径] [-T 宏软件包] [-s 段] 名称 ... man [-] [-adFlrt] [-M path] [-T macro-package] [-s section] name... man [-M 路径] -k 关键字 ... man [-M 路径] -f 文件 ... awk 按一定格式输出(pattern scanning and processing language) 用法 awk [-Fc] [-f 源代码 | 'cmds'] [文件] 十、vi 底行模式 /? 命令模式 i a o 输入模式 vi 的使用方法 1、光标 h 左 j 下 k 上 l 右 set nu 显示行号(set nonu) 21 光标停在指定行 21G 第N行 (G到文件尾,1G到文件头) 如果要将光标移动到文件第一行,那么就按 1G H 屏幕头 M 屏幕中间 L 屏幕底 ^ 或 shift+6 行首 $ 或 shift+4 行尾 Ctrl+f 下翻 Ctrl+b 上翻 2、输入 (输入模式) o 光标往下换一行 O (大写字母o)在光标所在行上插入一空行 i 在光标所在位置的前面插入字母 a 在光标所在位置的后面插入一个新字母 <Esc> 退出插入状态。 3、修改替换 r 替换一个字符 dd 删除行,剪切行 (5dd删除5行) 5,10d 删除 5 至 10 行(包括第 5行和第 10 行) x 删除一个字符 dw 删除词,剪切词。 ( 3dw删除 3 单词) cw 替换一个单词。 (cw 和 dw 的区别 cw 删除某一个单词后直接进入编辑模式,而dw删除词后仍处于命令模式) cc 替换一行 C 替换从光标到行尾 yy 复制行 (用法同下的 Y ,见下行) Y 将光标移动到要复制行位置,按yy。当你想粘贴的时候,请将光标移动到你想复制的位置的前一个位置,然后按 p yw 复制词 p 当前行下粘贴 1,2co3 复制行1,2在行3之后 4,5m6 移动行4,5在行6之后 u 当你的前一个命令操作是一个误操作的时候,那么可以按一下 u键,即可复原。只能撤销一次 r file2 在光标所在处插入另一个文件 ~ 将字母变成大写 J 可以将当前行与下一行连接起来 /字符串 从上往下找匹配的字符串 ?字符串 从下往上找匹配的字符串 n 继续查找 1,$s/旧串/新串/g 替换全文(或者 %s/旧串/新串/g) (1表示从第一行开始) 没有g则只替换一次,加g替换所有 3、存盘和退出 w 存盘 w newfile 存成新文件 wq 存盘再退出VI(或者ZZ或 X) q! 强行退出不存盘 查看用户 users 显示在线用户(仅显示用户名)。 who 显示在线用户,但比users更详细,包括用户名、终端号、登录时间、IP地址。 who am i 仅显示自己,(但包括用户名、端口、登录时间、IP地址;信息量=who)。 whoami 也仅显示自己,但只有用户名(仅显示自己的有效的用户名)。 w 显示比who更多内容,还包括闲置时间、占CPU、平均占用CPU、执行命令。 用法 w [ -hlsuw ] [ 用户 ] su 改变用户,需再输入密码。 用法 su [-] [ username [ arg ... ] ] su - 相当于退出再重新登录。 查找 find 查找文件 用法 find [-H | -L] 路径列表 谓词列表 find / -name perl 从根目录开始查找名为perl的文件。 find . -mtime 10 -print 从当前目录查找距离现在10天时修改的文件,显示在屏幕上。 (注 “10”表示第10天的时候;如果是“+10”表示10天以外的范围;“-10”表示10天以内的范围。) grep 文件中查找字符;有过滤功能,只列出想要的内容 用法 grep -hblcnsviw 模式 文件 . . . 如 grep abc /etc/passwd 在passwd文件下找abc字符 wc 统计 -l 统计行数; -w统计单词数; -c 统计字符数 如 grep wang /etc/passwd|wc -l 统计passwd文件含“wang”的行数 du 查看目录情况 如 du -sk * 不加-s会显示子目录,-k按千字节排序 用法 du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [文件...] 进程管理 ps 显示进程。 用法 ps [ -aAdeflcjLPyZ ] [ -o 格式 ] [ -t 项列表 ] [ -u 用户列表 ] [ -U 用户列表 ] [ -G 组列表 ] [ -p 进程列表 ] [ -g 程序组列表 ] [ -s 标识符列表 ] [ -z 区域列表 ] ps 显示自己的进程。 ps -e 显示每个进程,包括空闲进程。 ps -f 显示详情。 ps -ef 组合-e和-f,所有进程的详情。 ps -U uidlist(用户列表) 具体查看某人的进程。 kill pkill sleep jobs 用法 jobs [-l ] fg %n bg %n stop %n 挂起(仅csh能用) Ctrl+C Ctrl+Z 网络链接 ping usage ping host [timeout] usage ping -s [-l | U] [adLnRrv] [-A addr_family] [-c traffic_class] [-g gateway [-g gateway ...]] [-F flow_label] [-I interval] [-i interface] [-P tos] [-p port] [-t ttl] host [data_size] [npackets] ifconfig -a /sbin/ifconfig 查看本机的IP地址 netstat -rn rlogin ftp 帮助文件 [sd0807@localhost ~]$ help GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu) These shell commands are defined internally. Type `help' to see this list. Type `help name' to find out more about the function `name'. Use `info bash' to find out more about the shell in general. Use `man -k' or `info' to find out more about commands not in this list. A star (*) next to a name means that the command is disabled. JOB_SPEC [&] (( expression )) . filename [arguments] [ arg... ] [[ expression ]] alias [-p] [name[=value] ... ] bg [job_spec ...] bind [-lpvsPVS] [-m keymap] [-f fi break [n] builtin [shell-builtin [arg ...]] caller [EXPR] case WORD in [PATTERN [| PATTERN]. cd [-L|-P] [dir] command [-pVv] command [arg ...] compgen [-abcdefgjksuv] [-o option complete [-abcdefgjksuv] [-pr] [-o continue [n] declare [-afFirtx] [-p] [name[=val dirs [-clpv] [+N] [-N] disown [-h] [-ar] [jobspec ...] echo [-neE] [arg ...] enable [-pnds] [-a] [-f filename] eval [arg ...] exec [-cl] [-a name] file [redirec exit [n] export [-nf] [name[=value] ...] or false fc [-e ename] [-nlr] [first] [last fg [job_spec] for NAME [in WORDS ... ;] do COMMA for (( exp1; exp2; exp3 )); do COM function NAME { COMMANDS ; } or NA getopts optstring name [arg] hash [-lr] [-p pathname] [-dt] [na help [-s] [pattern ...] history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si let arg [arg ...] local name[=value] ... logout popd [+N | -N] [-n] printf [-v var] format [arguments] pushd [dir | +N | -N] [-n] pwd [-LP] read [-ers] [-u fd] [-t timeout] [ readonly [-af] [name[=value] ...] return [n] select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o option] [arg ...] shift [n] shopt [-pqsu] [-o long-option] opt source filename [arguments] suspend [-f] test [expr] time [-p] PIPELINE times trap [-lp] [arg signal_spec ...] true type [-afptP] name [name ...] typeset [-afFirtx] [-p] name[=valu ulimit [-SHacdfilmnpqstuvx] [limit umask [-p] [-S] [mode] unalias [-a] name [name ...] unset [-f] [-v] [name ...] until COMMANDS; do COMMANDS; done variables - Some variable names an wait [n] while COMMANDS; do COMMANDS; done { COMMANDS ; } 输入 man help BASH_BUILTINS(1) BASH_BUILTINS(1) NAME bash, :, ., [, alias, bg, bind, break, builtin, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, una- lias, unset, wait - bash built-in commands, see bash(1) BASH BUILTIN COMMANDS Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the end of the options. For example, the :, true, false, and test builtins do not accept options. : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned. . filename [arguments] source filename [arguments] Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename. If filename does not contain a slash, file names in PATH are used to find the directory containing file- name. The file searched for in PATH need not be executable. When bash is not in posix mode, the current directory is searched if no file is found in PATH. If the sourcepath option to the shopt builtin command is turned off, the PATH is not searched. If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise the positional parameters are unchanged. The return status is the status of the last command exited within the script (0 if no commands are executed), and false if filename is not found or cannot be read. alias [-p] [name[=value] ...] Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output. When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias substitution when the alias is expanded. For each name in the argument list for which no value is supplied, the name and value of the alias is printed. Alias returns true unless a name is given for which no alias has been defined. bg [jobspec ...] Resume each suspended job jobspec in the background, as if it had been started with &. If jobspec is not present, the shell’s notion of the current job is used. bg jobspec returns 0 unless run when job control is disabled or, when run with job con- trol enabled, any specified jobspec was not found or was started without job control. bind [-m keymap] [-lpsvPSV] bind [-m keymap] [-q function] [-u function] [-r keyseq] bind [-m keymap] -f filename bind [-m keymap] -x keyseq:shell-command bind [-m keymap] keyseq:function-name bind readline-command Display current readline key and function bindings, bind a key sequence to a readline function or macro, or set a readline variable. Each non-option argument is a command as it would appear in .inputrc, but each binding or command must be passed as a sepa- rate argument; e.g., ’"\C-x\C-r": re-read-init-file’. Options, if supplied, have the following meanings: -m keymap Use keymap as the keymap to be affected by the subsequent bindings. Accept- able keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is equivalent to emacs-standard. -l List the names of all readline functions. -p Display readline function names and bindings in such a way that they can be re-read. -P List current readline function names and bindings. -v Display readline variable names and values in such a way that they can be re- read. -V List current readline variable names and values. -s Display readline key sequences bound to macros and the strings they output in such a way that they can be re-read. -S Display readline key sequences bound to macros and the strings they output. -f filename Read key bindings from filename. -q function Query about which keys invoke the named function. -u function Unbind all keys bound to the named function. -r keyseq Remove any current binding for keyseq. -x keyseq:shell-command Cause shell-command to be executed whenever keyseq is entered. The return value is 0 unless an unrecognized option is given or an error occurred. break [n] Exit from within a for, while, until, or select loop. If n is specified, break n levels. n must be ≥ 1. If n is greater than the number of enclosing loops, all enclosing loops are exited. The return value is 0 unless the shell is not executing a loop when break is executed. builtin shell-builtin [arguments] Execute the specified shell builtin, passing it arguments, and return its exit sta- tus. This is useful when defining a function whose name is the same as a shell builtin, retaining the functionality of the builtin within the function. The cd builtin is commonly redefined this way. The return status is false if shell-builtin is not a shell builtin command. cd [-L|-P] [dir] Change the current directory to dir. The variable HOME is the default dir. The variable CDPATH defines the search path for the directory containing dir. Alterna- tive directory names in CDPATH are separated by a colon (:). A null directory name in CDPATH is the same as the current directory, i.e., ‘‘.’’. If dir begins with a slash (/), then CDPATH is not used. The -P option says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin command); the -L option forces symbolic links to be followed. An argument of - is equivalent to $OLDPWD. If a non-empty directory name from CDPATH is used, or if - is the first argument, and the directory change is successful, the absolute path- name of the new working directory is written to the standard output. The return value is true if the directory was successfully changed; false otherwise. caller [expr] Returns the context of any active subroutine call (a shell function or a script exe- cuted with the . or source builtins. Without expr, caller displays the line number and source filename of the current subroutine call. If a non-negative integer is supplied as expr, caller displays the line number, subroutine name, and source file corresponding to that position in the current execution call stack. This extra information may be used, for example, to print a stack trace. The current frame is frame 0. The return value is 0 unless the shell is not executing a subroutine call or expr does not correspond to a valid position in the call stack. command [-pVv] command [arg ...] Run command with args suppressing the normal shell function lookup. Only builtin com- mands or commands found in the PATH are executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The -v option causes a single word indicating the command or file name used to invoke command to be displayed; the -V option produces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not. If neither option is supplied and an error occurred or command cannot be found, the exit status is 127. Otherwise, the exit status of the command builtin is the exit status of command. compgen [option] [word] Generate possible completion matches for word according to the options, which may be any option accepted by the complete builtin with the exception of -p and -r, and write the matches to the standard output. When using the -F or -C options, the vari- ous shell variables set by the programmable completion facilities, while available, will not have useful values. The matches will be generated in the same way as if the programmable completion code had generated them directly from a completion specification with the same flags. If word is specified, only those completions matching word will be displayed. The return value is true unless an invalid option is supplied, or no matches were generated. complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] name [name ...] complete -pr [name ...] Specify how arguments to each name should be completed. If the -p option is sup- plied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be reused as input. The -r option removes a completion specification for each name, or, if no names are supplied, all completion specifica- tions. The process of applying these completion specifications when word completion is attempted is described above under Programmable Completion. Other options, if specified, have the following meanings. The arguments to the -G, -W, and -X options (and, if necessary, the -P and -S options) should be quoted to protect them from expansion before the complete builtin is invoked. -o comp-option The comp-option controls several aspects of the compspec’s behavior beyond the simple generation of completions. comp-option may be one of: bashdefault Perform the rest of the default bash completions if the compspec gen- erates no matches. default Use readline’s default filename completion if the compspec generates no matches. dirnames Perform directory name completion if the compspec generates no matches. filenames Tell readline that the compspec generates filenames, so it can per- form any filename-specific processing (like adding a slash to direc- tory names or suppressing trailing spaces). Intended to be used with shell functions. nospace Tell readline not to append a space (the default) to words completed at the end of the line. plusdirs After any matches defined by the compspec are generated, directory name completion is attempted and any matches are added to the results of the other actions. -A action The action may be one of the following to generate a list of possible comple- tions: alias Alias names. May also be specified as -a. arrayvar Array variable names. binding Readline key binding names. builtin Names of shell builtin commands. May also be specified as -b. command Command names. May also be specified as -c. directory Directory names. May also be specified as -d. disabled Names of disabled shell builtins. enabled Names of enabled shell builtins. export Names of exported shell variables. May also be specified as -e. file File names. May also be specified as -f. function Names of shell functions. group Group names. May also be specified as -g. helptopic Help topics as accepted by the help builtin. hostname Hostnames, as taken from the file specified by the HOSTFILE shell variable. job Job names, if job control is active. May also be specified as -j. keyword Shell reserved words. May also be specified as -k. running Names of running jobs, if job control is active. service Service names. May also be specified as -s. setopt Valid arguments for the -o option to the set builtin. shopt Shell option names as accepted by the shopt builtin. signal Signal names. stopped Names of stopped jobs, if job control is active. user User names. May also be specified as -u. variable Names of all shell variables. May also be specified as -v. -G globpat The filename expansion pattern globpat is expanded to generate the possible completions. -W wordlist The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members of the resultant list which match the word being completed. -C command command is executed in a subshell environment, and its output is used as the possible completions. -F function The shell function function is executed in the current shell environment. When it finishes, the possible completions are retrieved from the value of the COMPREPLY array variable. -X filterpat filterpat is a pattern as used for filename expansion. It is applied to the list of possible completions generated by the preceding options and argu- ments, and each completion matching filterpat is removed from the list. A leading ! in filterpat negates the pattern; in this case, any completion not matching filterpat is removed. -P prefix prefix is added at the beginning of each possible completion after all other options have been applied. -S suffix suffix is appended to each possible completion after all other options have been applied. The return value is true unless an invalid option is supplied, an option other than -p or -r is supplied without a name argument, an attempt is made to remove a comple- tion specification for a name for which no specification exists, or an error occurs adding a completion specification. continue [n] Resume the next iteration of the enclosing for, while, until, or select loop. If n is specified, resume at the nth enclosing loop. n must be ≥ 1. If n is greater than the number of enclosing loops, the last enclosing loop (the ‘‘top-level’’ loop) is resumed. The return value is 0 unless the shell is not executing a loop when con- tinue is executed. declare [-afFirtx] [-p] [name[=value] ...] typeset [-afFirtx] [-p] [name[=value] ...] Declare variables and/or give them attributes. If no names are given then display the values of variables. The -p option will display the attributes and values of each name. When -p is used, additional options are ignored. The -F option inhibits the display of function definitions; only the function name and attributes are printed. If the extdebug shell option is enabled using shopt, the source file name and line number where the function is defined are displayed as well. The -F option implies -f. The following options can be used to restrict output to variables with the specified attribute or to give variables attributes: -a Each name is an array variable (see Arrays above). -f Use function names only. -i The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION ) is performed when the variable is assigned a value. -r Make names readonly. These names cannot then be assigned values by subsequent assignment statements or unset. -t Give each name the trace attribute. Traced functions inherit the DEBUG and RETURN traps from the calling shell. The trace attribute has no special mean- ing for variables. -x Mark names for export to subsequent commands via the environment. Using ‘+’ instead of ‘-’ turns off the attribute instead, with the exception that +a may not be used to destroy an array variable. When used in a function, makes each name local, as with the local command. If a variable name is followed by =value, the value of the variable is set to value. The return value is 0 unless an invalid option is encountered, an attempt is made to define a function using ‘‘-f foo=bar’’, an attempt is made to assign a value to a readonly variable, an attempt is made to assign a value to an array variable without using the compound assignment syntax (see Arrays above), one of the names is not a valid shell variable name, an attempt is made to turn off readonly status for a readonly variable, an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-exis- tent function with -f. dirs [-clpv] [+n] [-n] Without options, displays the list of currently remembered directories. The default display is on a single line with directory names separated by spaces. Directories are added to the list with the pushd command; the popd command removes entries from the list. +n Displays the nth entry counting from the left of the list shown by dirs when invoked without options, starting with zero. -n Displays the nth entry counting from the right of the list shown by dirs when invoked without options, starting with zero. -c Clears the directory stack by deleting all of the entries. -l Produces a longer listing; the default listing format uses a tilde to denote the home directory. -p Print the directory stack with one entry per line. -v Print the directory stack with one entry per line, prefixing each entry with its index in the stack. The return value is 0 unless an invalid option is supplied or n indexes beyond the end of the directory stack. disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job. echo [-neE] [arg ...] Output the args, separated by spaces, followed by a newline. The return status is always 0. If -n is specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped characters is enabled. The -E option disables the interpretation of these escape characters, even on systems where they are interpreted by default. The xpg_echo shell option may be used to dynamically determine whether or not echo expands these escape characters by default. echo does not interpret -- to mean the end of options. echo interprets the following escape sequences: \a alert (bell) \b backspace \c suppress trailing newline \e an escape character \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \\ backslash \0nnn the eight-bit character whose value is the octal value nnn (zero to three octal digits) \nnn the eight-bit character whose value is the octal value nnn (one to three octal digits) \xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits) enable [-adnps] [-f filename] [name ...] Enable and disable builtin shell commands. Disabling a builtin allows a disk command which has the same name as a shell builtin to be executed without specifying a full pathname, even though the shell normally searches for builtins before disk commands. If -n is used, each name is disabled; otherwise, names are enabled. For example, to use the test binary found via the PATH instead of the shell builtin version, run ‘‘enable -n test’’. The -f option means to load the new builtin command name from shared object filename, on systems that support dynamic loading. The -d option will delete a builtin previously loaded with -f. If no name arguments are given, or if the -p option is supplied, a list of shell builtins is printed. With no other option arguments, the list consists of all enabled shell builtins. If -n is supplied, only disabled builtins are printed. If -a is supplied, the list printed includes all builtins, with an indication of whether or not each is enabled. If -s is supplied, the output is restricted to the POSIX special builtins. The return value is 0 unless a name is not a shell builtin or there is an error loading a new builtin from a shared object. eval [arg ...] The args are read and concatenated together into a single command. This command is then read and executed by the shell, and its exit status is returned as the value of eval. If there are no args, or only null arguments, eval returns 0. exec [-cl] [-a name] [command [arguments]] If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command. If the -l option is supplied, the shell places a dash at the beginning of the zeroth arg passed to command. This is what login(1) does. The -c option causes command to be executed with an empty environ- ment. If -a is supplied, the shell passes name as the zeroth argument to the exe- cuted command. If command cannot be executed for some reason, a non-interactive shell exits, unless the shell option execfail is enabled, in which case it returns failure. An interactive shell returns failure if the file cannot be executed. If command is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1. exit [n] Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed. A trap on EXIT is executed before the shell termi- nates. export [-fn] [name[=word]] ... export -p The supplied names are marked for automatic export to the environment of subsequently executed commands. If the -f option is given, the names refer to functions. If no names are given, or if the -p option is supplied, a list of all names that are exported in this shell is printed. The -n option causes the export property to be removed from each name. If a variable name is followed by =word, the value of the variable is set to word. export returns an exit status of 0 unless an invalid option is encountered, one of the names is not a valid shell variable name, or -f is sup- plied with a name that is not a function. fc [-e ename] [-nlr] [first] [last] fc -s [pat=rep] [cmd] Fix Command. In the first form, a range of commands from first to last is selected from the history list. First and last may be specified as a string (to locate the last command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the current command number). If last is not specified it is set to the current command for listing (so that ‘‘fc -l -10’’ prints the last 10 commands) and to first otherwise. If first is not speci- fied it is set to the previous command for editing and -16 for listing. The -n option suppresses the command numbers when listing. The -r option reverses the order of the commands. If the -l option is given, the commands are listed on standard output. Otherwise, the editor given by ename is invoked on a file contain- ing those commands. If ename is not given, the value of the FCEDIT variable is used, and the value of EDITOR if FCEDIT is not set. If neither variable is set, is used. When editing is complete, the edited commands are echoed and executed. In the second form, command is re-executed after each instance of pat is replaced by rep. A useful alias to use with this is ‘‘r="fc -s"’’, so that typing ‘‘r cc’’ runs the last command beginning with ‘‘cc’’ and typing ‘‘r’’ re-executes the last command. If the first form is used, the return value is 0 unless an invalid option is encoun- tered or first or last specify history lines out of range. If the -e option is sup- plied, the return value is the value of the last command executed or failure if an error occurs with the temporary file of commands. If the second form is used, the return status is that of the command re-executed, unless cmd does not specify a valid history line, in which case fc returns failure. fg [jobspec] Resume jobspec in the foreground, and make it the current job. If jobspec is not present, the shell’s notion of the current job is used. The return value is that of the command placed into the foreground, or failure if run when job control is dis- abled or, when run with job control enabled, if jobspec does not specify a valid job or jobspec specifies a job that was started without job control. getopts optstring name [args] getopts is used by shell procedures to parse positional parameters. optstring con- tains the option characters to be recognized; if a character is followed by a colon, the option is expected to have an argument, which should be separated from it by white space. The colon and question mark characters may not be used as option char- acters. Each time it is invoked, getopts places the next option in the shell vari- able name, initializing name if it does not exist, and the index of the next argument to be processed into the variable OPTIND. OPTIND is initialized to 1 each time the shell or a shell script is invoked. When an option requires an argument, getopts places that argument into the variable OPTARG. The shell does not reset OPTIND auto- matically; it must be manually reset between multiple calls to getopts within the same shell invocation if a new set of parameters is to be used. When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is set to the index of the first non-option argument, and name is set to ?. getopts normally parses the positional parameters, but if more arguments are given in args, getopts parses those instead. getopts can report errors in two ways. If the first character of optstring is a colon, silent error reporting is used. In normal operation diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable OPTERR is set to 0, no error messages will be displayed, even if the first character of optstring is not a colon. If an invalid option is seen, getopts places ? into name and, if not silent, prints an error message and unsets OPTARG. If getopts is silent, the option character found is placed in OPTARG and no diagnostic message is printed. If a required argument is not found, and getopts is not silent, a question mark (?) is placed in name, OPTARG is unset, and a diagnostic message is printed. If getopts is silent, then a colon (:) is placed in name and OPTARG is set to the option charac- ter found. getopts returns true if an option, specified or unspecified, is found. It returns false if the end of options is encountered or an error occurs. hash [-lr] [-p filename] [-dt] [name] For each name, the full file name of the command is determined by searching the directories in $PATH and remembered. If the -p option is supplied, no path search is performed, and filename is used as the full file name of the command. The -r option causes the shell to forget all remembered locations. The -d option causes the shell to forget the remembered location of each name. If the -t option is supplied, the full pathname to which each name corresponds is printed. If multiple name arguments are supplied with -t, the name is printed before the hashed full pathname. The -l option causes output to be displayed in a format that may be reused as input. If no arguments are given, or if only -l is supplied, information about remembered commands is printed. The return status is true unless a name is not found or an invalid option is supplied. help [-s] [pattern] Display helpful information about builtin commands. If pattern is specified, help gives detailed help on all commands matching pattern; otherwise help for all the builtins and shell control structures is printed. The -s option restricts the infor- mation displayed to a short usage synopsis. The return status is 0 unless no command matches pattern. history [n] history -c history -d offset history -anrw [filename] history -p arg [arg ...] history -s arg [arg ...] With no options, display the command history list with line numbers. Lines listed with a * have been modified. An argument of n lists only the last n lines. If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for strftime(3) to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line. If filename is supplied, it is used as the name of the history file; if not, the value of HISTFILE is used. Options, if supplied, have the following meanings: -c Clear the history list by deleting all the entries. -d offset Delete the history entry at position offset. -a Append the ‘‘new’’ history lines (history lines entered since the beginning of the current bash session) to the history file. -n Read the history lines not already read from the history file into the current history list. These are lines appended to the history file since the begin- ning of the current bash session. -r Read the contents of the history file and use them as the current history. -w Write the current history to the history file, overwriting the history file’s contents. -p Perform history substitution on the following args and display the result on the standard output. Does not store the results in the history list. Each arg must be quoted to disable normal history expansion. -s Store the args in the history list as a single entry. The last command in the history list is removed before the args are added. If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file. The return value is 0 unless an invalid option is encountered, an error occurs while reading or writing the history file, an invalid offset is supplied as an argument to -d, or the history expansion supplied as an argument to -p fails. jobs [-lnprs] [ jobspec ... ] jobs -x command [ args ... ] The first form lists the active jobs. The options have the following meanings: -l List process IDs in addition to the normal information. -p List only the process ID of the job’s process group leader. -n Display information only about jobs that have changed status since the user was last notified of their status. -r Restrict output to running jobs. -s Restrict output to stopped jobs. If jobspec is given, output is restricted to information about that job. The return status is 0 unless an invalid option is encountered or an invalid jobspec is sup- plied. If the -x option is supplied, jobs replaces any jobspec found in command or args with the corresponding process group ID, and executes command passing it args, returning its exit status. kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ... kill -l [sigspec | exit_status] Send the signal named by sigspec or signum to the processes named by pid or jobspec. sigspec is either a case-insensitive signal name such as SIGKILL (with or without the SIG prefix) or a signal number; signum is a signal number. If sigspec is not present, then SIGTERM is assumed. An argument of -l lists the signal names. If any arguments are supplied when -l is given, the names of the signals corresponding to the arguments are listed, and the return status is 0. The exit_status argument to -l is a number specifying either a signal number or the exit status of a process termi- nated by a signal. kill returns true if at least one signal was successfully sent, or false if an error occurs or an invalid option is encountered. let arg [arg ...] Each arg is an arithmetic expression to be evaluated (see ARITHMETIC EVALUATION). If the last arg evaluates to 0, let returns 1; 0 is returned otherwise. local [option] [name[=value] ...] For each argument, a local variable named name is created, and assigned value. The option can be any of the options accepted by declare. When local is used within a function, it causes the variable name to have a visible scope restricted to that function and its children. With no operands, local writes a list of local variables to the standard output. It is an error to use local when not within a function. The return status is 0 unless local is used outside a function, an invalid name is sup- plied, or name is a readonly variable. logout Exit a login shell. popd [-n] [+n] [-n] Removes entries from the directory stack. With no arguments, removes the top direc- tory from the stack, and performs a cd to the new top directory. Arguments, if sup- plied, have the following meanings: +n Removes the nth entry counting from the left of the list shown by dirs, start- ing with zero. For example: ‘‘popd +0’’ removes the first directory, ‘‘popd +1’’ the second. -n Removes the nth entry counting from the right of the list shown by dirs, starting with zero. For example: ‘‘popd -0’’ removes the last directory, ‘‘popd -1’’ the next to last. -n Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated. If the popd command is successful, a dirs is performed as well, and the return status is 0. popd returns false if an invalid option is encountered, the directory stack is empty, a non-existent directory stack entry is specified, or the directory change fails. printf [-v var] format [arguments] Write the formatted arguments to the standard output under the control of the format. The format is a character string which contains three types of objects: plain charac- ters, which are simply copied to standard output, character escape sequences, which are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive argument. In addition to the standard printf(1) formats, %b causes printf to expand backslash escape sequences in the cor- responding argument (except that \c terminates output, backslashes in \', \", and \? are not removed, and octal escapes beginning with \0 may contain up to four digits), and %q causes printf to output the corresponding argument in a format that can be reused as shell input. The -v option causes the output to be assigned to the variable var rather than being printed to the standard output. The format is reused as necessary to consume all of the arguments. If the format requires more arguments than are supplied, the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied. The return value is zero on success, non-zero on failure. pushd [-n] [dir] pushd [-n] [+n] [-n] Adds a directory to the top of the directory stack, or rotates the stack, making the new top of the stack the current working directory. With no arguments, exchanges the top two directories and returns 0, unless the directory stack is empty. Arguments, if supplied, have the following meanings: +n Rotates the stack so that the nth directory (counting from the left of the list shown by dirs, starting with zero) is at the top. -n Rotates the stack so that the nth directory (counting from the right of the list shown by dirs, starting with zero) is at the top. -n Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated. dir Adds dir to the directory stack at the top, making it the new current working directory. If the pushd command is successful, a dirs is performed as well. If the first form is used, pushd returns 0 unless the cd to dir fails. With the second form, pushd returns 0 unless the directory stack is empty, a non-existent directory stack element is specified, or the directory change to the specified new current directory fails. pwd [-LP] Print the absolute pathname of the current working directory. The pathname printed contains no symbolic links if the -P option is supplied or the -o physical option to the set builtin command is enabled. If the -L option is used, the pathname printed may contain symbolic links. The return status is 0 unless an error occurs while reading the name of the current directory or an invalid option is supplied. read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...] One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to the first name, the second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name. If there are fewer words read from the input stream than names, the remaining names are assigned empty values. The characters in IFS are used to split the line into words. The backslash character (\) may be used to remove any special meaning for the next character read and for line continuation. Options, if supplied, have the following meanings: -a aname The words are assigned to sequential indices of the array variable aname, starting at 0. aname is unset before any new values are assigned. Other name arguments are ignored. -d delim The first character of delim is used to terminate the input line, rather than newline. -e If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line. -n nchars read returns after reading nchars characters rather than waiting for a com- plete line of input. -p prompt Display prompt on standard error, without a trailing newline, before attempt- ing to read any input. The prompt is displayed only if input is coming from a terminal. -r Backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation. -s Silent mode. If input is coming from a terminal, characters are not echoed. -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has no effect if read is not reading input from the terminal or a pipe. -u fd Read input from file descriptor fd. If no names are supplied, the line read is assigned to the variable REPLY. The return code is zero, unless end-of-file is encountered, read times out, or an invalid file descriptor is supplied as the argument to -u. readonly [-apf] [name[=word] ...] The given names are marked readonly; the values of these names may not be changed by subsequent assignment. If the -f option is supplied, the functions corresponding to the names are so marked. The -a option restricts the variables to arrays. If no name arguments are given, or if the -p option is supplied, a list of all readonly names is printed. The -p option causes output to be displayed in a format that may be reused as input. If a variable name is followed by =word, the value of the vari- able is set to word. The return status is 0 unless an invalid option is encountered, one of the names is not a valid shell variable name, or -f is supplied with a name that is not a function. return [n] Causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command executed in the function body. If used outside a function, but during execution of a script by the . (source) command, it causes the shell to stop executing that script and return either n or the exit status of the last command executed within the script as the exit status of the script. If used outside a function and not during execution of a script by ., the return status is false. Any command associated with the RETURN trap is executed before execution resumes after the function or script. set [--abefhkmnptuvxBCHP] [-o option] [arg ...] Without options, the name and value of each shell variable are displayed in a format that can be reused as input for setting or resetting the currently-set variables. Read-only variables cannot be reset. In posix mode, only shell variables are listed. The output is sorted according to the current locale. When options are specified, they set or unset shell attributes. Any arguments remaining after the options are processed are treated as values for the positional parameters and are assigned, in order, to $1, $2, ... $n. Options, if specified, have the following meanings: -a Automatically mark variables and functions which are modified or created for export to the environment of subsequent commands. -b Report the status of terminated background jobs immediately, rather than before the next primary prompt. This is effective only when job control is enabled. -e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a && or ││ list, or if the command’s return value is being inverted via !. A trap on ERR, if set, is executed before the shell exits. -f Disable pathname expansion. -h Remember the location of commands as they are looked up for execution. This is enabled by default. -k All arguments in the form of assignment statements are placed in the environ- ment for a command, not just those that precede the command name. -m Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that support it (see JOB CONTROL above). Back- ground processes run in a separate process group and a line containing their exit status is printed upon their completion. -n Read commands but do not execute them. This may be used to check a shell script for syntax errors. This is ignored by interactive shells. -o option-name The option-name can be one of the following: allexport Same as -a. braceexpand Same as -B. emacs Use an emacs-style command line editing interface. This is enabled by default when the shell is interactive, unless the shell is started with the --noediting option. errtrace Same as -E. functrace Same as -T. errexit Same as -e. hashall Same as -h. histexpand Same as -H. history Enable command history, as described above under HISTORY. This option is on by default in interactive shells. ignoreeof The effect is as if the shell command ‘‘IGNOREEOF=10’’ had been exe- cuted (see Shell Variables above). keyword Same as -k. monitor Same as -m. noclobber Same as -C. noexec Same as -n. noglob Same as -f. nolog Currently ignored. notify Same as -b. nounset Same as -u. onecmd Same as -t. physical Same as -P. pipefail If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all command

2010-02-10

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除