++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
学完了linux对其中的命令做一总结当做复习
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
查看IP和配置IP
-
查看IP: ifconfig 只能查看已激活的网口
ifconfig -a 查看所有网口信息
注意:真实的网口有eth0、eth1、eth2等等,虚拟的网口有lo,本地回环网口,用于测试本机的TCP/IP协议是否正常,也用于本机中不同进程之间的通信。 -
设置IP:
1、临时设置:ifconfig 网口名称 IP地址 netmask 子网掩码。例
ifconfig eth0 172.16.5.20 netmask 255.255.0.0
2 、永久配置:先找到网口配置文件的目录:/etc/sysconfig/network-scripts
网口配置文件的名称是以ifcfg-开头,后面跟网口名。例 vim ifcfg-eth0
DEVICE=eth0 #网口名称
ONBOOT=yes #OS启动时,要不要激活该网口
BOOTPROTO=static #网口启动时,使用什么协议,静态(static/none),动态(dhcp)
IPADDR=172.17.50.2 # 静态IP NETMASK=255.255.0.0 # 子网掩码
注意:配置完配置文件一定要重启网口 ifdown 网口名 ifup 网口名
查看内核版本
Linux操作系统构成:Linux内核、系统基本库、应用程序
查看内核版本:
[root@rhel1 ~]# uname -r
2.6.32-642.el6.x86_64
[root@rhel1 ~]# uname -a
Linux rhel1 2.6.32-642.el6.x86_64 #1 SMP Wed Apr 13 00:51:26 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
查看发行版本
[root@rhel1 ~]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 6.8 (Santiago)
Release: 6.8
Codename: Santiago
判断内、外部命令
1、查找命令所在路径,如果找不到,叫做内部命令,否则外部命令(不推荐)
[root@rhel1 ~]# which cd
/usr/bin/which: no cd in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@rhel1 ~]# which touch
/bin/touch
2、用type查看
(cd是内部命令,touch显示绝对路径是外部命令)
[root@rhel1 ~]# type cd
cd is a shell builtin
[root@rhel1 ~]# type touch
touch is /bin/touch
3、使用man命令去查看帮助
如果看到BASH_BUILTINS,表示内部命令,
[root@rhel1 ~]# man cd
..........................................
BASH_BUILTINS(1) BASH_BUILTINS(1)
..........................................
看到 User Commands ,表示外部命令
[root@rhel1 ~]# man touch
..........................................
TOUCH(1) User Commands TOUCH(1)
shell查看
linux中有很多类型的shell,默认是bash
查看Linux中支持哪些shell:
[root@rhel1 ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
查看当前使用的是哪个shell , 用ps命令
[root@rhel1 ~]# ps
PID TTY TIME CMD
2329 pts/0 00:00:00 bash
2516 pts/0 00:00:00 ps
查看命令帮助
1、man查看命令帮助:
下一页用空格,下一行用回车,退出用q
[root@rhel1 ~]# man date
.............................................................
DATE(1) User Commands DATE(1)
.............................................................
DATE(1)中的1代表用户在shell环境中可以操作的命令或可执行文件
[root@rhel1 ~]# man null
............................................................
NULL(4) Linux Programmer’s Manual NULL(4)
.............................................................
4是文件设备的说明,通常在/dev下的文件
5是配置文件或者是某些文件的格式
8是系统管理员可用的管理命令
2、help和- -help获取命令的简略帮助
内部命名用help ,外部命令用- -help
[root@rhel1 ~]# help cd
或
[root@rhel1 ~]#- -help touch
3、info也能获取命令的详细帮助
[root@rhel1 ~]# info help
切换用户
su - 用户名
由root用户切换到其他用户不需要输入密码,由其他用户切换到root用户需要输入密码
exit 退出用户
bash 快捷键
Tab键:自动补齐命令字 按两下:补齐所有命令字
ctrl+c:终止当前进程
ctrl+d:终止输入并退出 输入结束
ctrl+z:挂起程序 暂停程序,放到后台
ctrl+l:清屏 clear
ctrl+k:删除从光标到行末的所有字符 (包括光标)
ctrl+u:删除从光标处到行首的所有字符 (不包括光标)
ctrl+r:查找历史命令 从最近命令开始找
history:查看历史命令
!历史命令编号:重复运行历史命令
!!:运行上一个命令
!rpm :调用以rpm开头的最近的历史命令
ctrl+S:锁屏
ctrl+Q:解屏
ctrl+a:快速将光标移动到命令行首
ctrl+e:快速将光标移动到命令行尾
pwd:查看工作目录 查看当前目录
ls命令
ls:列出目录内容(文件名字),查看目录文件的内容
-l:以长格式显示 查看文件属性 ls -l = ll
-d:显示目录本身的属性
linux下隐藏文件名称以 .开头,
-a:显示所有子目录和包括隐藏文件
-A:不显示 . 和. .
-h:以字节单位显示信息
-R:递归显示内容
对目录的一些操作
mkdir:创建目录
rmdir:只能删空目录
rm -rf :删除
du:统计目录及文件的占用情况(默认K字节)显示目录大小 文件系统大小
du -h +目录 以字节单位显示信息
du -sh +目录 目录总大小
du -a +目录 统计时包括所有的文件,不仅仅只统计目录
显示目前所支持的语言
[root@rhel1 ~]# echo $LANG
en_US.UTF-8
修改语言:LANG=
DATE 时间
使用date命令时可以查看命令帮助
查看当前时间
[root@rhel1 ~]# date
Fri Mar 22 01:29:56 CST 2019
年/月/日
[root@rhel1 ~]# date +%Y/%m/%d
2019/03/22
[root@rhel1 ~]# date +%y/%m/%d
19/03/22
年-月-日
[root@rhel1 ~]# date +%F
2019-03-22
[root@rhel1 ~]# date +%y-%m-%d
19-03-22
[root@rhel1 ~]# date +%Y-%m-%d
2019-03-22
时:分
[root@rhel1 ~]# date +%H:%M
01:31
时:分:秒
[root@rhel1 ~]# date +%T
01:42:29
年月日 时分秒
[root@rhel1 ~]# date +%F' '%T
2019-03-22 01:35:26
时间戳:
从1970-01-01 00:00:00算起现在总共多少秒
%s seconds since 1970-01-01 00:00:00 UTC
[root@rhel1 ~]# date +%s
1553189838
cal 显示日历
基本上cal的语法为: cal [ [month] year ]
[root@rhel1 ~]# cal 1 2019
January 2019
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
如果要列出这个月的日历,直接使用cal
显示整年的日历情况用 cal 年份 [root@rhel1 ~]# cal 2019
bc计算器
(按quit离开bc的软件环境)
[root@rhel1 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1+3
4
9*9
81
quit
bc默认只输出整数,如果要输出全部小数,那么就必须执行scale=number,number就是小数点后位数
[root@rhel1 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale=3
1/5
.200
6/5
1.200