当前位置: 首页 > news >正文

【Linux】-初识Linux

作者:学Java的冬瓜

博客主页:☀冬瓜的主页🌙

专栏:【Linux】

分享:逆着光行走,任风吹雨打。 ——《起风了》

主要内容:Linux的一些最基本指令,Linux的小程序,Linux关于连网端口的指令,Linux关于文件的指令,使用Linux编写代码。

在这里插入图片描述

文章目录

    • 一、什么是Linux?
    • 二、Linux好玩的一些东西
      • 1、Linux一些最基本指令
      • 2、Linux小程序
      • 3、LInux关于连网端口的指令
          • @ 判断连网
          • @ 查看端口
          • @ 连接/关闭网络
      • 4、Linux关于文件的指令
          • @ 创建文件
          • @ 查看文件
          • @ 删除文件
      • 5、安装vim/gcc
    • 三、使用nano编写Linux代码

一、什么是Linux?

Linux定位以及前后端开发定位:
在这里插入图片描述

  • Linux系统应用:
    1> 作为企业后台服务器
    2> 嵌入式Linux系统
    3> 个人桌面应用,比如安卓系统是基于Linux内核的。
  • 企业使用Linux系统作为后台服务器原因:免费,开源,稳定,安全
  • windows和Linux界面的区别:
    Linux:Centos中的界面,其实是Centos中的一款软件,是以进程的形式存在于Linux操作系统中
    Windows:界面和操作系统绑在一起,界面没加载完,操作系统就还没完成启动。
  • 基本编程,系统编程,网络编程的区别?
    基本编程:接近底层,如写C语言代码,写算法
    系统编程:通过操作系统的接口进行业务处理,进程间通信、多线程编程、本地文件读写等等
    网络编程:可以理解为是系统编程的一个分支,依托于系统编程,加入了网络接口,在后台使用多线程等方式处理业务,往后写到数据库,往前写到浏览器。

二、Linux好玩的一些东西

1、Linux一些最基本指令

su -:切换用户身份,从普通用户到超级用户
ctrl d:从超级管理用户到普通用户
whoami:查看当前用户
passwd:修改密码(先切换到超级管理员,再用这个指令)

2、Linux小程序

例一:跑动的火车

// 火车:有时候官方版本下载不了,就需要在非官方(epel)下载:
// sudo yum install -y epel-release)
[mhad@localhost ~]$ sudo yum install -y sl   #安装
[sudo] password for mhad:                      #输入你的密码,这里是不会显示的
[mhad@localhost ~]$ sl              #运行起来

在这里插入图片描述

例二:画讲话的动物

[mhad@localhost ~]$ sudo yum install -y boxes
[sudo] password for mhad:                      
[mhad@localhost ~]$ echo Hello Linux | boxes -d cat/\             /\|`\\_,--="=--,_//`|\ ."  :'. .':  ". /==)  _ :  '  : _  (==|>/O\   _   /O\<|| \-"~` _ `~"-/ |>|`===. \_/ .===`|<.-"-.   \==='  |  '===/   .-"-.
.---{'. '`}---\,  .-'-.  ,/---{.'. '}---.)  `"---"`     `~-===-~`     `"---"`  (
(  Hello Linux                          ))                                     (
'---------------------------------------'

例三:使用Linux进入百度官网,浏览页面

[mhad@localhost ~]$ sudo yum install -y elinks
[sudo] password for mhad:                     
[mhad@localhost ~]$ elinks www.baidu.com

在这里插入图片描述

3、LInux关于连网端口的指令

@ 判断连网

ping -c2 www.baidu.com:判断连网,如果有2条响应内容,则表示连网了;不联网则输出:ping: www.baidu.com: Name or service not known

@ 查看端口

ifconfig:查看端口

[mhad@localhost ~]$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.221.128  netmask 255.255.255.0  broadcast 192.168.221.255inet6 fe80::f4f1:ac8c:cc14:6282  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:f8:47:0a  txqueuelen 1000  (Ethernet)RX packets 131961  bytes 186659338 (178.0 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 20528  bytes 1272300 (1.2 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 68  bytes 5920 (5.7 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 68  bytes 5920 (5.7 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:21:f6:09  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
@ 连接/关闭网络

sudo ifup ens33:连接网络
sudo ifdown ens33:关闭网络,如下:可以发现,关闭网络后,inet和inet6这两行都没有了

[mhad@localhost ~]$ sudo ifdown ens33
[sudo] password for mhad: 
Device 'ens33' successfully disconnected.
[mhad@localhost ~]$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500ether 00:0c:29:f8:47:0a  txqueuelen 1000  (Ethernet)RX packets 131991  bytes 186661328 (178.0 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 20532  bytes 1272689 (1.2 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 68  bytes 5920 (5.7 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 68  bytes 5920 (5.7 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255ether 52:54:00:21:f6:09  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

4、Linux关于文件的指令

@ 创建文件

mkdir:创建目录,在当前目录下创建目录。
cd:切换目录
cd..:回退到上级目录
pwd:查看当前的根目录

示例1:

[mhad@localhost ~]$ mkdir Lession
[mhad@localhost ~]$ cd Lession
[mhad@localhost Lession]$ pwd
/home/mhad/Lession
@ 查看文件

ls:当前目录下所有文件
ll:当前目录下所有文件的详细信息,d开头是文件目录,-开头是普通文件
ls -l:显示列表,但不包括隐藏文件,ls -l比ls显示当前目录更多信息。
ls -la(或ls -l -a):显示列表,包括隐藏文件 (以点开头的文件:隐藏文件)

示例2:

[mhad@localhost ~]$ ls
a.out  code  Code.c  Desktop  Documents  Downloads  Lession  Music  Pictures  Public  Templates  test.c  Videos
[mhad@localhost ~]$ 
[mhad@localhost ~]$ ll
total 32
-rwxrwxr-x. 1 mhad mhad 8512 Mar  5 00:20 a.out
-rwxrwxr-x. 1 mhad mhad 8512 Mar 12 20:32 code
-rw-rw-r--. 1 mhad mhad   79 Mar 12 20:31 Code.c
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Desktop
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Documents
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Downloads
drwxrwxr-x. 2 mhad mhad    6 Mar 12 21:10 Lession
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Music
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Pictures
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Public
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Templates
-rw-rw-r--. 1 mhad mhad   64 Mar  5 00:19 test.c
drwxr-xr-x. 2 mhad mhad    6 Mar  2 21:33 Videos
[mhad@localhost ~]$
@ 删除文件

rm 文件名:删除文件
rm -rf 目录名:删除目录

5、安装vim/gcc

[mhad@localhost Lession]$ sudo yum install -y vim
[mhad@localhost Lession]$ sudo yum install -y gcc  #gcc是默认安装的

三、使用nano编写Linux代码

[mhad@localhost ~]$ touch code.c  #创建Code.c文件
[mhad@localhost ~]$ nano code.c   #nano 是一个Linux下很简单的文本编辑器,该指令表示进入code.c文件编辑
#include <stdio.h>
int main()
{printf("你好,Linux!\n");return 0;
}
[mhad@localhost ~]$ gcc -o code code.c   #gcc是linux下的C编译器,该指令表示编译文件
[mhad@localhost ~]$ ls
code code.c                              #code是编译后产生的文件
[mhad@localhost ~]$ ./code               #运行
你好,Linux!
http://www.lryc.cn/news/42578.html

相关文章:

  • 精选7个 Python 学习资源库,助你成为优秀的开发者
  • 【大数据处理与可视化】三 、Pandas库的运用
  • FPGA解码SDI视频任意尺寸缩放拼接输出 提供工程源码和技术支持
  • 线索二叉树结构
  • 6.网络爬虫——BeautifulSoup详讲与实战
  • Vue:路由管理模式
  • 7个最好的PDF编辑器,帮你像编辑Word一样编辑PDF
  • 【数据结构】树的介绍
  • CoreDNS 性能优化
  • 前端三剑客常见面试题及其答案
  • 【DFS专题】深度优先搜索 “暴搜”优质题单推荐 10道题(C++ | 洛谷 | acwing)
  • 微信小程序自定义组件生命周期有哪些?
  • Linux就该这么学(六)
  • 目标检测算法——YOLOv5/v7/v8改进结合涨点Trick之Wise-IoU(超越CIOU/SIOU)
  • 【蓝桥杯选拔赛真题39】python输出数字组合 青少年组蓝桥杯python 选拔赛STEMA比赛真题解析
  • 网络安全工程师做什么?
  • 总结:K8S运维常用命令
  • 你是真的“C”——进行动态内存分配库函数的使用详解
  • Python|蓝桥杯进阶第五卷——数论
  • 用Python实现单例模式
  • 交叉编译说明:工具链安装和环境变量配置
  • 文件上传的多种利用方式
  • 盘一盘C++的类型描述符(二)
  • 慎投,Frontiers这本期刊显示on hold中
  • Winform控件开发(21)——ProgressBar(史上最全)
  • 校招失败后,在外包公司熬了 2 年终于进了字节跳动,竭尽全力....
  • UniApp + SpringBoot 实现接入支付宝支付功能和退款功能
  • 初识进程
  • SOAP传输协议
  • <Linux>进程控制