点击蓝字
关注我们
Linux系统基础命令篇
●命令提示符含义
当前用户@主机名 工作目录] #
[root@rhel8 ~]#
当前用户为root@主机名为 rhel8 当前所在目录 ~为家目录 #为管理员提示符
[lisi@localhost ~]$
当前用户为lisi@主机名为localhost 当前所在目录 ~为家目录 $ 为普通用户提示符
●在Linux系统下所有的目录和文件都是以倒挂的树形结构存在与 /(根)目录下,也可以说 /(根)目录就是Linux的起点
●init 系统启动级别
—— init 0:关机
—— init 1:单用户模式(只root用户进行维护)
—— init 2:多用户模式(不带网络)
—— init 3:完全多用户模式(标准的运行级别)
—— init 4:安全模式
—— init 5:图形化界面
—— init 6:重启
●查看系统当前运行级别:[root@Chinese ~]# runlevel
●Linux命令
——用来实现某一种功能的指令或程序
——命令的执行依赖于解释器(例如:/bin/bash)
●Linux命令的分类
——内部命令:系统自带属于解释器的一部分
——外部命令:系统之外自己安装的其他程序
●命令行的一般格式
命令字 选项… 参数1 参数2…
ls —— 用途:查看目录和文件属性及目录下内容
格式:ls 选项… 目录或文件名…
[root@rhel8 opt]# ls -l /etc/passwd
-rw-r--r--. 1 root root 1080 3月 24 18:50 /etc/passwd
●常用选项:
-l以长格式显示目录下的内容列表。
-d仅显示目录名,而不显示目录下的内容列表
-t用文件和目录的更改时间排序
-a显示所有目录文件,包括隐藏的内容
-h人性化显示目录下内容的大小
-R递归查看目录下所有内容
●命令的一般格式:命令字 选项… 参数1 参数2…
●命令的选项
——短选项:-l-d-h-a-t……
[root@rhel8 opt]# ls -l /etc/passwd
——复合选项:-lha……
[root@localhost ~]# ls -lhd /etc/passwd
●命令的参数
——单个参数:[root@rhel8 opt]# ls -l /etc/passwd
——多个参数:[root@localhost ~]# ls -lha /etc/passwd /etc/resolv.conf
●查看当前所在的目录
pwd —— 用途:查看当前所在的工作目录
[root@rhel8 ~]# pwd
切换工作目录
cd —— 用途:切换到其他目录
格式:cd 目标目录
[root@rhel8 ~]# cd /opt/
●查看文件内容
cat —— 用途:查看文本文件内容
命令行一般格式:cat 选项 文件…i]k,=8
[root@rhel8 ~]# cat -n /etc/profile
[root@rhel8 ~]# cat -b /etc/profile
●常用选项
-n查看时以行号的形式显示文件内容
-b查看时以行号的形式显示文件内容,对空行不编号
●查看红帽系统版本信息
[root@rhel8 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.0 (Ootpa)
●查看内核版本信息
[root@rhel8 ~]# uname -r
4.18.0-80.el8.x86_64
●查看CPU处理器等信息
[root@rhel8 ~]# lscpu 或 [root@rhel8 ~]# cat /proc/cpuinfo
●查看内存大小及空闲情况
[root@rhel8 ~]# free –h或[root@rhel8 ~]# cat /proc/meminfo
●查看主机名
[root@rhel8 ~]# hostname
rhel8
●查看网卡信息
[root@rhel8 ~]# ip add show
●创建目录格式
mkdir —— 命令格式 mkdir 【选项】【目录名】
●命令选项:
-p递归创建多个目录
-m创建目录时并设置目录权限
[root@rhel8 ~]# mkdir /test/
[root@rhel8 ~]# mkdir -p /test/t1/t2/t3/
[root@rhel8 ~]# ls -R /test/
[root@rhel8 ~]# mkdir -m ugo=rwx /xxoo/
[root@rhel8 ~]# ls -ld /xxoo/
drwxrwxrwx. 2 root root 6 3月 24 22:35 /xxoo/
●绝对路径:
绝对路径必须以根目录开始,到查找对象(目录或文件)所必须经过的每个目录的名字,它是文件位置的完整路标。
[root@rhel8 ~]# ls /test/t1/t2/t3/
●相对路径
相对路径不以根开头,从当前所在目录开始,到查找对象(目录或文件)所必须经过的每一个目录的名字。
[root@rhel8 ~]# cd /test/
[root@rhel8 test]# ls t1/t2/t3/
●创建文件格式
touch —— 用途:新建空白文件
格式1:touch[目录]文件名
[root@rhel8 ~]# touch /test/test.txt
[root@rhel8 ~]# ls /test/
t1 test.txt
格式2:touch 文件名
[root@rhel8 ~]# touch 1.txt
[root@rhel8 ~]# ls
txt anaconda-ks.cfg
●less 工具是对文件或其它输出进行分页显示的工具,常用于查看内容量较大的文件
●命令格式:
less [参数] 文件
命令常用参数:-N 显示每行的行号
[root@rhel8 test]# less -N /var/log/messages
●查看选项参数
鼠标上下键逐行查看
/字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
pgdn 向下翻动一页
pgup向上翻动一页
●head命令
head 用来显示文件的开头至标准输出中,默认head命令打印其相应文件的开头10行
●常用参数
-n 显示的行数
-v 显示文件名
[root@rhel8 ]# head -v -n 2 /etc/passwd
==> /etc/passwd <==
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
●tail命令
tail 用来显示文件的末尾至标准输出中,默认tail命令打印其相应文件的末尾10行
●常用参数
-n 显示的行数
-f动态显示
-v 显示文件名
[root@rhel8 ~]# tail -v -n 2 -f /var/log/messages
==> /var/log/messages <==
Mar 25 00:11:21 Chinese dnf[17239]:
Mar 25 00:11:21 Chinese systemd[1]: Started dnf makecache
●grep命令
Linux系统中grep命令是一种强大的文本搜索工具,它能利用正则表达式搜索文本,并把匹配的行打印出来,用于查找文件里符合条件的字符串。
命令格式:grep 选项… “查找条件” 目标文件
●常用选项
-v 显示不包含匹配文本的所有行
-i 忽略字符大小写的差别
-n标示出该行的列数编号
[root@rhel8 bin]# grep "root" /etc/passwd
[root@rhel8 bin]# grep -n "root" /etc/passwd
[root@rhel8 bin]# grep -i "ROOT" /etc/passwd
[root@rhel8 bin]# grep -v "root" /etc/passwd
●linux下常用的关机命令有:shutdown、halt、poweroff、init
1、halt立刻关机
2、psweroff立刻关机
3、shutdown –h now 立刻关机
4、shutdown -h 10 10分钟后自动关机
●重启命令:reboot shutdown
1、reboot立刻重启
2、shutdown -r now 立刻重启
3、shutdown -r 10过十分钟后重启
为方便来自五湖四海的Linux爱好者能共同
学(吹)习(牛)讨(打)论(趣)
热烈欢迎大家加入专属QQ群——1084685279
群内定时上传资料还有老师全天答疑
入群即可免费获得:
1、必备工具源码包
2、内部精选电子书
3、运维资料大礼包
欲知更多福利,欢迎你的加入点击“阅读原文”