linux基本命令和管理系统命令

1.1tab补全
* rm -rf 要删除的文件名:删除文件
* touch 要创建的文件名:创建文件
* mkdir 要创建的文件夹名:创建文件夹

  Tab一次,输入的内容能够唯一标识,直接跳出命令
           输入的内容不能唯一标识,再tab,显示出所有补全的命令
  Tab命令补全的原理:vi,系统根据环境变量$PATH去文件下寻找命令

1.2 shell命令操作

  • Ctrl+a 光标直接跳到最前面 Ctrl+e 光标直接跳到最后面

  • 想删除,Ctrl+k光标以后,Ctrl+u光标以前

  • 清屏,Ctrl+l

  • Ctrl+r,搜索历史命令

  • Ctrl+c,停止当前正在运行的程序
    1.3 vim操作
    编辑模式:i:在当前光标下插入
                     O:上一行插入
                      o:下一行插入
    命令行模式:退出q 强制退出q!
                          保存w 强制保存w!
                          x保存退出
                          set nu 设置行号
    1.4 history

  • !10 !+历史命令的列表行数

  • !$ 执行最后一次的历史命令

  • help history 查看帮助
    history -w把历史命令列表同步到历史命令文件中
    echo $HISTFILE查看历史命令位置

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

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

1.5 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

1.6 变量

#!/bin/bash

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

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

1.7 标准输入,输出

  • filename 标准输出到文件
    [root@localhost~]# ls >file1

  • 2>errname 错误输出到文件
    [root@localhost~]# mysql 2>err

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

    [root@localhost~]# cat > file3 <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-ksl.cfg >test3 2>test4
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ksl.cfg &>test5
[root@localhost ~]# ll anaconda-ks.cfg anaconda-ksl.cfg >>test5 2>&1

  扩展:
   echo  $? 判断上一条命令执行是否成功,若成功,返回0;失败,返回非0;如下图:
        192.168.1.35为可以ping通的地址,则显示为0;192.168.1.69为ping不通的地址,则显示为非0。

192.168.1.35为可以ping通的地址,则显示为0;192.168.1.69为ping不通的地址,则显示为非0,在这里插入图片描述

#!/bin/bash
IP=‘192.168.42.145’

ping -c1 $IP &>/dev/null
if [ $? -eq 0 ]
then
echo ‘tong,’
fi
在这里插入图片描述

1.8 特殊符号
1.符号

  • “|”:把上个命令的执行结果交给了下一个命令处理
    [root@localhost ~]# ll |grep err
    [root@localhost ~]# ip a |grep inet在这里插入图片描述

  • “tee”把过滤的结果打印到文件中

  • “…”代表上级目录
    [root@localhost test]# ll …/

  • “.”代表当前目录
    [root@localhost test]# ll ./ * “;”表示多条命令的分割
    [root@localhost test]# a=abc;echo $a * “``”把内容还原成命令
    [root@localhost test]# a=ls;echo $a

  • “*”匹配所有

  • *“?”匹配单个任意字符

2.系统管理的常用命令
ls

  • ls -a 显示的所有隐藏文件及目录,
  • ls -A 显示隐藏文件
  • ls -l ===> ll
  • ls :显示的是链接文件及链接路径,
  • ls -L显示的是链接路径下的真实文件
    相对路径,绝对路径,pwd

在这里插入图片描述

  • 用绝对路径表示 index.html ;/root/test/app/index.html

  • 用相对路径表示 index.html ;app/index.html

  • pwd 显示的是当前路径(快捷方式),pwd -P 显示的是链接文件的真实路径

  • cd -切换到上一次文件所在的路径

  • cd ~切换到用户的家目录

  • cd …/切换到上层目录

  • cd …/…/切换到上上层目录

  • 在这里插入图片描述

date

  • 时钟显示格式拼接:
    [root@localhost ~]# date “+%Y-%m-%d %H:%M:%S”
  • 修改系统时间:
    [root@localhost ~]# date -s 17:54:30
  • 显示时区:
    [root@localhost ~]# date +%Z
    具体如下图
    在这里插入图片描述
    拓展:
    #!/bin/bash
    Time=date “+%H”
    Echo $time.log

wget

[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
在这里插入图片描述
上图所示,先安装wget命令,若安装不成功输入mount /dev/sr0 /media 将光盘挂载到media上,然后下载yum源,若不成功输入vi /etc/resolv.conf进入文件,输入nameserver 加网关,保存退出,再次下载yum源。
-b 后台运行
-c端点续传
-P 指定下载路径

Uname:
[root@localhost ~]# uname -a 查看系统内核信息
加粗样式 [root@localhost ~]# uname -r
在这里插入图片描述

free:
[root@localhost ~]# free
在这里插入图片描述
[root@localhost ~]# free -m
在这里插入图片描述
[root@localhost ~]# free -h
在这里插入图片描述

^mem: 内存
^swap: 在磁盘上格式化的一个和内存格式相同的分区
^buffer: 数据读的缓存空间
^cache: 数据写的缓存空间

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值