linux(CentOS7) 命令操作
前言
linux 系统架构
- 硬件
- 系统内核
- 命令解析器
- 上层应用程序
初认命令行
- [当前用户@计算机名字~]#
- [当前用户@计算机名字~]$
#
为 root 用户,$普通用户
1
2
3
4
[root@Cc ~]# su yf
[yf@Cc root]$ su root
Password:
[root@Cc ~]#
bash Shell
别名
alias
创建别名,unalias
撤销别名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@Cc ~]# alias cc='ls -l'
[root@Cc ~]# cc
total 24
drwxr-xr-x 2 root root 4096 Dec 11 22:44 Cc
drwxr-xr-x 7 root root 4096 Nov 22 19:56 FileRecv
drwxr-xr-x 5 root root 4096 Nov 28 11:45 fileWehChat
drwxr-xr-x 19 root root 4096 Mar 3 15:45 gogs-repositories
drwxr-xr-x 17 root root 4096 Mar 18 13:51 lichaocheng
drwxr-xr-x 2 root root 4096 Mar 18 08:57 supervisord.d
[root@Cc ~]# unalias cc
[root@Cc ~]# cc
cc: fatal error: no input files
compilation terminated.
[root@Cc ~]#
历史命令使用
-
!!
上一个命令
-
找出特定字符命令
1
2
3
[root@Cc ~]# history | grep sou
1050 history | grep sou
[root@Cc ~]#
- ![num]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1050 history | grep sou
1051 history | grep ps
1052 ll
1053 history
[root@Cc ~]# !1052
ll
total 24
drwxr-xr-x 2 root root 4096 Dec 11 22:44 Cc
drwxr-xr-x 7 root root 4096 Nov 22 19:56 FileRecv
drwxr-xr-x 5 root root 4096 Nov 28 11:45 fileWehChat
drwxr-xr-x 19 root root 4096 Mar 3 15:45 gogs-repositories
drwxr-xr-x 17 root root 4096 Mar 18 13:51 lichaocheng
drwxr-xr-x 2 root root 4096 Mar 18 08:57 supervisord.d
[root@Cc ~]#
- 通配符使用
多个字符、任意字符、范围查找、
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@Cc ~]# ls /opt/go*
/opt/gomod:
Gin
/opt/gopath:
bin pkg src
[root@Cc ~]#
[root@Cc ~]# ls /bin/l?
/bin/ld /bin/ln /bin/lp /bin/ls
[root@Cc ~]#
[root@Cc ~]# ls [a-f]*
Cc:
fileWehChat:
2019-09 2019-10 2019-11
[root@Cc ~]# find /opt/ -name "cc"
/opt/lichaocheng.top/lichaocheng.top.server/.git/objects/cc
/opt/gopath/src/smtface/client_user_server/.git/objects/cc
/opt/gopath/src/google.golang.org/grpc/.git/objects/cc
/opt/client/bogl.lichaocheng.top/.git/objects/cc
[root@Cc ~]#
管道
标准输入输出
注意
ctrl+d
结束
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@Cc ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
IPADDR=172.24.40.83
NETMASK=255.255.192.0
ONBOOT=yes
GATEWAY=172.24.63.253
[root@Cc ~]# cat
lcc
lcc
yf
yf
cc
cc
[root@Cc ~]#
输入重定向
1
2
3
4
5
6
7
8
[root@Cc ~]# wc< /etc/sysconfig/network-scripts/ifcfg-eth0
5 5 87
[root@Cc ~]# cat< /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
IPADDR=172.24.40.83
NETMASK=255.255.192.0
ONBOOT=yes
GATEWAY=172.24.63.253
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@Cc ~]# cat <<<EEE
EEE
[root@Cc ~]#
[root@Cc ~]# cat <<CC
> 第一个输入
> 第二个输入
> exit^C
[root@Cc ~]# cat <<CC
第一个输入
第二个输入
> 第三个输入
> -bash: warning: here-document at line 50 delimited by end-of-file (wanted `CC')
第一个输入
第二个输入
第三个输入
- 正确的值追加到文件
1
2
3
4
5
6
7
8
9
[root@Cc ~]#
[root@Cc RedHad]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 23 21:59 readme.md
[root@Cc RedHad]# cat readme.md
[root@Cc RedHad]# ls -l ./ >> readme.md
[root@Cc RedHad]# cat readme.md
total 0
-rw-r--r-- 1 root root 0 Mar 23 21:59 readme.md
This post is licensed under
CC BY 4.0
by the author.