ToB企服应用市场:ToB评测及商务社交产业平台

标题: Linux系统的基础知识和常用命令 [打印本页]

作者: 八卦阵    时间: 2024-7-11 15:39
标题: Linux系统的基础知识和常用命令
1、什么是Linux?
是一种免费利用和自由流传的类UNIX操作系统,其内核由林纳斯·本纳第克特·托瓦兹于1991年10月5日首次发布,它主要受到Minix和Unix思想的启发,是一个基于POSIX的多用户、多使命、支持多线程和多CPU的操作系统。它能运行主要的Unix工具软件、应用程序和网络协议。它支持32位和64位硬件。
2、毗连linux比较好用的工具:
不停在用FinalShell,不仅可以敲命令,尚有图形化界面可操作

官网下载毗连为:点击下载
3、登录后你在的位置?
一样寻常登岸后,你的位置位于自己的主目次中。当不确定自己在哪,迷路时,可利用 pwd 表现当前目次
  1. [root@ecs-yewuyingyong ~]# pwd
  2. /root
复制代码
4、文件的绝对路径和相对路径
绝对文件路径:形貌了在虚拟机目次布局中该目次简直切位置,以虚拟目次根目次开始,相称于目次全名。
以正斜杠(/) 开始,比如 /usr/local
相对文件路径:允许用户执行一个基于当前位置的目的文件路径。
比如,当前在 /usr/local 下
  1. [root@ecs-yewuyingyong ~]# cd /usr/local
  2. [root@ecs-yewuyingyong local]# ls
  3. bin  etc  games  include  lib  lib64  libexec  mysql-8.0.33  mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz  nginx  redis  sbin  share  src  tomcat-gwc  tomcat-php  var  web
  4. [root@ecs-yewuyingyong local]# cd bin
  5. [root@ecs-yewuyingyong bin]#
复制代码
5、如何切换目次
语法:cd destination
destination 相对文件路径大概绝对文件路径
/ 称为根目次
. 称为当前目次
… 称为当前目次的上级目次
cd …: 返回上级目次
cd ~:进入用户家目
cd -:返回近来访问目次
6、如何检察目次中的文件
ls 命令会用最根本的形式表现当前目次下的文件和和目次:
  1. [root@ecs-yewuyingyong nginx]# ls
  2. auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
复制代码
可以用 ls -F来区分哪些是目次(目次带/),哪些是文件(文件不带/)
  1. [root@ecs-yewuyingyong nginx]# ls -F
  2. auto/  CHANGES  CHANGES.ru  conf/  configure*  contrib/  html/  LICENSE  Makefile  man/  objs/  README  src/
复制代码
-a 列出目次下的所有文件,包罗以 . 开头的隐含文件。
-l 列出文件的详细信息。
-r 对目次反向排序。
-t 以时间排序。
-R 列出所有子目次下的文件。(递归)
7、创建文件或目次
(1) 创建文件:touch 文件名
批量创建文件:touch 文件名 文件名
  1. [root@ecs-yewuyingyong temp]# touch a.txt
  2. [root@ecs-yewuyingyong temp]# ls
  3. a.txt
  4. [root@ecs-yewuyingyong temp]# touch b.txt c.txt
  5. [root@ecs-yewuyingyong temp]# ls
  6. a.txt  b.txt  c.txt
复制代码
(1) 创建目次:mkdir 目次名
批量创建目次:mkdir 文件名 目次名
  1. [root@ecs-yewuyingyong temp]# mkdir me
  2. [root@ecs-yewuyingyong temp]# ls
  3. me
  4. [root@ecs-yewuyingyong temp]# mkdir you she
  5. [root@ecs-yewuyingyong temp]# ls
  6. me  she  you
复制代码
8、删除文件或目次
语法:rm destination
可带以下命令
-f: 不会出现告诫信息,逼迫删除
-i: 会出现提示删除信息,扣问是否删除
-r: 递归删除,常用在目次下的删除,就是把目次下的东西全删了
  1. [root@ecs-yewuyingyong temp]# rm -r me
  2. rm:是否进入目录"me"? y
  3. rm:是否删除普通空文件 "me/a.txt"?y
  4. rm:是否删除目录 "me"?y
复制代码
rm 不能删除有文件的目次,必要递归删除。
9、重新命名文件,移动文件
语法:mv source target
(1) 重命名:
  1. [root@ecs-yewuyingyong temp]# ls
  2. redis
  3. [root@ecs-yewuyingyong temp]# mv redis redis3.6
  4. [root@ecs-yewuyingyong temp]# ls
  5. redis3.6
复制代码
(2) 移动文件:
新建 it 目次,把 java 目次移动到 it 目次下
  1. [root@ecs-yewuyingyong temp]# ls
  2. java
  3. [root@ecs-yewuyingyong temp]# mkdir it
  4. [root@ecs-yewuyingyong temp]# mv java it
  5. [root@ecs-yewuyingyong temp]# ls -R
  6. .:
  7. it
  8. ./it:
  9. java
  10. ./it/java:
复制代码
10、复制文件
语法:cp source target
  1. [root@ecs-yewuyingyong temp]# ls
  2. a.txt  it
  3. [root@ecs-yewuyingyong temp]# cp a.txt it
  4. [root@ecs-yewuyingyong temp]# cd it
  5. [root@ecs-yewuyingyong it]# ls
  6. a.txt  java
复制代码
当然也可以带上以下命令
-p 带上文件的属性一起赋值
-r 持续递归赋值,用于目次的复制行为
-f 逼迫复制
-i 若目的文档已经存在,会扣问是否覆盖
注:如果重复复制,覆盖会默认进行扣问,如果想逼迫执行不扣问: cp -r 路径
11、压缩文件息争压文件
比如以 .gz 的格式举例。
压缩语法:gzip destination
解压语法:gunzip destination
  1. [root@ecs-yewuyingyong temp]# ls
  2. a.txt  it
  3. [root@ecs-yewuyingyong temp]# gzip a.txt
  4. [root@ecs-yewuyingyong temp]# ls
  5. a.txt.gz  it
  6. [root@ecs-yewuyingyong temp]# gunzip a.txt.gz
  7. [root@ecs-yewuyingyong temp]# ls
  8. a.txt  it
复制代码
12、如何检察命令汗青记录?
history 命令可以展示你用过的命令的汗青记录
13、列出已经安装的包、安装软件、更新软件、卸载
列出已经安装的包:yum list installed
安装软件:yum install package_name
更新软件:yum update package_name
卸载软件:yum remove package_name //只删除软件包,保留数据文件和设置文件
如果不希望保留数据文件和设置文件,可以执行:yum erase package_name
14、源码安装通常的套路
tar -zxvf xx.gz //解压安装包
cd xx
./configure
make
make install
15、vim 编辑器的根本操作
语法:vim [文件名]
功能 :能打开一个文件,如果不存在就会创建文件.
注意事项 :
(1) 第一次进入的时候是平凡模式.
(2) 想要编辑,要按下 i 进入插入模式
(3) 当把内容写完之后,按 Esc 退出插入模式
(4) 输入英文下的冒号 :然后根据情况输入5至7的字符
(5) q 如果未修改缓冲区数据,按 Enter 键退出。
(6) q! 取消所有对缓冲区数据的修改并按 Enter 键退出
(7) wq 将缓冲区数据保存到文件并按 Enter 键退出
16、检察设备尚有多少磁盘空间
dm 可以检察所有已挂载在磁盘的利用情况,-m 用兆字节
  1. [root@ecs-yewuyingyong ~]# df -m
  2. 文件系统        1M-块  已用  可用 已用% 挂载点
  3. devtmpfs        15996     0 15996    0% /dev
  4. tmpfs           16006     0 16006    0% /dev/shm
  5. tmpfs           16006     1 16005    1% /run
  6. tmpfs           16006     0 16006    0% /sys/fs/cgroup
  7. /dev/sda1      100664 53539 42912   56% /
  8. tmpfs            3202     0  3202    0% /run/user/0
复制代码
17、检察当前系统中的进程
语法:ps [参数]
例如查询所在系统 nginx 的进程
  1. [root@ecs-yewuyingyong ~]# ps aux|grep nginx
  2. root      3744  0.0  0.0  20712  1520 ?        Ss    2023   0:00 nginx: master process /usr/local/web/nginx-iot/sbin/nginx -c /usr/local/web/nginx-iot/conf/nginx.conf
  3. nobody   16489  0.0  0.0  21380  2388 ?        S    6月25   2:42 nginx: worker process
  4. root     16857  0.0  0.0 112832   988 pts/1    S+   21:25   0:00 grep --color=auto nginx
  5. root     18085  0.0  0.0  20564   660 ?        Ss   5月24   0:00 nginx: master process ./nginx
  6. nobody   18086  0.0  0.0  21328  2076 ?        S    5月24  14:39 nginx: worker process
  7. root     18260  0.0  0.0  20708  1560 ?        Ss   5月24   0:00 nginx: master process ./nginx
  8. root     24103  0.0  0.0  21612  2480 ?        S    5月15   1:27 nginx: worker process
复制代码
18、netstat 命令,检察当前的网络状态
netstat -anp
netstat -anp | grep “进程名”
netstat -anp | grep “端口号”
检察端口是否被占用,用下面命令
  1. [root@ecs-yewuyingyong ~]# netstat ntulp|grep 8080 //查询8080端口是否被占用
复制代码
19、搜索查询匹配的文件
语法 find 「搜索范围,就是目次」「选项」
从指定目次向下递归的遍历各个子目次,将满意条件的文件或目次表现在终端
-name 按照指定的文件名查找
-user 按照指定的用户进行查找
-size 按照文件巨细进行查找
​ +10M 表示超过10M的
  1. [root@ecs-yewuyingyong local]# find -name nginx
  2. ./nginx
  3. ./nginx/objs/nginx
  4. ./web/nginx-iot/sbin/nginx
  5. ./web/nginx-php/screen2.0/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  6. ./web/nginx-php/screen1.7/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  7. ./web/nginx-php/screen1.8/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  8. ./web/nginx-php/screen2.3/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  9. ./web/nginx-php/screen2.1/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  10. ./web/nginx-php/screen2.2/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  11. ./web/nginx-php/screen2.4/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  12. ./web/nginx-php/screen/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  13. ./web/nginx-php/screen1.9/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
  14. ./web/nginx-php/sbin/nginx
  15. ./web/nginx-gwc/sbin/nginx
复制代码
20、如何检察当前主机名,如何修改
  1. [root@ecs-yewuyingyong ~]# hostname //查看当前主机名
  2. ecs-yewuyingyong
  3. [root@ecs-yewuyingyong ~]# hostname ecs-guanquyingyong//修改当前主机名
  4. [root@ecs-yewuyingyong ~]# hostname //查看当前主机名
  5. ecs-guanquyingyong
复制代码
大家知道一样寻常来讲命令重启就会失效,现在根本上用的centos7的比较多,两种方式可以支持重启生效。
(1) 命令
  1. [root@ecs-yewuyingyong ~]# hostnamectl set-hostname leebao
  2. [root@ecs-yewuyingyong ~]# hostname
  3. leebao
  4. [root@leebao ~]#
复制代码
(2) 修改设置文件:/etc/hostname
  1. [root@leebao ~l# vim /etc/hostname
复制代码
以上就是最常用的一些命令,另外利用 tab 键可以补全命令

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4