Centos7(三)之基本的操作命令
基本的操作命令
1、centos终端
通过 tty 命令看到当前所属的虚拟终端
[[email protected] ~]# tty
/dev/pts/0
[[email protected] ~]# cd /dev/pts
[[email protected] pts]# ls
0 1 2 3 4 ptmx
不同虚拟终端之间通讯
echo nihao > /dev/pts/1
广播,所有终端 都能收到
wall “the system will be shutdown in 10 minutes”
2、认识shell
Shell 俗称壳,它提供了用户与内核进行交互操作的一种接口,它接收用户输入的命令并把它送入内核去执行 Shell 实际上是一个命令解释器,它通过解释用户输入的命令并把它传输给系统内核去执行。
区分内外部命令
[[email protected] /]# type cat
cat 是 /usr/bin/cat
[[email protected] /]# type pwd
pwd 是 shell 内嵌
查看所有shells的类型
[[email protected] /]# cat etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
3、基本的操作命令
pwd //查看所在的目录
[[email protected] /]# ls -l a.txt
-rw-r–r--. 1 root root 0 12月 13 23:40 a.txt
[[email protected] /]# ll a.txt
-rw-r–r--. 1 root root 0 12月 13 23:40 a.txt
第一个字符表示的是文件类型:
d:目录文件、 l:链接文件、 b:块设备文件 、c:字符设备文件、 p:管道文件、 -: 表示普通文件
查看隐藏文件
ls -a
只查看目录
ls -d /etc
ls -ld /etc
-S 以文件的大小进行排序
ls -lS /etc
4、别名的使用(alias)
alias vimens33=‘vi /etc/sysconfig/network-scripts/ifcfg-ens33’
vimens33
产出别名
unalias vimens33
设置永久别名
(只针对root)
vi /root/.bashrc //隐藏文件
alias vimenss33=“vi /etc/sysconfig/network-scripts/ifcfg-ens33” //插入
source /root/.bashrc
(全局使用)
vi /etc/bashrc
同理
5、history的使用
ctrl+r >>输入某条命令的关键字>>找出来对应的命令,按右光标键
history>>!数字 //执行历史命令中第 N 条命令
6、快捷键
ctrl + L 清屏
ctrl + R 搜索历史命令
!$ 引用上一个命令的最后一个参数
7、系统时间管理
两种时间
[[email protected] /]# hwclock
2019年12月14日 星期六 00时05分54秒 -10.010855 秒
[[email protected] /]# date
2019年 12月 14日 星期六 00:07:43 CST
-s 把时间设为字符串所描述的时间
[[email protected] /]# date -s “2018-11-2 22:30”
2018年 11月 02日 星期五 22:30:00 CST
[[email protected] /]# date “+%Y%m%d”
20181102
[[email protected] /]# date “+%Y-%m-%d %H:%M:%S”
2018-11-02 22:32:55
time 作用:一般用来测量一个命令的运行时间
[[email protected] /]# time ls -l /etc/
real 0m0.056s
user 0m0.016s
sys 0m0.040s
说明: real:实际使用时间 user:用户状态使用的时间 sys:内核状态使用的时间
8、关机命令(shutdown)
[[email protected] /]#shutdown -h +10 //10 分钟之后关机
[[email protected] /]#shutdown -h 23:30 //指定具体的时间点进行关机
[[email protected] /]#shutdown -r 22:22 #22:22 以后重启
[[email protected] /]#shutdown -c #撤销关机命令
9、启动级别
语法:init 0-6
0 系统停机模式,系统默认运行级别不能设置为 0,否则不能正常启动,机器关的
1 单用户模式,root 权限,用于系统维护,禁止远程登陆,就像 Windows 下的安全模式登录
2 多用户模式,没有 NFS 和网络支持
3 完整的多用户文本模式,有 NFS 和网络,登陆后进入控制台命令行模式
4 系统未使用
5 图形化模式,登陆后进入图形 GUI 模式,X Window 系
6 重启模式,默认运行级别不能设为 6,否则不能正常启动。运行 init 6 机器就会重启
init 0 //关机
init 3 //进入3级别字符界面
设置默认的运行界别
第 3 运行级用 multi-user.target 替代
第 5 运行级用 graphical.target 替代
设置默认第三启动级别
[[email protected] /]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
设置默认第五启动级别
[[email protected] /]# systemctl set-default graphical.target
查看当前级别
runlevel
systemctl get-default