网站关键词价格唐山培训网站建设
1、什么是Linux?
 是一种免费使用和自由传播的类UNIX操作系统,其内核由林纳斯·本纳第克特·托瓦兹于1991年10月5日首次发布,它主要受到Minix和Unix思想的启发,是一个基于POSIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的Unix工具软件、应用程序和网络协议。它支持32位和64位硬件。
 2、连接linux比较好用的工具:
 一直在用FinalShell,不仅可以敲命令,还有图形化界面可操作
 
 官网下载连接为:点击下载
 3、登录后你在的位置?
 一般登陆后,你的位置位于自己的主目录中。当不确定自己在哪,迷路时,可使用 pwd 显示当前目录
[root@ecs-yewuyingyong ~]# pwd
/root
 
4、文件的绝对路径和相对路径
 绝对文件路径:描述了在虚拟机目录结构中该目录的确切位置,以虚拟目录根目录开始,相当于目录全名。
 以正斜杠(/) 开始,比如 /usr/local
 相对文件路径:允许用户执行一个基于当前位置的目标文件路径。
 比如,当前在 /usr/local 下
[root@ecs-yewuyingyong ~]# cd /usr/local
[root@ecs-yewuyingyong local]# ls
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
[root@ecs-yewuyingyong local]# cd bin
[root@ecs-yewuyingyong bin]# 
 
5、如何切换目录
 语法:cd destination
 destination 相对文件路径或者绝对文件路径
 / 称为根目录
 . 称为当前目录
 … 称为当前目录的上级目录
 cd …: 返回上级目录
 cd ~:进入用户家目
 cd -:返回最近访问目录
 6、如何查看目录中的文件
 ls 命令会用最基本的形式显示当前目录下的文件和和目录:
[root@ecs-yewuyingyong nginx]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
 
可以用 ls -F来区分哪些是目录(目录带/),哪些是文件(文件不带/)
[root@ecs-yewuyingyong nginx]# ls -F
auto/  CHANGES  CHANGES.ru  conf/  configure*  contrib/  html/  LICENSE  Makefile  man/  objs/  README  src/
 
-a 列出目录下的所有文件,包括以 . 开头的隐含文件。
 -l 列出文件的详细信息。
 -r 对目录反向排序。
 -t 以时间排序。
 -R 列出所有子目录下的文件。(递归)
 7、创建文件或目录
 (1) 创建文件:touch 文件名
 批量创建文件:touch 文件名 文件名
[root@ecs-yewuyingyong temp]# touch a.txt
[root@ecs-yewuyingyong temp]# ls
a.txt
[root@ecs-yewuyingyong temp]# touch b.txt c.txt
[root@ecs-yewuyingyong temp]# ls
a.txt  b.txt  c.txt
 
(1) 创建目录:mkdir 目录名
 批量创建目录:mkdir 文件名 目录名
[root@ecs-yewuyingyong temp]# mkdir me
[root@ecs-yewuyingyong temp]# ls
me
[root@ecs-yewuyingyong temp]# mkdir you she
[root@ecs-yewuyingyong temp]# ls
me  she  you
 
8、删除文件或目录
 语法:rm destination
 可带以下命令
 -f: 不会出现警告信息,强制删除
 -i: 会出现提示删除信息,询问是否删除
 -r: 递归删除,常用在目录下的删除,就是把目录下的东西全删了
[root@ecs-yewuyingyong temp]# rm -r me
rm:是否进入目录"me"? y
rm:是否删除普通空文件 "me/a.txt"?y
rm:是否删除目录 "me"?y
 
rm 不能删除有文件的目录,需要递归删除。
 9、重新命名文件,移动文件
 语法:mv source target
 (1) 重命名:
[root@ecs-yewuyingyong temp]# ls
redis
[root@ecs-yewuyingyong temp]# mv redis redis3.6
[root@ecs-yewuyingyong temp]# ls
redis3.6
 
(2) 移动文件:
 新建 it 目录,把 java 目录移动到 it 目录下
[root@ecs-yewuyingyong temp]# ls
java
[root@ecs-yewuyingyong temp]# mkdir it
[root@ecs-yewuyingyong temp]# mv java it
[root@ecs-yewuyingyong temp]# ls -R
.:
it
./it:
java
./it/java:
 
10、复制文件
 语法:cp source target
[root@ecs-yewuyingyong temp]# ls
a.txt  it
[root@ecs-yewuyingyong temp]# cp a.txt it
[root@ecs-yewuyingyong temp]# cd it
[root@ecs-yewuyingyong it]# ls
a.txt  java
 
当然也可以带上以下命令
 -p 带上文件的属性一起赋值
 -r 持续递归赋值,用于目录的复制行为
 -f 强制复制
 -i 若目标文档已经存在,会询问是否覆盖
 注:如果重复复制,覆盖会默认进行询问,如果想强制执行不询问: cp -r 路径
 11、压缩文件和解压文件
 比如以 .gz 的格式举例。
 压缩语法:gzip destination
 解压语法:gunzip destination
[root@ecs-yewuyingyong temp]# ls
a.txt  it
[root@ecs-yewuyingyong temp]# gzip a.txt
[root@ecs-yewuyingyong temp]# ls
a.txt.gz  it
[root@ecs-yewuyingyong temp]# gunzip a.txt.gz
[root@ecs-yewuyingyong temp]# ls
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 用兆字节
[root@ecs-yewuyingyong ~]# df -m
文件系统        1M-块  已用  可用 已用% 挂载点
devtmpfs        15996     0 15996    0% /dev
tmpfs           16006     0 16006    0% /dev/shm
tmpfs           16006     1 16005    1% /run
tmpfs           16006     0 16006    0% /sys/fs/cgroup
/dev/sda1      100664 53539 42912   56% /
tmpfs            3202     0  3202    0% /run/user/0
 
17、查看当前系统中的进程
 语法:ps [参数]
 例如查询所在系统 nginx 的进程
[root@ecs-yewuyingyong ~]# ps aux|grep nginx
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
nobody   16489  0.0  0.0  21380  2388 ?        S    6月25   2:42 nginx: worker process
root     16857  0.0  0.0 112832   988 pts/1    S+   21:25   0:00 grep --color=auto nginx
root     18085  0.0  0.0  20564   660 ?        Ss   5月24   0:00 nginx: master process ./nginx
nobody   18086  0.0  0.0  21328  2076 ?        S    5月24  14:39 nginx: worker process
root     18260  0.0  0.0  20708  1560 ?        Ss   5月24   0:00 nginx: master process ./nginx
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 “端口号”
 查看端口是否被占用,用下面命令
[root@ecs-yewuyingyong ~]# netstat ntulp|grep 8080 //查询8080端口是否被占用
 
19、搜索查询匹配的文件
 语法 find 「搜索范围,就是目录」「选项」
 从指定目录向下递归的遍历各个子目录,将满足条件的文件或目录显示在终端
 -name 按照指定的文件名查找
 -user 按照指定的用户进行查找
 -size 按照文件大小进行查找
  +10M 表示超过10M的
[root@ecs-yewuyingyong local]# find -name nginx
./nginx
./nginx/objs/nginx
./web/nginx-iot/sbin/nginx
./web/nginx-php/screen2.0/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen1.7/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen1.8/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.3/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.1/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.2/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen2.4/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/screen1.9/Cesium-1.92/ThirdParty/codemirror-5.52.0/mode/nginx
./web/nginx-php/sbin/nginx
./web/nginx-gwc/sbin/nginx
 
20、如何查看当前主机名,如何修改
[root@ecs-yewuyingyong ~]# hostname //查看当前主机名
ecs-yewuyingyong
[root@ecs-yewuyingyong ~]# hostname ecs-guanquyingyong//修改当前主机名
[root@ecs-yewuyingyong ~]# hostname //查看当前主机名
ecs-guanquyingyong
 
大家知道一般来讲命令重启就会失效,目前基本上用的centos7的比较多,两种方式可以支持重启生效。
 (1) 命令
[root@ecs-yewuyingyong ~]# hostnamectl set-hostname leebao
[root@ecs-yewuyingyong ~]# hostname 
leebao
[root@leebao ~]#
 
(2) 修改配置文件:/etc/hostname
[root@leebao ~l# vim /etc/hostname
 
以上就是最常用的一些命令,另外使用 tab 键可以补全命令
