之前的系统安装、配置会单独出一篇博客,这里就不赘述了,直接进入主题
进入SecureCRT,连接服务器
创建一个目录
mkdir tmp
[oracle@localhost ~]$ mkdir tmp
[oracle@localhost ~]$ ls
Desktop Downloads Pictures Templates app oradiag_oracle upload
Documents Music Public Videos oraInventory tmp
[oracle@localhost ~]$
在这里如果想要递归的创建目录,比如创建目录a下面再创建目录b,再在目录b下面创建目录c,可以使用-p参数
[oracle@CentOS tmp]$ mkdir -p a/b/c
[oracle@CentOS tmp]$ ls a/b
c
[oracle@CentOS tmp]$ tree a
a
`-- b
`-- c
2 directories, 0 files
查看当前用户
[oracle@localhost ~]$ who
oracle pts/0 Aug 4 11:59 (2.2.2.1)
更改目录位置
[oracle@localhost ~]$ cd tmp/
[oracle@localhost tmp]$
如果cd命令后什么都不加,默认回到家目录
[oracle@CentOS tmp]$ cd
[oracle@CentOS ~]$ pwd
/home/oracle
[oracle@CentOS ~]$ whoami
oracle
[root@CentOS6 ~]# cd tmp/
[root@CentOS6 tmp]# cd ~
[root@CentOS6 ~]# cd tmp/
[root@CentOS6 tmp]# cd -
/root
[root@CentOS6 ~]# pwd
/root
查看当前目录位置
pwd
[oracle@localhost tmp]$ pwd
/home/oracle/tmp
在目录下创建文件
[oracle@CentOS tmp]$ touch test.txt
[oracle@CentOS tmp]$ ll
total 0
drwxr-xr-x 3 oracle dba 15 Aug 5 13:22 a
-rw-r--r-- 1 oracle dba 0 Aug 5 13:37 test.txt
[oracle@CentOS tmp]$ touch 1.txt 2.txt 3.txt
[oracle@CentOS tmp]$ ll
total 0
-rw-r--r-- 1 oracle dba 0 Aug 5 13:40 1.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:40 2.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:40 3.txt
drwxr-xr-x 3 oracle dba 15 Aug 5 13:22 a
-rw-r--r-- 1 oracle dba 0 Aug 5 13:37 test.txt
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ touch {a,b,c}.txt
[oracle@CentOS tmp]$ ll
total 0
-rw-r--r-- 1 oracle dba 0 Aug 5 13:40 1.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:40 2.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:40 3.txt
drwxr-xr-x 3 oracle dba 15 Aug 5 13:22 a
-rw-r--r-- 1 oracle dba 0 Aug 5 13:41 a.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:41 b.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:41 c.txt
-rw-r--r-- 1 oracle dba 0 Aug 5 13:37 test.txt
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ for f in `seq 1000`;do touch $f.txt;done
[oracle@CentOS tmp]$ ls
1.txt 19.txt 280.txt 371.txt 462.txt 553.txt 644.txt 735.txt 826.txt 917.txt
10.txt 190.txt 281.txt 372.txt 463.txt 554.txt 645.txt 736.txt 827.txt 918.txt
100.txt 191.txt 282.txt 373.txt 464.txt 555.txt 646.txt 737.txt 828.txt 919.txt
1000.txt 192.txt 283.txt 374.txt 465.txt 556.txt 647.txt 738.txt 829.txt 92.txt
101.txt 193.txt 284.txt 375.txt 466.txt 557.txt 648.txt 739.txt 83.txt 920.txt
102.txt 194.txt 285.txt 376.txt 467.txt 558.txt 649.txt 74.txt 830.txt 921.txt
103.txt 195.txt 286.txt 377.txt 468.txt 559.txt 65.txt 740.txt 831.txt 922.txt
104.txt 196.txt 287.txt 378.txt 469.txt 56.txt 650.txt 741.txt 832.txt 923.txt
105.txt 197.txt 288.txt 379.txt 47.txt 560.txt 651.txt 742.txt 833.txt 924.txt
106.txt 198.txt 289.txt 38.txt 470.txt 561.txt 652.txt 743.txt 834.txt 925.txt
107.txt 199.txt 29.txt 380.txt 471.txt 562.txt 653.txt 744.txt 835.txt 926.txt
108.txt 2.txt 290.txt 381.txt 472.txt 563.txt 654.txt 745.txt 836.txt 927.txt
109.txt 20.txt 291.txt 382.txt 473.txt 564.txt 655.txt 746.txt 837.txt 928.txt
11.txt 200.txt 292.txt 383.txt 474.txt 565.txt 656.txt 747.txt 838.txt 929.txt
110.txt 201.txt 293.txt 384.txt 475.txt 566.txt 657.txt 748.txt 839.txt 93.txt
111.txt 202.txt 294.txt 385.txt 476.txt 567.txt 658.txt 749.txt 84.txt 930.txt
112.txt 203.txt 295.txt 386.txt 477.txt 568.txt 659.txt 75.txt 840.txt 931.txt
113.txt 204.txt 296.txt 387.txt 478.txt 569.txt 66.txt 750.txt 841.txt 932.txt
114.txt 205.txt 297.txt 388.txt 479.txt 57.txt 660.txt 751.txt 842.txt 933.txt
115.txt 206.txt 298.txt 389.txt 48.txt 570.txt 661.txt 752.txt 843.txt 934.txt
116.txt 207.txt 299.txt 39.txt 480.txt 571.txt 662.txt 753.txt 844.txt 935.txt
117.txt 208.txt 3.txt 390.txt 481.txt 572.txt 663.txt 754.txt 845.txt 936.txt
118.txt 209.txt 30.txt 391.txt 482.txt 573.txt 664.txt 755.txt 846.txt 937.txt
119.txt 21.txt 300.txt 392.txt 483.txt 574.txt 665.txt 756.txt 847.txt 938.txt
12.txt 210.txt 301.txt 393.txt 484.txt 575.txt 666.txt 757.txt 848.txt 939.txt
120.txt 211.txt 302.txt 394.txt 485.txt 576.txt 667.txt 758.txt 849.txt 94.txt
121.txt 212.txt 303.txt 395.txt 486.txt 577.txt 668.txt 759.txt 85.txt 940.txt
122.txt 213.txt 304.txt 396.txt 487.txt 578.txt 669.txt 76.txt 850.txt 941.txt
123.txt 214.txt 305.txt 397.txt 488.txt 579.txt 67.txt 760.txt 851.txt 942.txt
124.txt 215.txt 306.txt 398.txt 489.txt 58.txt 670.txt 761.txt 852.txt 943.txt
125.txt 216.txt 307.txt 399.txt 49.txt 580.txt 671.txt 762.txt 853.txt 944.txt
126.txt 217.txt 308.txt 4.txt 490.txt 581.txt 672.txt 763.txt 854.txt 945.txt
127.txt 218.txt 309.txt 40.txt 491.txt 582.txt 673.txt 764.txt 855.txt 946.txt
128.txt 219.txt 31.txt 400.txt 492.txt 583.txt 674.txt 765.txt 856.txt 947.txt
129.txt 22.txt 310.txt 401.txt 493.txt 584.txt 675.txt 766.txt 857.txt 948.txt
13.txt 220.txt 311.txt 402.txt 494.txt 585.txt 676.txt 767.txt 858.txt 949.txt
130.txt 221.txt 312.txt 403.txt 495.txt 586.txt 677.txt 768.txt 859.txt 95.txt
131.txt 222.txt 313.txt 404.txt 496.txt 587.txt 678.txt 769.txt 86.txt 950.txt
132.txt 223.txt 314.txt 405.txt 497.txt 588.txt 679.txt 77.txt 860.txt 951.txt
133.txt 224.txt 315.txt 406.txt 498.txt 589.txt 68.txt 770.txt 861.txt 952.txt
134.txt 225.txt 316.txt 407.txt 499.txt 59.txt 680.txt 771.txt 862.txt 953.txt
135.txt 226.txt 317.txt 408.txt 5.txt 590.txt 681.txt 772.txt 863.txt 954.txt
136.txt 227.txt 318.txt 409.txt 50.txt 591.txt 682.txt 773.txt 864.txt 955.txt
137.txt 228.txt 319.txt 41.txt 500.txt 592.txt 683.txt 774.txt 865.txt 956.txt
138.txt 229.txt 32.txt 410.txt 501.txt 593.txt 684.txt 775.txt 866.txt 957.txt
139.txt 23.txt 320.txt 411.txt 502.txt 594.txt 685.txt 776.txt 867.txt 958.txt
14.txt 230.txt 321.txt 412.txt 503.txt 595.txt 686.txt 777.txt 868.txt 959.txt
140.txt 231.txt 322.txt 413.txt 504.txt 596.txt 687.txt 778.txt 869.txt 96.txt
141.txt 232.txt 323.txt 414.txt 505.txt 597.txt 688.txt 779.txt 87.txt 960.txt
142.txt 233.txt 324.txt 415.txt 506.txt 598.txt 689.txt 78.txt 870.txt 961.txt
143.txt 234.txt 325.txt 416.txt 507.txt 599.txt 69.txt 780.txt 871.txt 962.txt
144.txt 235.txt 326.txt 417.txt 508.txt 6.txt 690.txt 781.txt 872.txt 963.txt
145.txt 236.txt 327.txt 418.txt 509.txt 60.txt 691.txt 782.txt 873.txt 964.txt
146.txt 237.txt 328.txt 419.txt 51.txt 600.txt 692.txt 783.txt 874.txt 965.txt
147.txt 238.txt 329.txt 42.txt 510.txt 601.txt 693.txt 784.txt 875.txt 966.txt
148.txt 239.txt 33.txt 420.txt 511.txt 602.txt 694.txt 785.txt 876.txt 967.txt
149.txt 24.txt 330.txt 421.txt 512.txt 603.txt 695.txt 786.txt 877.txt 968.txt
15.txt 240.txt 331.txt 422.txt 513.txt 604.txt 696.txt 787.txt 878.txt 969.txt
150.txt 241.txt 332.txt 423.txt 514.txt 605.txt 697.txt 788.txt 879.txt 97.txt
151.txt 242.txt 333.txt 424.txt 515.txt 606.txt 698.txt 789.txt 88.txt 970.txt
152.txt 243.txt 334.txt 425.txt 516.txt 607.txt 699.txt 79.txt 880.txt 971.txt
153.txt 244.txt 335.txt 426.txt 517.txt 608.txt 7.txt 790.txt 881.txt 972.txt
154.txt 245.txt 336.txt 427.txt 518.txt 609.txt 70.txt 791.txt 882.txt 973.txt
155.txt 246.txt 337.txt 428.txt 519.txt 61.txt 700.txt 792.txt 883.txt 974.txt
156.txt 247.txt 338.txt 429.txt 52.txt 610.txt 701.txt 793.txt 884.txt 975.txt
157.txt 248.txt 339.txt 43.txt 520.txt 611.txt 702.txt 794.txt 885.txt 976.txt
158.txt 249.txt 34.txt 430.txt 521.txt 612.txt 703.txt 795.txt 886.txt 977.txt
159.txt 25.txt 340.txt 431.txt 522.txt 613.txt 704.txt 796.txt 887.txt 978.txt
16.txt 250.txt 341.txt 432.txt 523.txt 614.txt 705.txt 797.txt 888.txt 979.txt
160.txt 251.txt 342.txt 433.txt 524.txt 615.txt 706.txt 798.txt 889.txt 98.txt
161.txt 252.txt 343.txt 434.txt 525.txt 616.txt 707.txt 799.txt 89.txt 980.txt
162.txt 253.txt 344.txt 435.txt 526.txt 617.txt 708.txt 8.txt 890.txt 981.txt
163.txt 254.txt 345.txt 436.txt 527.txt 618.txt 709.txt 80.txt 891.txt 982.txt
164.txt 255.txt 346.txt 437.txt 528.txt 619.txt 71.txt 800.txt 892.txt 983.txt
165.txt 256.txt 347.txt 438.txt 529.txt 62.txt 710.txt 801.txt 893.txt 984.txt
166.txt 257.txt 348.txt 439.txt 53.txt 620.txt 711.txt 802.txt 894.txt 985.txt
167.txt 258.txt 349.txt 44.txt 530.txt 621.txt 712.txt 803.txt 895.txt 986.txt
168.txt 259.txt 35.txt 440.txt 531.txt 622.txt 713.txt 804.txt 896.txt 987.txt
169.txt 26.txt 350.txt 441.txt 532.txt 623.txt 714.txt 805.txt 897.txt 988.txt
17.txt 260.txt 351.txt 442.txt 533.txt 624.txt 715.txt 806.txt 898.txt 989.txt
170.txt 261.txt 352.txt 443.txt 534.txt 625.txt 716.txt 807.txt 899.txt 99.txt
171.txt 262.txt 353.txt 444.txt 535.txt 626.txt 717.txt 808.txt 9.txt 990.txt
172.txt 263.txt 354.txt 445.txt 536.txt 627.txt 718.txt 809.txt 90.txt 991.txt
173.txt 264.txt 355.txt 446.txt 537.txt 628.txt 719.txt 81.txt 900.txt 992.txt
174.txt 265.txt 356.txt 447.txt 538.txt 629.txt 72.txt 810.txt 901.txt 993.txt
175.txt 266.txt 357.txt 448.txt 539.txt 63.txt 720.txt 811.txt 902.txt 994.txt
176.txt 267.txt 358.txt 449.txt 54.txt 630.txt 721.txt 812.txt 903.txt 995.txt
177.txt 268.txt 359.txt 45.txt 540.txt 631.txt 722.txt 813.txt 904.txt 996.txt
178.txt 269.txt 36.txt 450.txt 541.txt 632.txt 723.txt 814.txt 905.txt 997.txt
179.txt 27.txt 360.txt 451.txt 542.txt 633.txt 724.txt 815.txt 906.txt 998.txt
18.txt 270.txt 361.txt 452.txt 543.txt 634.txt 725.txt 816.txt 907.txt 999.txt
180.txt 271.txt 362.txt 453.txt 544.txt 635.txt 726.txt 817.txt 908.txt a
181.txt 272.txt 363.txt 454.txt 545.txt 636.txt 727.txt 818.txt 909.txt a.txt
182.txt 273.txt 364.txt 455.txt 546.txt 637.txt 728.txt 819.txt 91.txt b.txt
183.txt 274.txt 365.txt 456.txt 547.txt 638.txt 729.txt 82.txt 910.txt c.txt
184.txt 275.txt 366.txt 457.txt 548.txt 639.txt 73.txt 820.txt 911.txt seq
185.txt 276.txt 367.txt 458.txt 549.txt 64.txt 730.txt 821.txt 912.txt test.txt
186.txt 277.txt 368.txt 459.txt 55.txt 640.txt 731.txt 822.txt 913.txt
187.txt 278.txt 369.txt 46.txt 550.txt 641.txt 732.txt 823.txt 914.txt
188.txt 279.txt 37.txt 460.txt 551.txt 642.txt 733.txt 824.txt 915.txt
189.txt 28.txt 370.txt 461.txt 552.txt 643.txt 734.txt 825.txt 916.txt
[oracle@CentOS tmp]$
查看文件内容:cat
[root@CentOS6 tmp]# cat -n t1.txt
1 test
[root@CentOS6 tmp]# cat t1.txt
test
[root@CentOS6 tmp]# cat t2.txt
test1
[root@CentOS6 tmp]# cat t1.txt t2.txt >t3.txt
[root@CentOS6 tmp]# cat t3.txt
test
test1
[root@CentOS6 tmp]# cat /dev/null > c.log
[root@CentOS6 tmp]# cat c.log
[root@CentOS6 tmp]#
想文件中添加内容
[oracle@CentOS tmp]$ vi test.txt
hello word
~
[oracle@CentOS tmp]$ cat test.txt
hello word
[oracle@CentOS tmp]$ echo "go" > test.txt
[oracle@CentOS tmp]$ cat test.txt
go
[oracle@CentOS tmp]$ echo "test" >> test.txt
[oracle@CentOS tmp]$ cat test.txt
go
test
echo:回显字符-n不换行,-e可以用转义字符
[root@CentOS6 tmp]# echo hello
hello
[root@CentOS6 tmp]# echo -n hello
hello[root@CentOS6 tmp]#
[root@CentOS6 tmp]# echo -e "hello\tworld"
hello world
一个大于号是将文件原先内容清空后写入内容,两个大于号是在文件中追加内容
清空文件
[oracle@CentOS tmp]$ >test.txt
[oracle@CentOS tmp]$ cat test.txt
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ >test.txt
[oracle@CentOS tmp]$ cat test.txt
[oracle@CentOS tmp]$ cat >test.txt
test to
[oracle@CentOS tmp]$ cat test.txt
test to
另一种方式
[oracle@CentOS tmp]$ rm test.txt
[oracle@CentOS tmp]$ cat >>test.txt<<eof
> test test
> eof
[oracle@CentOS tmp]$ cat test.txt
test test
[oracle@CentOS tmp]$
其中eof可以使任意成对字符
[oracle@CentOS tmp]$ cat >test.txt<<ppp
> test ppp
> ppp
[oracle@CentOS tmp]$ cat test.txt
test ppp
[oracle@CentOS tmp]$
拷贝文件命令
[oracle@CentOS tmp]$ mkdir data
[oracle@CentOS tmp]$ cp test.txt ./data/
[oracle@CentOS tmp]$ ls ./data/
test.txt
[oracle@CentOS tmp]$
拷贝目录
[oracle@CentOS tmp]$ ll
total 4
drwxr-xr-x 3 oracle dba 15 Aug 5 13:22 a
drwxr-xr-x 2 oracle dba 22 Aug 6 09:49 data
-rw-r--r-- 1 oracle dba 9 Aug 5 22:27 test.txt
[oracle@CentOS tmp]$ cp -ap ./a ./data
[oracle@CentOS tmp]$ tree data
data
|-- a
| `-- b
| `-- c
`-- test.txt
3 directories, 1 file
[oracle@CentOS tmp]$
查看执行过的命令
[oracle@CentOS tmp]$ history
1 su - root
2 ll
移动目录
[oracle@CentOS tmp]$ ll
total 4
drwxr-xr-x 3 oracle dba 15 Aug 5 13:22 a
drwxr-xr-x 3 oracle dba 31 Aug 6 10:15 data
-rw-r--r-- 1 oracle dba 9 Aug 5 22:27 test.txt
[oracle@CentOS tmp]$ mv data ./a
[oracle@CentOS tmp]$ tree a
a
|-- b
| `-- c
`-- data
|-- a
| `-- b
| `-- c
`-- test.txt
6 directories, 1 file
[oracle@CentOS tmp]$
删除文件,删除目录
[oracle@CentOS tmp]$ ll
total 4
drwxr-xr-x 4 oracle dba 27 Aug 6 10:19 a
-rw-r--r-- 1 oracle dba 9 Aug 5 22:27 test.txt
[oracle@CentOS tmp]$ rm test.txt
[oracle@CentOS tmp]$ ll
total 0
drwxr-xr-x 4 oracle dba 27 Aug 6 10:19 a
[oracle@CentOS tmp]$ rm -r a
[oracle@CentOS tmp]$ ll
total 0
[oracle@CentOS tmp]$
返回到上一级目录
[oracle@CentOS tmp]$ pwd
/home/oracle/tmp
[oracle@CentOS tmp]$ cd ../
[oracle@CentOS ~]$ pwd
/home/oracle
[oracle@CentOS ~]$
过滤文件信息,去掉不想显示的项
grep -v排除不想看的字符 -i忽略大小写
[oracle@CentOS tmp]$ cat >test.txt<<ff
> centos
> redhat
> ff
[oracle@CentOS tmp]$ cat test.txt
centos
redhat
[oracle@CentOS tmp]$ cat test.txt | grep -v redhat
centos
[oracle@CentOS tmp]$
或者这么写
[oracle@CentOS tmp]$ grep -v redhat test.txt
centos
[oracle@CentOS tmp]$
这样写也行
[oracle@CentOS tmp]$ head -1 test.txt
centos
[oracle@CentOS tmp]$
grep命令
[oracle@CentOS tmp]$ grep redhat test.txt
redhat
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ grep 1521 /etc/services
ncube-lm 1521/tcp # nCube License Manager
ncube-lm 1521/udp # nCube License Manager
[oracle@CentOS tmp]$
sed命令
[oracle@CentOS tmp]$ sed -e '/redhat/d' test.txt
centos
[oracle@CentOS tmp]$ sed -n /redhat/p test.txt
redhat
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ sed -n /[^redhat]/p test.txt
centos
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ awk -n /[^redhat]/ test.txt
centos
[oracle@CentOS tmp]$
拷贝文件时不提示直接覆盖
[oracle@CentOS tmp]$ mkdir a
[oracle@CentOS tmp]$ mkdir b
[oracle@CentOS tmp]$ cd a
[oracle@CentOS a]$ touch test.txt
[oracle@CentOS a]$ cd ../b
[oracle@CentOS b]$ touch test.txt
[oracle@CentOS b]$ \cp -f ./test.txt ../a/test.txt
[oracle@CentOS b]$ /bin/cp -f ./test.txt ../a/test.txt
[oracle@CentOS b]$
查看命令别名
[oracle@CentOS b]$ alias
alias asmcmd='rlwrap asmcmd'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias lsnrctl='rlwrap lsnrctl'
alias sqlplus='rlwrap sqlplus'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[oracle@CentOS b]$
cp、mv命令在没有-i参数的情况下是不会提示是否删除的
使用\和全路径都是为了屏蔽别名
别名一般存放在家目录下的.bashrc文件中
[oracle@CentOS b]$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/grid
export ORACLE_OWNER=oracle
export ORACLE_SID=+ASM
export ORACLE_TERM=vt100
export THREADS_FLAG=native
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LANG=en_us
alias sqlplus='rlwrap sqlplus'
alias lsnrctl='rlwrap lsnrctl'
alias asmcmd='rlwrap asmcmd'
只看文件中的制定行
用序列生成文件
[oracle@CentOS tmp]$ seq 100 > test.txt
[oracle@CentOS tmp]$ cat test.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ tail -2 test.txt
99
100
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ head -30 test.txt | tail
21
22
23
24
25
26
27
28
29
30
[oracle@CentOS tmp]$
另外几种写法
[oracle@CentOS tmp]$ sed -n '20,30p' test.txt
20
21
22
23
24
25
26
27
28
29
30
[oracle@CentOS tmp]$
[oracle@CentOS tmp]$ awk '{if(NR>19 && NR<31) print $1}' test.txt
20
21
22
23
24
25
26
27
28
29
30
[oracle@CentOS tmp]$
查找命令
[root@CentOS ~]# find /etc/ -type f -name "services"
/etc/services
[root@CentOS ~]# find /etc/ -type f -name "serv*"
/etc/services
/etc/xdg/menus/server-settings.menu
删除的另一种写法
[oracle@CentOS ~]$ find ./tmp/ -name "test.txt" -exec rm -f {} \;
删除七天前的文件
[oracle@CentOS ~]$ find ./tmp/ -name "test.txt" -mtime +7 -exec rm -f {} \;
[oracle@CentOS ~]$ ls ./tmp/
a b
[oracle@CentOS ~]$ find ./tmp/ -name "test.txt" -mtime +7|xargs rm -f
删除目录
[oracle@CentOS ~]$ find ./ -type d -name "tmp" -mtime +7|xargs rm -rf
也可以加入排除选项
[root@CentOS6 tmp]# find . -type f ! -name "t1.txt" -exec ls -l {} \;
-rw-r--r--. 1 root root 6 8月 8 05:14 ./t2.txt
-rw-r--r--. 1 root root 11 8月 8 22:44 ./t3.txt
-rw-r--r--. 1 root root 0 8月 8 22:47 ./c.log
[root@CentOS6 ~]# uname -r
2.6.32-358.el6.x86_64
[root@CentOS6 ~]# cat /etc/redhat-release
CentOS release 6.10 (Final)
[root@CentOS6 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 8G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 512M 0 part [SWAP]
└─sda3 8:3 0 7.3G 0 part /
文本比较工具:diff vimdiff
[root@CentOS6 tmp]# echo test >t1.txt
[root@CentOS6 tmp]# echo test1 >t2.txt
[root@CentOS6 tmp]# diff t1.txt t2.txt
1c1
< test
---
> test1
[root@CentOS6 tmp]#
[root@CentOS6 tmp]# vimdiff t1.txt t2.txt
还有 2 个文件等待编辑
test | test1
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
t1.txt 1,1 全部 t2.txt 1,1 全部
{}的用法:花括号可以指定一组序列,按照格式执行命令,比如:
[root@CentOS6 tmp]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@CentOS6 tmp]# mkdir {1..10}
[root@CentOS6 tmp]# ls
1 10 2 3 4 5 6 7 8 9 t1.txt t2.txt
[root@CentOS6 tmp]#
seq序列中,默认情况以回车作为间隔符,但是可以用-s指定序列间隔符号
[root@CentOS6 tmp]# seq -s " " 20 30
20 21 22 23 24 25 26 27 28 29 30
[root@CentOS6 tmp]# ls
1 10 2 20 21 22 23 24 25 26 27 28 29 3 30 4 5 6 7 8 9 t1.txt t2.txt
[root@CentOS6 tmp]#
其中的命令我们用``括起来表示
几种查看文件行号的方法
[test@CentOS6 tnp]$ nl test.txt
1 Port 52113 #更改端口..........
2 PermitRootLogin no #不允许root用户远程登录##
3 PermitEmptyPasswords no #不允许空密码用户登录##
4 UseDNS no #禁止DNS解析##
[test@CentOS6 tnp]$ cat -n ./test.txt
1 Port 52113 #更改端口..........
2 PermitRootLogin no #不允许root用户远程登录##
3 PermitEmptyPasswords no #不允许空密码用户登录##
4 UseDNS no #禁止DNS解析##
vi编辑器命令行模式输入 :set nu
[test@CentOS6 tnp]$ vi ./test.txt
1 Port 52113 #更改端口..........
2 PermitRootLogin no #不允许root用户远程登录##
3 PermitEmptyPasswords no #不允许空密码用户登录##
4 seDNS no #禁止DNS解析##
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:set nu
[test@CentOS6 tnp]$ grep -n . ./test.txt
1:Port 52113 #更改端口..........
2:PermitRootLogin no #不允许root用户远程登录##
3:PermitEmptyPasswords no #不允许空密码用户登录##
4:UseDNS no #禁止DNS解析##
5:1111
6:1111
7:1111
[test@CentOS6 tnp]$ less -N test.txt
1 Port 52113 #更改端口..........
2 PermitRootLogin no #不允许root用户远程登录##
3 PermitEmptyPasswords no #不允许空密码用户登录##
4 UseDNS no #禁止DNS解析##
5 1111
6 1111
7 1111
三种实时更新文件内容的命令
[test@CentOS6 tnp]$ tail -f test.txt
Port 52113 #更改端口..........
PermitRootLogin no #不允许root用户远程登录##
PermitEmptyPasswords no #不允许空密码用户登录##
UseDNS no #禁止DNS解析##
[test@CentOS6 tnp]$ tail -F test.txt
Port 52113 #更改端口..........
PermitRootLogin no #不允许root用户远程登录##
PermitEmptyPasswords no #不允许空密码用户登录##
UseDNS no #禁止DNS解析##
[test@CentOS6 tnp]$ tailf ./test.txt
Port 52113 #更改端口..........
PermitRootLogin no #不允许root用户远程登录##
PermitEmptyPasswords no #不允许空密码用户登录##
UseDNS no #禁止DNS解析##
设置开机自动启动服务
[test@CentOS6 tnp]$ LANG=en
[test@CentOS6 tnp]$ chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@CentOS6 ~]# chkconfig --level 245 sshd off
[root@CentOS6 ~]# chkconfig --list sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
也可以在配置文件中增加启动条目
[root@CentOS6 ~]# echo "/etc/init.d/sshd start" >> /etc/rc.local
打包(生成压缩文件)
test@CentOS6 ~]$ tar acvf tnp.tar.gz ./tnp
./tnp/
./tnp/新建文本文档.txt
[test@CentOS6 ~]$ ll
总用量 2
drwxrwxr-x. 2 test test 4096 8月 13 16:21 tnp
-rw-rw-r-- 1 test test 193 8月 13 16:58 tnp.tar.gz
解压文件
[test@CentOS6 ~]$ mv tnp tnpp
[test@CentOS6 ~]$ tar zxvf tnp.tar.gz
./tnp/
./tnp/新建文本文档.txt
[test@CentOS6 ~]$ ll
drwxrwxr-x 2 test test 4096 8月 13 16:21 tnp
drwxrwxr-x. 2 test test 4096 8月 13 16:21 tnpp
-rw-rw-r-- 1 test test 193 8月 13 17:00 tnp.tar.gz
[test@CentOS6 ~]$
打包排除默写文件
[test@CentOS6 ~]$ rm *.gz
[test@CentOS6 ~]$ cd tnp
[test@CentOS6 tnp]$ ll
总用量 4
-rw-r--r-- 1 test test 27 8月 13 16:21 新建文本文档.txt
[test@CentOS6 tnp]$ touch test.txt
[test@CentOS6 tnp]$ cd ../
[test@CentOS6 ~]$ tar zcvf tnp.tar.gz ./tnp --exclude=tnp/test.txt
./tnp/
./tnp/新建文本文档.txt
[test@CentOS6 ~]$ ll
总用量 16
drwxrwxr-x 2 test test 4096 8月 13 17:08 tnp
drwxrwxr-x. 2 test test 4096 8月 13 16:21 tnpp
-rw-rw-r-- 1 test test 193 8月 13 17:10 tnp.tar.gz
[test@CentOS6 ~]$ rm -r tnp
[test@CentOS6 ~]$ tar xf tnp.tar.gz
./tnp/
./tnp/新建文本文档.txt
[test@CentOS6 ~]$ ll
总用量 16
drwxrwxr-x 2 test test 4096 8月 13 17:08 tnp
drwxrwxr-x. 2 test test 4096 8月 13 16:21 tnpp
-rw-rw-r-- 1 test test 193 8月 13 17:10 tnp.tar.gz
[test@CentOS6 ~]$ cd tnp
[test@CentOS6 tnp]$ ll
总用量 4
-rw-r--r-- 1 test test 27 8月 13 16:21 新建文本文档.txt
解压到指定目录
[test@CentOS6 ~]$ tar xvf tnp.tar.gz -C ./vv/
./tnp/
./tnp/新建文本文档.txt
[test@CentOS6 ~]$ ll ./vv/tnp/
总用量 4
-rw-r--r-- 1 test test 27 8月 13 16:21 新建文本文档.txt
不解压看压缩包内容
[test@CentOS6 ~]$ tar tf tnp.tar.gz
./tnp/
./tnp/新建文本文档.txt
用另一种方式进行打包
[test@CentOS6 ~]$ tar jcvf vv.tar.bz ./vv
./vv/
./vv/tnp/
./vv/tnp/新建文本文档.txt
[test@CentOS6 ~]$ ll
总用量 16
drwxrwxr-x 3 test test 4096 8月 13 11:09 test
-rw-rw-r-- 1 test test 193 8月 13 17:10 tnp.tar.gz
drwxrwxr-x 3 test test 4096 8月 13 20:25 vv
-rw-rw-r-- 1 test test 220 8月 13 20:34 vv.tar.bz
cut命令:截取字符串,-d指定分隔符,-f指定取字符串的列,-c指定字符
[test@CentOS6 ~]$ echo "this is a test" > test.txt
[test@CentOS6 ~]$ cat test.txt
this is a test
[test@CentOS6 ~]$ cut -d " " -f 2,4 test.txt
is test
我们指定字符试试
[test@CentOS6 ~]$ cut -c 6-8,11- test.txt
is test
如果文本类型比较复杂,可以用awk
[test@CentOS6 ~]$ cat test.txt
this is a test,show you the output.
[test@CentOS6 ~]$ awk -F '[ ,]' '{print $3}' test.txt
a
[test@CentOS6 ~]$ awk -F '[ ,]' '{print $3" "$6}' test.txt
a you
也可以用$NF选取最后一列
[test@CentOS6 ~]$ awk -F '[ ,]' '{print $3" "$NF}' test.txt
a output.
wc命令,查看文件有多少行
[test@CentOS6 ~]$ wc -l /etc/services
10774 /etc/services
[test@CentOS6 ~]$ cat -n /etc/services | tail -1
10774 iqobject 48619/udp # iqobject
[test@CentOS6 ~]$
[test@CentOS6 ~]$ sed -n '$=' /etc/services
10774
[test@CentOS6 ~]$ awk '{print NR}' /etc/services | tail -1
10774
[test@CentOS6 ~]$ grep -n $ /etc/services | tail -1
10774:iqobject 48619/udp # iqobject
wc命令通常用在查看进程数量上
[test@CentOS6 ~]$ ps -ef | grep sshd
root 1117 1 0 20:23 ? 00:00:00 /usr/sbin/sshd
root 1185 1117 0 20:24 ? 00:00:00 sshd: test [priv]
test 1187 1185 0 20:24 ? 00:00:00 sshd: test@pts/0
test 1328 1188 0 21:19 pts/0 00:00:00 grep sshd
[test@CentOS6 ~]$
[test@CentOS6 ~]$ ps -ef | grep sshd | wc -l
4
grep过滤
[test@CentOS6 ~]$ grep -E "3306|1521" /etc/services
mysql 3306/tcp # MySQL
mysql 3306/udp # MySQL
ncube-lm 1521/tcp # nCube License Manager
ncube-lm 1521/udp # nCube License Manager
[test@CentOS6 ~]$ egrep "3306|1521" /etc/services --color
mysql 3306/tcp # MySQL
mysql 3306/udp # MySQL
ncube-lm 1521/tcp # nCube License Manager
ncube-lm 1521/udp # nCube License Manager
ls命令查看完整时间格式
[root@CentOS6 ~]# ls -l --full-time
总用量 44
-rw-------. 1 root root 1149 2018-08-07 01:00:24.840998270 +0800 anaconda-ks.cfg
-rw-r--r--. 1 root root 23833 2018-08-07 01:00:23.470998271 +0800 install.log
-rw-r--r--. 1 root root 7688 2018-08-07 00:59:37.404998323 +0800 install.log.syslog
drwxr-xr-x. 12 root root 4096 2018-08-08 22:47:48.561079067 +0800 tmp
[root@CentOS6 ~]# ls -l --time-style=long-iso
总用量 44
-rw-------. 1 root root 1149 2018-08-07 01:00 anaconda-ks.cfg
-rw-r--r--. 1 root root 23833 2018-08-07 01:00 install.log
-rw-r--r--. 1 root root 7688 2018-08-07 00:59 install.log.syslog
drwxr-xr-x. 12 root root 4096 2018-08-08 22:47 tmp
查看文件详细信息
[root@CentOS6 ~]# stat install.log
File: "install.log"
Size: 23833 Blocks: 56 IO Block: 4096 普通文件
Device: 803h/2051d Inode: 15 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-08-07 00:56:30.454998539 +0800
Modify: 2018-08-07 01:00:23.470998271 +0800
Change: 2018-08-07 01:00:30.637998262 +0800
sed命令
1.过滤
[root@CentOS6 home]# sed -n '/test/' /etc/passwd
sed: -e expression #1, char 6: missing command
[root@CentOS6 home]# sed -n "/test/" /etc/passwd
sed: -e expression #1, char 6: missing command
[root@CentOS6 home]# sed -n /test/ /etc/passwd
sed: -e expression #1, char 6: missing command
这里-n是取消默认输出,p是打印,d是排除选项,-i直接更改文件
test@CentOS6 ~]$ echo 'aaa' > a.txt
[test@CentOS6 ~]$ echo 'bbb' >> a.txt
[test@CentOS6 ~]$ echo 'aabb' >> a.txt
[test@CentOS6 ~]$ more a.txt
aaa
bbb
aabb
[test@CentOS6 ~]$ sed '/a/d' a.txt
bbb
[test@CentOS6 ~]$ more a.txt
aaa
bbb
aabb
[test@CentOS6 ~]$ sed -i '/aa/d' a.txt
[test@CentOS6 ~]$ more a.txt
bbb
2.替换
s是替换,g是全局
[test@CentOS6 ~]$ echo 'aa'>>a.txt
[test@CentOS6 ~]$ echo 'aabb'>>a.txt
[test@CentOS6 ~]$ echo 'aacc'>>a.txt
[test@CentOS6 ~]$ more a.txt
bbb
aa
aabb
aacc
[test@CentOS6 ~]$ sed 's#a#c#g' a.txt
bbb
cc
ccbb
cccc
[test@CentOS6 ~]$ more a.txt
bbb
aa
aabb
aacc
3.打印
[test@CentOS6 ~]$ seq 10 >> a.txt
[test@CentOS6 ~]$ more a.txt
bbb
aa
aabb
aacc
1
2
3
4
5
6
7
8
9
10
打印文件2到5行
[test@CentOS6 ~]$ sed -n '2,5p' a.txt
aa
aabb
aacc
1
也可以用~表示步长
[test@CentOS6 ~]$ sed -n '1~2p' a.txt
bbb
aabb
1
3
5
7
9
在seq中也有这样的写法
[test@CentOS6 ~]$ seq 1 3 10
1
4
7
10