天天看点

系统管理维护与常用命令

一、系统管理和维护

1.1Tab补全

输入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! wq!

                       : x (保存退出)

                       : set nu

1.4 History命令

!10 !+历史命令

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

help history 查看帮助

history -w 把历史命令列表同步到历史命令文件中

echo $HISTFILE 查看历史命令文件位置

如何设置历史命令的保存数量

echo $HISTSIZE

vim /etc/profile

HISTSIZE=10

source /etc/profile

如何设置历史命令的时间戳和使用用户

vim /etc/profile

export HISTTIMEFORMAT="%F %T

whoami

"

source /etc/profile

1.5 alias

[[email protected] ~]# alias net=“vim /etc/sysconfig/network-scripts/ifcfg-eth0” #定义别名

[[email protected] ~]# unalias net      #取消别名

[[email protected] ~]# \net         #跳过别名

[[email protected] ~]# vim /etc/bashrc        #让别名永久生效

alias net=“vim /etc/sysconfig/network-scripts/ifcfg-eth0”

:wq

[[email protected] ~]# source /etc/bashrc

1.6 变量

#!/bin/bash

who=‘whoami’        #全局变量,作用于当前文件

test(){IP=‘192.168.254.125’         #局部变量,作用于一行代码,或者代码块

ping $IP

echo $who}

test

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

1.7 标准输入、输出

 >filename 标准输出到文件

[[email protected] ~]# ls >file1

2> errname 错误输出到文件

[[email protected] ~]# mysql 2>err

重定向:

三种方法将标准输出与错误输出放入同一个文件

 >filename 2>errname 将标准输出到filename文件,错误输出到errname

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ksl.cfg >ceu 2>err

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ksl.cfg &>file4

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ksl.cfg >file5 2> &1

标准输入到file3

[[email protected] ~]# ll > test1[[email protected] ~]# ll >> test1

[[email protected] ~]# fdisk 2>test2

[[email protected] ~]# fdisk 2>>test2

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ksl.cfg >test3 2>test4[[email protected] ~]# ll anaconda-ks.cfg anaconda-ksl.cfg &>test5[[email protected] ~]# ll anaconda-ks.cfg anaconda-ksl.cfg >>test5 2>&1

1.8 特殊符号、通配符

“|”:把上一个命令交给下一个命令继续处理

[[email protected] ~]# ll |grep err

[[email protected] ~]# ip a |grep inet

[[email protected] ~]# ip a |grep inet |tee test6

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

“…”: 上一级目录

[[email protected] ~]# ll …/

[[email protected] ~]# cd …/

“.”: 代表当前目录

“;”: 代表多条命令的分割 [[email protected] ~]# a=abc;echo $a

“``” (反撇号) 把内容还原成命令 [[email protected] ~]# a=

ls

;echo $a

“”: (星号)   匹配所有 [[email protected] ~]# ll te

“?”: 匹配单个任意字符 [[email protected] ~]# ll te?

二、系统管理的常用命令

ls 显示的是链接文件及连接目录

ls -a 显示所有的隐藏文件及目录

ls -A 只显示隐藏文件

ls -l 等同于ll

ls -L 显示的是连接路径下的真实文件

2.1绝对路径、相对路径、pwd

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

用相对路径表示: index.html;app/index.html^C

pwd 显示当前工作目录,当前路径       -p 显示链接文件的真实路径

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

cd~ 切换到用户的家目录

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

[[email protected] ~]# cd …/…/

date

时钟显示格式拼接:

[[email protected] ~]# date “+%Y-%m-%d %H:%M:%S”

修改系统时间:

[[email protected] ~]# date -s 17:54:30

显示时区:

[[email protected] ~]# date +%Z

uname

[[email protected] ~]# uname -a 查看系统内核信息

[[email protected] ~]# uname -r

系统管理维护与常用命令

free

[[email protected] ~]# free

[[email protected] ~]# free -m

[[email protected] ~]# free -h

系统管理维护与常用命令
系统管理维护与常用命令

mem: 内存

swap: 在磁盘上格式化的一个和内存格式相同的分区

buffer: 数据读的缓存空间

cache: 数据写的缓存空间

reboot 重启系统

shutdown -h now 关机