[Linux服务器] Linux基本命令一

368 0
Honkers 2026-6-5 05:39:46 来自手机 | 显示全部楼层 |阅读模式

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

学完了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

  1. DEVICE=eth0 #网口名称
  2. ONBOOT=yes #OS启动时,要不要激活该网口
  3. BOOTPROTO=static #网口启动时,使用什么协议,静态(static/none),动态(dhcp)
  4. IPADDR=172.17.50.2 # 静态IP NETMASK=255.255.0.0 # 子网掩码
复制代码

注意:配置完配置文件一定要重启网口 ifdown 网口名 ifup 网口名

查看内核版本

Linux操作系统构成:Linux内核、系统基本库、应用程序
查看内核版本:

  1. [root@rhel1 ~]# uname -r
  2. 2.6.32-642.el6.x86_64
  3. [root@rhel1 ~]# uname -a
  4. 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
复制代码

查看发行版本

  1. [root@rhel1 ~]# lsb_release -a
  2. 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
  3. Distributor ID: RedHatEnterpriseServer
  4. Description: Red Hat Enterprise Linux Server release 6.8 (Santiago)
  5. Release: 6.8
  6. Codename: Santiago
复制代码

判断内、外部命令

1、查找命令所在路径,如果找不到,叫做内部命令,否则外部命令(不推荐)

  1. [root@rhel1 ~]# which cd
  2. /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)
  3. [root@rhel1 ~]# which touch
  4. /bin/touch
复制代码

2、用type查看
(cd是内部命令,touch显示绝对路径是外部命令)

  1. [root@rhel1 ~]# type cd
  2. cd is a shell builtin
  3. [root@rhel1 ~]# type touch
  4. touch is /bin/touch
复制代码

3、使用man命令去查看帮助
如果看到BASH_BUILTINS,表示内部命令,

  1. [root@rhel1 ~]# man cd
  2. ..........................................
  3. BASH_BUILTINS(1) BASH_BUILTINS(1)
  4. ..........................................
复制代码

看到 User Commands ,表示外部命令

  1. [root@rhel1 ~]# man touch
  2. ..........................................
  3. TOUCH(1) User Commands TOUCH(1)
复制代码

shell查看

linux中有很多类型的shell,默认是bash
查看Linux中支持哪些shell:

  1. [root@rhel1 ~]# cat /etc/shells
  2. /bin/sh
  3. /bin/bash
  4. /sbin/nologin
  5. /bin/dash
  6. /bin/tcsh
  7. /bin/csh
复制代码

查看当前使用的是哪个shell , 用ps命令

  1. [root@rhel1 ~]# ps
  2. PID TTY TIME CMD
  3. 2329 pts/0 00:00:00 bash
  4. 2516 pts/0 00:00:00 ps
复制代码

查看命令帮助

1、man查看命令帮助:
下一页用空格,下一行用回车,退出用q

  1. [root@rhel1 ~]# man date
  2. .............................................................
  3. DATE(1) User Commands DATE(1)
  4. .............................................................
复制代码

DATE(1)中的1代表用户在shell环境中可以操作的命令或可执行文件

  1. [root@rhel1 ~]# man null
  2. ............................................................
  3. NULL(4) Linux Programmer’s Manual NULL(4)
  4. .............................................................
复制代码

4是文件设备的说明,通常在/dev下的文件
5是配置文件或者是某些文件的格式
8是系统管理员可用的管理命令
2、help和- -help获取命令的简略帮助
内部命名用help ,外部命令用- -help

  1. [root@rhel1 ~]# help cd
  2. [root@rhel1 ~]#- -help touch
复制代码

3、info也能获取命令的详细帮助

  1. [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 +目录 统计时包括所有的文件,不仅仅只统计目录

显示目前所支持的语言

  1. [root@rhel1 ~]# echo $LANG
  2. en_US.UTF-8
复制代码

修改语言:LANG=

DATE 时间

使用date命令时可以查看命令帮助

查看当前时间

  1. [root@rhel1 ~]# date
  2. Fri Mar 22 01:29:56 CST 2019
复制代码

年/月/日

  1. [root@rhel1 ~]# date +%Y/%m/%d
  2. 2019/03/22
  3. [root@rhel1 ~]# date +%y/%m/%d
  4. 19/03/22
复制代码

年-月-日

  1. [root@rhel1 ~]# date +%F
  2. 2019-03-22
  3. [root@rhel1 ~]# date +%y-%m-%d
  4. 19-03-22
  5. [root@rhel1 ~]# date +%Y-%m-%d
  6. 2019-03-22
复制代码

时:分

  1. [root@rhel1 ~]# date +%H:%M
  2. 01:31
复制代码

时:分:秒

  1. [root@rhel1 ~]# date +%T
  2. 01:42:29
复制代码

年月日 时分秒

  1. [root@rhel1 ~]# date +%F' '%T
  2. 2019-03-22 01:35:26
复制代码

时间戳:
从1970-01-01 00:00:00算起现在总共多少秒

  1. %s seconds since 1970-01-01 00:00:00 UTC
  2. [root@rhel1 ~]# date +%s
  3. 1553189838
复制代码

cal 显示日历

基本上cal的语法为: cal [ [month] year ]

  1. [root@rhel1 ~]# cal 1 2019
  2. January 2019
  3. Su Mo Tu We Th Fr Sa
  4. 1 2 3 4 5
  5. 6 7 8 9 10 11 12
  6. 13 14 15 16 17 18 19
  7. 20 21 22 23 24 25 26
  8. 27 28 29 30 31
复制代码

如果要列出这个月的日历,直接使用cal
显示整年的日历情况用 cal 年份 [root@rhel1 ~]# cal 2019

bc计算器

(按quit离开bc的软件环境)

  1. [root@rhel1 ~]# bc
  2. bc 1.06.95
  3. Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
  4. This is free software with ABSOLUTELY NO WARRANTY.
  5. For details type `warranty'.
  6. 1+3
  7. 4
  8. 9*9
  9. 81
  10. quit
复制代码

bc默认只输出整数,如果要输出全部小数,那么就必须执行scale=number,number就是小数点后位数

  1. [root@rhel1 ~]# bc
  2. bc 1.06.95
  3. Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
  4. This is free software with ABSOLUTELY NO WARRANTY.
  5. For details type `warranty'.
  6. scale=3
  7. 1/5
  8. .200
  9. 6/5
  10. 1.200
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行