linux的基础命令

主要用于 个人复习和工作时查找

1、内核版本

[root@VM-4-16-centos files]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
# 操作系统版本
[root@VM-4-16-centos files]# cat /etc/os-release
NAME="CentOS Linux"
......

2、发行版本

[root@VM-4-16-centos files]# yum install -y redhat-lsb
[root@VM-4-16-centos files]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core

3、当前主机名称:

[root@VM-4-16-centos files]# hostname  / hostnamectl
VM-4-16-centos
修改主机名:
1[root@szx ~]# vim /etc/hostname
2)hostnamectl set-hostname <newhostname>  # 已测试,可以
3)hostname <new-hostname>  # 临时更改主机名

4、显示CPU型号:

[root@VM-4-16-centos files]# lscpu
CPU(s):                2
.......

5、显示内存大小

[root@VM-4-16-centos files]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        940M        209M        612K        687M        726M
Swap:            0B          0B          0B

6、查看硬盘和分区情况

[root@VM-4-16-centos files]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 197.8M  0 rom
vda    253:0    0    40G  0 disk
└─vda1 253:1    0    40G  0 part /

7、退出当前登录状态,注销用户身份

exit
logout

8、执行quit命令,退出当前程序

[root@VM-4-16-centos files]# 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'.
2-3
-1
quit

9、关机重启的相关命令

重启:
reboot
init 6
shutdown -r now
关机:
Init 0
halt
poweroff
shutdown -h now
halt命令 – 关闭当前服务器系统
init命令 – 切换系统运行级别
0		关机
1		单用户
2		多用户
3		完全多用户模式
5		图形界面
6		重启

10、切换字符和图形界面模式

[root@VM-4-16-centos files]# runlevel
N 3
切换图形界面
init 5

11、显示日期和时间

1)date  
常用参数:日期%F  时间%T
-d "-1 day":显示昨天日期
-s '1 year':设置当前时间为明年日期

[root@VM-4-16-centos files]# date
Thu Jun 16 16:52:35 CST 2022
[root@VM-4-16-centos files]# date "+%F %T"
2022-06-16 16:55:20

2) cal 显示当前月历

3) clock / hwclock  操作系统硬件时间
常用参数:
-s:同步硬件时间为准,设置系统时间
-w:同步系统时间为准,设置硬件时间

[root@VM-4-16-centos files]# clock
Thu 16 Jun 2022 04:52:50 PM CST  -0.421848 seconds
[root@VM-4-16-centos files]# hwclock
Thu 16 Jun 2022 04:52:57 PM CST  -0.489178 seconds

12、用户登录信息

[root@VM-4-16-centos files]# whoami  # 当前登录有效用户
root
[root@VM-4-16-centos files]# who # 显示当前系统所有登录会话
root     pts/0        2022-06-16 15:13 (36.113.113.25)
[root@VM-4-16-centos files]# w    # who的功能+及所做的操作
 16:59:23 up 2 days,  3:18,  1 user,  load average: 0.00, 0.03, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    36.113.113.25    15:13    3.00s  0.24s  0.00s w

13、显示字符

echo
参数:
-n:一行显示
-e:启动转义,可以转义\

14、快捷键

Tab:补全命令或文件名,补全帮助
补全帮助:命令后面,输入两个空格和两个Tab
[root@VM-4-16-centos files]# ip  #示例
address      help         link         monitor      neigh        ntable       tcp_metrics  tuntap
addrlabel    ila          macsec       mroute       netconf      route        token        vrf
fou          l2tp         maddress     mrule        netns        rule         tunnel       xfrm
[root@VM-4-16-centos files]# rpm -q bash-completion # 此软件包才能支持命令补全功能
bash-completion-2.1-8.el7.noarch
中止执行:Ctrl + c
其余组合:
Ctrl + l  # 清屏,clear命令等价
Ctrl + u 从光标处删至行首
Ctrl + k 从光标处删至行尾
Ctrl + a 光标移到命令行首
Ctrl + e  光标移到命令行尾
Alt + r 删除当前行

15、命令分类
命令执行顺序:别名–>内部命令–>hash缓存区–>PATH路径下查找
1)内部命令

[root@VM-4-16-centos files]# enable  # 查看所有的内部命令
enable .
enable :
enable [
enable alias

[root@VM-4-16-centos files]# type set
set is a shell builtin  # 内部命令

2)外部命令
没有集成到在shell程序中,具体表现为一个独立的可执行文件

[root@VM-4-16-centos files]# type cat  # 通过type命令查看,有文件路径的提示
cat is hashed (/usr/bin/cat)

[root@szb ~]# echo $PATH # 通过path路径查找外部命令
/usr/local/git/bin:/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

查看外部命令对应的文件路径
[root@szb ~]# which hostname
/usr/bin/hostname
[root@szb ~]# whereis hostname
hostname: /usr/bin/hostname /etc/hostname /usr/share/man/man5/hostname.5.gz /usr/share/man/man1/hostname.1.gz

第一次执行外部命令后,系统将外部命令记录到内存缓存区,hash查看已执行的外部命令和存放路径
[root@szb ~]# hash   # hash -r参数清理缓存
hits    command
   1    /usr/bin/whereis
   1    /usr/bin/ls

3)别名 anlias unalias

定义别名:alias 别名=命令
查看指定别名:alias 别名
取消别名:unalias 别名
[root@szb ~]# alias ll
alias ll='ls -l --color=auto'

[root@szb ~]# alias datetime="date +'%F %T'"
[root@szb ~]# datetime
2022-06-16 17:48:14
注意:
别名和内部命令同名时,优先执行别名
不执行别名的情况:\别名 或者  '别名'
别名永久生效:
当前用户有效,配置文件:~/.bashrc
所有用户生效,配置文件:/etc/bashrc
修改完,执行生效(或重新登录):
source /etc/bashrc   或者  . /etc/bashrc
区别:
/etc/profile 是所有用户登录时加载配置环境
/etc/bashrc 是所有用户在执行bash shell 时,加载配置环境

16、获取命令帮助

whatis   # 基于数据库查找的简要说明,等价于man -f(新系统,需要使用mandb创建数据库)
[root@szb ~]# whatis cat
cat (1)              - concatenate files and print on the standard output
1) 内部命令帮助
help COMMAND
man bash  # 查看全部内部命令的帮助和详细说明

2)外部命令
COMMAND --help
[root@szb ~]# date --help
Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
...:多个参数,中间空格
| :多选一,只能选|左右一项
[]:可选项

3)man帮助--用于命令查看
配置:
命令配置手册:/usr/share/man
配置文件:/etc/man_db.conf
<>  必选内容
搜索:/keyword
退出:q
1 用户命令        2 系统调用
3 C库调用		 4 设备文件及特殊文件
5 配置文件格式    6 游戏
7 杂项		     8 管理类的命令
9 Linux内核API

4) info信息--文档参考
无参数
n:进入下一层;p:进入前一层
s:文字文本搜索;q:退出info

5)本地帮助文档:/usr/share/doc/
网站:https://tldp.org/
Linux命令手册:
逻辑比较清晰:https://www.linuxcool.com/
示例比较多:https://chinese.freecodecamp.org/news/the-linux-commands-handbook/
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值