linux基本指令(下)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux基本指令(下)相关的知识,希望对你有一定的参考价值。
(文章目录)
1.sort 指令
[yzq@VM-8-8-centos 6.6]$ vim 888.txt
[yzq@VM-8-8-centos 6.6]$ cat 888.txt
1111
2222
3333
4444
444444
333333
8888
- 这里vim编辑器的用法先不用了解,记住 使用 a 后输入你想要打印的内容
- 最后使用 ESC :wq 退出vim编辑器
sort ——升序
[yzq@VM-8-8-centos 6.6]$ sort 888.txt
1111
2222
3333
333333
4444
444444
8888
- sort排序规则:从左向右,每行的第一个字母开始按ascii值进行比较,谁的ascii值小就放在前面
sort -r ——降序
[yzq@VM-8-8-centos 6.6]$ sort -r 888.txt
8888
444444
4444
333333
3333
2222
1111
sort +文件 | uniq ——去重
[yzq@VM-8-8-centos 6.6]$ vim 888.txt
[yzq@VM-8-8-centos 6.6]$ cat 888.txt
1111
1111
2222
2222
3333
3333
- 这里vim编辑器的用法先不用了解,记住 使用 a 后输入你想要打印的内容
- 最后使用 ESC :wq 退出vim编辑器
[yzq@VM-8-8-centos 6.6]$ sort 888.txt | uniq
1111
2222
3333
2. find - name 指令
[yzq@VM-8-8-centos 6.6]$ find ~ -name test.c
/home/mydir/game/the-first-stu-wirting/通讯录 文件/通讯录 文件/test.c
/home/mydir/game/the-first-stu-wirting/文件/文件/test.c
/home/mydir/lesson5/test.c
- ~ 代表当前目录的家目录
- find ~ -name test.c 代表 在家目录中test.c文件全部被查找到
3. which 指令
[yzq@VM-8-8-centos 6.6]$ which pwd
/usr/bin/pwd
alias ——起别名
[yzq@VM-8-8-centos 6.6]$ which ls
alias ls=ls --color=auto
/usr/bin/ls
[yzq@VM-8-8-centos 6.6]$ ls -la -i -n
total 12
786436 drwxrwxr-x 2 1002 1002 4096 Nov 23 10:41 .
657483 drwx------ 15 1002 1002 4096 Nov 23 10:41 ..
786446 -rw-rw-r-- 1 1002 1002 31 Nov 23 10:41 888.txt
[yzq@VM-8-8-centos 6.6]$ alias myls=ls -la -i -n
[yzq@VM-8-8-centos 6.6]$ myls
total 12
786436 drwxrwxr-x 2 1002 1002 4096 Nov 23 10:41 .
657483 drwx------ 15 1002 1002 4096 Nov 23 10:41 ..
786446 -rw-rw-r-- 1 1002 1002 31 Nov 23 10:41 888.txt
- ls -la -i -n 输出的结果 与起别名后 myls 的结果相同
[yzq@VM-8-8-centos 6.6]$ which myls
alias myls=ls -la -i -n
/usr/bin/ls
4. whereis 指令
[yzq@VM-8-8-centos 6.6]$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
- 既找到 ls程序,又把程序配套的man手册对应的内容也显示出来了
5. grep指令
1.作用
[yzq@VM-8-8-centos 6.6]$ grep 88 test.txt
hello world [88]
hello world [188]
hello world [288]
hello world [388]
hello world [488]
hello world [588]
hello world [688]
hello world [788]
hello world [880]
hello world [881]
hello world [882]
hello world [883]
hello world [884]
hello world [885]
hello world [886]
hello world [887]
hello world [888]
hello world [889]
hello world [988]
2. grep -n
[yzq@VM-8-8-centos 6.6]$ grep -n 88 test.txt
89:hello world [88]
189:hello world [188]
289:hello world [288]
389:hello world [388]
489:hello world [488]
589:hello world [588]
689:hello world [688]
789:hello world [788]
881:hello world [880]
882:hello world [881]
883:hello world [882]
884:hello world [883]
885:hello world [884]
886:hello world [885]
887:hello world [886]
888:hello world [887]
889:hello world [888]
890:hello world [889]
989:hello world [988]
3.grep - v
[yzq@VM-8-8-centos 6.6]$ vim 888.txt
[yzq@VM-8-8-centos 6.6]$ cat 888.txt
aaaa
bbbb
cccc
AAAA
BBBB
CCCC
[yzq@VM-8-8-centos 6.6]$ grep aaaa -v 888.txt
bbbb
cccc
AAAA
BBBB
CCCC
- 除了包含 aaaa文本内容的显示全部出来
4. grep - i
[yzq@VM-8-8-centos 6.6]$ grep -i aaaa 888.txt
aaaa
AAAA
6 .zip指令
1. 安装
[yzq@VM-8-8-centos 6.6]$ yum install -y zip unzip
2. 打包
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test
[yzq@VM-8-8-centos ~]$ zip test.zip test
adding: test/ (stored 0%)
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.zip
3. 解包
[yzq@VM-8-8-centos ~]$ mv test.zip my
[yzq@VM-8-8-centos ~]$ cd my
[yzq@VM-8-8-centos my]$ ls
test.zip
[yzq@VM-8-8-centos my]$ unzip test.zip
Archive: test.zip
creating: test/
[yzq@VM-8-8-centos my]$ tree test
test
0 directories, 0 files
zip -r
6.6 9.9 dir game lesson5 mk mkdir my mybin test
[yzq@VM-8-8-centos ~]$ zip -r test.zip test
adding: test/ (stored 0%)
adding: test/makefile (deflated 16%)
adding: test/mytest (deflated 71%)
adding: test/mytest.c (deflated 38%)
adding: test/mytest_d (deflated 70%)
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.zip
[yzq@VM-8-8-centos ~]$ mv test.zip my
[yzq@VM-8-8-centos ~]$ cd my
[yzq@VM-8-8-centos my]$ ls
test test.zip
[yzq@VM-8-8-centos my]$ unzip test.zip
Archive: test.zip
inflating: test/makefile
inflating: test/mytest
inflating: test/mytest.c
inflating: test/mytest_d
[yzq@VM-8-8-centos my]$ tree test
test
|-- makefile
|-- mytest
|-- mytest.c
`-- mytest_d
0 directories, 4 files
4. unzip -d
6.6 9.9 dir game lesson5 mk mkdir my mybin test
[yzq@VM-8-8-centos ~]$ zip -r test.zip test
adding: test/ (stored 0%)
adding: test/makefile (deflated 16%)
adding: test/mytest (deflated 71%)
adding: test/mytest.c (deflated 38%)
adding: test/mytest_d (deflated 70%)
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.zip
[yzq@VM-8-8-centos ~]$ unzip test.zip -d 6.6
Archive: test.zip
creating: 6.6/test/
inflating: 6.6/test/makefile
inflating: 6.6/test/mytest
inflating: 6.6/test/mytest.c
inflating: 6.6/test/mytest_d
[yzq@VM-8-8-centos ~]$ cd 6.6
[yzq@VM-8-8-centos 6.6]$ ls
888.txt test test.txt
7. tar 指令
1.tar -czf ——打包
-
tar - c :创建一个新的归档文件即压缩包
-
tar - z : 使用打包的同时可以进行压缩
-
tar - f : 给归档文件一个名字
建议把 f 放在最后
-
tar -czf + 文件名.tgz +文件名
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test
[yzq@VM-8-8-centos ~]$ tar -czf test.tgz test
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.tgz
2.tar -xzf —— 解包
- tar -x 解开文件
tar -xzf 文件名.tgz
[yzq@VM-8-8-centos ~]$ tar -xzf test.tgz
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.tgz
[yzq@VM-8-8-centos ~]$ tree test
test
|-- makefile
|-- mytest
|-- mytest.c
`-- mytest_d
0 directories, 4 files
3.tar -ztvf ——直接查看压缩包内的内容
tar -ztvf +文件名.tgz
- tar -t 不解压 ,直接看压缩包中有什么
- tar -v :将文件显示更详细
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.tgz
[yzq@VM-8-8-centos ~]$ tar -ztvf test.tgz
drwxrwxr-x yzq/yzq 0 2022-11-23 06:37 test/
-rw-rw-r-- yzq/yzq 75 2022-10-15 18:29 test/makefile
-rwxrwxr-x yzq/yzq 8441 2022-11-23 06:37 test/mytest
-rw-rw-r-- yzq/yzq 278 2022-10-16 14:03 test/mytest.c
-rwxrwxr-x yzq/yzq 9648 2022-10-15 18:30 test/mytest_d
4. tar -xzf 文件名.tgz -C
tar -xzf 文件名.tgz -C
[yzq@VM-8-8-centos ~]$ tar czf test.tgz test
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.tgz
[yzq@VM-8-8-centos ~]$ tar -xzf test.tgz -C 6.6
[yzq@VM-8-8-centos ~]$ ls
6.6 9.9 dir game lesson5 mk mkdir my mybin test test.tgz
[yzq@VM-8-8-centos ~]$ cd 6.6
[yzq@VM-8-8-centos 6.6]$ ls
888.txt test test.txt
[yzq@VM-8-8-centos 6.6]$ tree test
test
|-- makefile
|-- mytest
|-- mytest.c
`-- mytest_d
0 directories, 4 files
8. bc 指令
[yzq@VM-8-8-centos ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty.
1+1
2
5*2
10
2.0*5.0
10.0
5.0/4.0
1
以上是关于linux基本指令(下)的主要内容,如果未能解决你的问题,请参考以下文章