@@ -381,8 +381,244 @@ hello3.txt
381
381
[deploy@sz-local3 test1]$ ls
382
382
```
383
383
384
+ ##### mv (移动文件与目录,或修改名称)
384
385
386
+ >mv [-fiu] 源文件 目标文件
385
387
388
+ 选项与参数:
389
+ - -f : 强制。如果目标文件已经存在,不会询问,直接覆盖。
390
+ - -i :若目标文件已存在,则询问是否覆盖。
391
+ - -u : 若目标文件已存在,且源比较新,才会升级。
392
+
393
+ ```shell
394
+ [deploy@sz-local3 test1]$ cat hello.txt
395
+ hello
396
+ [deploy@sz-local3 test1]$ cat boy.txt
397
+ boy
398
+ [deploy@sz-local3 test1]$ mv hello.txt boy.txt # 将hello.txt命名为boy.txt,原来的boy.txt没了
399
+ [deploy@sz-local3 test1]$ ls
400
+ boy.txt tmpdir
401
+ [deploy@sz-local3 test1]$ cat boy.txt
402
+ hello
403
+ [deploy@sz-local3 test1]$ mv boy.txt tmpdir/
404
+ [deploy@sz-local3 test1]$ ls
405
+ tmpdir
406
+ [deploy@sz-local3 test1]$ cd tmpdir/
407
+ [deploy@sz-local3 tmpdir]$ ls
408
+ boy.txt
409
+
410
+ [deploy@sz-local3 test1]$ echo ' hello' > hello.txt
411
+ [deploy@sz-local3 test1]$ echo ' boy' > boy.txt
412
+ [deploy@sz-local3 test1]$ mv -i hello.txt boy.txt #提示是否覆盖已存在的boy.txt文件
413
+ mv: overwrite `boy.txt' ?
414
+ ` ` `
415
+
416
+ # ## Linux 文件内容查看
417
+
418
+ Linux 系统中使用以下命令来查看文件的内容:
419
+
420
+ - cat : 由第一行开始显示内容
421
+ - tac : 从最后一行开始显示,可以看出 tac 是 cat 的倒写
422
+ - nl : 显示的时候,顺道输出行号
423
+ - more : 一页一页的显示文件
424
+ - less : 与 more 类似,但是比more更好的是,less可以往前翻页
425
+ - head : 只看头几行
426
+ - tail : 只看尾几行
427
+
428
+ # ### cat 由第一行开始显示文件内容
429
+
430
+ > cat [-AbEnTv]
431
+
432
+ 选项与参数:
433
+ - -A : 相当于 -vET 的组合项,可列出一些特殊字符而不是空白而已
434
+ - -b : 列出行号,仅针对非空白行做行号显示,空白行不标行号
435
+ - -E : 将结尾的断行字节$显示出来
436
+ - -n : 列出行号,连同空白行也会有行号,与 -b 选项不同
437
+ - -T : 将tab键以 ^| 显示出俩
438
+ - -v : 列出一些看不出来的特殊字符
439
+
440
+ # ### tac 和cat相反
441
+
442
+
443
+ QuickSortTest.java 的内容如下:
444
+
445
+ ` ` ` java
446
+ package org.byron4j.cookbook.algrithms;
447
+
448
+ import org.junit.Test;
449
+
450
+ public class QuickSortTest {
451
+ @Test
452
+ public void test (){
453
+ int[] arr = new int[]{6, 2, 4, 1, 5, 9};
454
+ QuickSort.sortCore(arr, 0, 5);
455
+ for (int i : arr) {
456
+ System.out.println(i);
457
+ }
458
+ }
459
+ }
460
+
461
+ ` ` `
462
+
463
+ 示例如下:
464
+ ` ` ` shell
465
+ [deploy@sz-local3 test1]$ cat QuickSortTest.java
466
+ package org.byron4j.cookbook.algrithms;
467
+
468
+ import org.junit.Test;
469
+
470
+ public class QuickSortTest {
471
+ @Test
472
+ public void test (){
473
+ int[] arr = new int[]{6, 2, 4, 1, 5, 9};
474
+ QuickSort.sortCore(arr, 0, 5);
475
+ for (int i : arr) {
476
+ System.out.println(i);
477
+ }
478
+ }
479
+ }
480
+ [deploy@sz-local3 test1]$
481
+ [deploy@sz-local3 test1]$
482
+ [deploy@sz-local3 test1]$ tac QuickSortTest.java
483
+ }
484
+ }
485
+ }
486
+ System.out.println(i);
487
+ for (int i : arr) {
488
+ QuickSort.sortCore(arr, 0, 5);
489
+ int[] arr = new int[]{6, 2, 4, 1, 5, 9};
490
+ public void test (){
491
+ @Test
492
+ public class QuickSortTest {
493
+
494
+ import org.junit.Test;
495
+
496
+ package org.byron4j.cookbook.algrithms;
497
+ ` ` `
498
+
499
+
500
+ # ### nl 显示行号查看内容
501
+
502
+ > nl [-bnw] 文件
503
+
504
+ 选项与参数:
505
+ - -b : 指定行号指定的方式,主要有两种:
506
+ - -b a:表示不论是否为空行,也同样列出行号(类似 cat -n);
507
+ - -b t:如果有空行,空的那一行不要列出行号(默认值)
508
+ - -n :列出行号表示的方法,有三种:
509
+ - -n ln : 行号在屏幕的最左方显示
510
+ - -n rn : 行号在行号栏位的最右方显示
511
+ - -n rz : 行号在行号栏位的最右方显示,且补足0
512
+ - -w : 行号栏位的占用的位数
513
+
514
+ 实例,分别展示了行号在行号栏位的展示位置:
515
+ ` ` ` shell
516
+ [deploy@sz-local3 test1]$ nl -nln QuickSortTest.java
517
+ 1 package org.byron4j.cookbook.algrithms;
518
+ 2
519
+ 3 import org.junit.Test;
520
+ 4
521
+ 5 public class QuickSortTest {
522
+ 6 @Test
523
+ 7 public void test (){
524
+ 8 int[] arr = new int[]{6, 2, 4, 1, 5, 9};
525
+ 9 QuickSort.sortCore(arr, 0, 5);
526
+ 10 for (int i : arr) {
527
+ 11 System.out.println(i);
528
+ 12 }
529
+ 13 }
530
+ 14 }
531
+ [deploy@sz-local3 test1]$ nl -nrn QuickSortTest.java
532
+ 1 package org.byron4j.cookbook.algrithms;
533
+ 2
534
+ 3 import org.junit.Test;
535
+ 4
536
+ 5 public class QuickSortTest {
537
+ 6 @Test
538
+ 7 public void test (){
539
+ 8 int[] arr = new int[]{6, 2, 4, 1, 5, 9};
540
+ 9 QuickSort.sortCore(arr, 0, 5);
541
+ 10 for (int i : arr) {
542
+ 11 System.out.println(i);
543
+ 12 }
544
+ 13 }
545
+ 14 }
546
+ [deploy@sz-local3 test1]$ nl -nrz QuickSortTest.java
547
+ 000001 package org.byron4j.cookbook.algrithms;
548
+ 000002
549
+ 000003 import org.junit.Test;
550
+ 000004
551
+ 000005 public class QuickSortTest {
552
+ 000006 @Test
553
+ 000007 public void test (){
554
+ 000008 int[] arr = new int[]{6, 2, 4, 1, 5, 9};
555
+ 000009 QuickSort.sortCore(arr, 0, 5);
556
+ 000010 for (int i : arr) {
557
+ 000011 System.out.println(i);
558
+ 000012 }
559
+ 000013 }
560
+ 000014 }
561
+
562
+ ` ` `
563
+
564
+
565
+ # ### more 一页一页的翻动
566
+
567
+ lovelyman.txt 摘录了魏巍的《谁是最可爱的人?》文章。下面以此为例演示:
568
+
569
+ ! [](more.png)
570
+
571
+ 使用了 ` ` ` more lovelyman.txt ` ` ` 查看文件内容,一页后显示了当前所占文件内容的比例。
572
+ 在 more 这个程序的运行过程中,你有几个按键可以按的:
573
+ - 空白键 : 代表向下翻一页
574
+ - Enter : 代表向下翻一行
575
+ - /str : 代表这个显示的内容当中,向下搜寻str这个关键字
576
+ - :f : 立刻显示出文档名以及当前显示的行数
577
+ - q : quit,表示立刻离开more,不再显示该文件内容
578
+ - b 或 ctrl-b : 代表往回翻页,但是这只对文件有用,对管道无用
579
+
580
+ # ### less 一页一页翻动
581
+
582
+ > less 文件
583
+
584
+ less 运行时可以输入的命令有:
585
+ - 空白键 : 向下翻一页
586
+ - pagedow : 向下翻一页
587
+ - pageup : 向上翻一页
588
+ - /str : 向下搜寻str
589
+ - ? str : 向上搜寻str
590
+ - n : 重复前一个搜寻(与/或?相关)
591
+ - N : 反向的重复前一个搜寻(与/或?相关)
592
+ - q : 离开less这个程序
593
+
594
+ # ### head 去除文件前面几行
595
+
596
+ > head [-n 行数] 文件
597
+
598
+ ` ` ` shell
599
+ [deploy@sz-local3 test1]$ head -n 5 QuickSortTest.java
600
+ package org.byron4j.cookbook.algrithms;
601
+
602
+ import org.junit.Test;
603
+
604
+ public class QuickSortTest {
605
+ ` ` `
606
+
607
+ # ### tail 取出文件后面几行
608
+
609
+ > tail [-n 行数] 文件
610
+
611
+ - -n : 后面接数字,代表显示几行的意思
612
+ - -f :表示持续侦测后面所接的档名,要等到按下ctrl-c才会结束tail的侦测
613
+
614
+ ` ` ` shell
615
+ [deploy@sz-local3 test1]$ tail -n 5 QuickSortTest.java
616
+ for (int i : arr) {
617
+ System.out.println(i);
618
+ }
619
+ }
620
+ }
621
+ ` ` `
386
622
387
623
388
624
0 commit comments