第二次作业(系统管理)

系统基础管理和维护
1.常用命令
放大终端 : “ctrl”+“shift”+"+"(有的电脑"ctrl"+"+")
切换目录: cd ~
查看当前目录: pwd
显示 链接文件的真实路径: pwd -P
查看当前目录的文件和子目录: ls
显示所有文件包括隐藏文件: ls -a
显示影藏文件: ls -A
显示的是链接路径下的真实文件: ls -L
清屏: clear 或者ctrl+l
新建文件夹(目录): mkdir +文件名
编辑文件: vi +文件名
删除文件: rm
使用管理员权限: su
进入etc目录: cd /etc
退出命令窗口: exit
关闭虚拟机: halt
将文件移动到某目录下: mv +文件名+目录名
切换中英文输入法: ctrl + 空格
运行程序: ./test
最后一次历史命令: !$
用绝对路径,表示index.html ;/root/test/app/index.html
用相对路径,表示index.html ;app/index.html

2.tab 命令补全的原理
:vi ,系统根据环境变量$PATH去文件下寻找命令

3.shell命令操作
ctrl + a :跳到命令最前面
ctrl + e:跳到命令最后
ctrl +k:删除光标后的内容
ctrl+u:删除光标前的内容
ctrl+l:清屏
ctrl+r:搜索历史命令。
ctrl +c:停止当前正在运行的程序

4.vim操作
编辑模式:i 在当前光标下插入
O 在上一行插入
o 在下一行输入
命令模式: :q 退出
:wq 保存后退出
:q ! 不保存退出
:w 保存
5.历史命令(history)
! 10 :第10行历史命令(!+历史命令行数)
!$ :执行最后一次历史命令
help history :查看帮助历史
history -w:把历史命令同步到历史命令文件中
echo HISTFILE:查看历史命令文件位置

如何设置历史命令的保存数量:
echo $HISTSIZE
vim /etc/profile
HISTSIZE=1000
:wq
source /etc/profile

如何设置历史命令的时间戳,和使用用户
vim /etc/profile
export HISTTIMEFORMAT="%F %T whoami "
:wq
source /etc/profile

6.设置,定义别名 alias
root@localhost ~]# alias net=“vim /etc/sysconfig/network-scripts/ifcfg-eth0” #定义别名
[root@localhost ~]# unalias net #取消别名
[root@localhost ~]# \net #跳过别名

让别名永久生效
[root@localhost ~]# vim /etc/bashrc
alias net=“vim /etc/sysconfig/network-scripts/ifcfg-eth0”
:wq
[root@localhost ~]# source /etc/bashrc

7.#!/bin/bash
#全局变量,作用于对当前文件
who=whoami
test(){
IP=‘192.168.254.125’ #局部变量,作用于一行代码,或者代码块
#ping $IP
echo $who
}
#test
ping $IP

环境变量:正对于当前的shell下的所有进程及子进程都生效

8.标准输入,输出
标准输出到文件:> filename [root@localhost ~]# ls >file1
错误输出到文件:2>eername [root@localhost ~]# ls 2>err

将标注输出到filename文件,错误输出到errname
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ks1.cfg > ceu 2>err
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ks1.cfg &>file4
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ks1.cfg >file5 2>&1

[root@localhost ~]# cat > file3 <<EOF

123
abc
EOF

标准输入到文件file3
[root@localhost ~]# ll > test1 [root@localhost ~]# ll >>test1

[root@localhost ~]# fdisk 2>test2
[root@localhost ~]# fdisk 2>>test2

[root@localhost ~]# ll anaconda-ks.cfg anaconda-ks1.cfg >test3 2>test4
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ks1.cfg &>test5
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ks1.cfg >>test5 2>&1
9.特殊符号,通配符
“|” 管道符:把上个命令的执行结果交给了 下一个命令继续处理 ll |grep f (找出 ll 文件下的所有有 f 的文件)
“…” 代表上一级目录[root@localhost ~]# cd …
“./” 多条命令的分割 [root@localhost ~]# cd …/…/
“``” 把内容还原成命令 [root@localhost ~]# a=ls ;echo $a
"" 匹配所有[root@localhost ~]# ls f (匹配出ls文件下的以 f 开头的所有文件)
“?” 匹配单个任意字符
在这里插入图片描述

10.日期设置date
时钟显示格式的拼接:[root@localhost ~]# date "+%Y-%m-%d %H:%M:%S
修改系统时间: [root@localhost ~]# date -s 00:00:00
显示时区: [root@localhost ~]# date +%Z
扩展:
#!/bin/bash
time=date "+%H"
echo $time.log

11.wget命令(wget是一个从网上自动下载文件的自由工具)
wget -b: 后台下载模式
wget -o: 下载到指定目录
wget -c: 断点续传
wget -t: 最大尝试次数
wget -p: 下载页面内的所有资源,包括图片,视频等。
wget -r: 递归下载
[root@localhost ~]# yum install wget
Index of /centos/7.6.1810/extras/x86_64/Packages/
[root@localhost ~]# wget http://mirrors.sohu.com/centos/7.6.1810/extras/x86_64/Packages/centos-release-scl-2-3.el7.centos.noarch.rpm
[root@localhost src]# wget -b -c http://mirrors.sohu.com/centos/7.6.1810/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm /usr/local/src/
[root@localhost src]# wget -P /usr/local/src/ http://mirrors.sohu.com/centos/7.6.1810/extras/x86_64/Packages/ansible-2.4.2.0-2.el7.noarch.rpm

12.free命令
free-m: 内存占用磁盘大小(有单位)
free -h: 内存占用磁盘大小(无单位)
[root@localhost src]# free -m
[root@localhost src]# free -h
total used free shared buff/cache available
Mem: 976M 132M 533M 6.7M 311M 663M
Swap: 2.0G 0B 2.0G
free mam: 内存
free swap: 在磁盘格化的一个和内存格式相同的分区
free buff: 数据读的缓存空间
free cache: 数据写的缓存空间
chakan
13.uname命令
uname -a: 查看系统内核信息
uname -r:
reboot: 重启
shut down -h now: 立即关机

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值