Linux常用指令

灰色:普通文件

蓝色:目录

红色:压缩文件

绿色:可执行文件


man [option] 查看具体指令信息
cd / 退回到根目录 change directory
cd ~ 退回到家目录(cd)
id [userid] 查看用户信息
su [userid] 切换用户 switch user
pwd 查看当前所在的目录 print working directory
ctrl+u 删除光标前的内容 在k上面
ctrl+k 删除光标后的内容
ctr+l 清空控制台 (clear)
ll |grep  查看具体文件信息
find [范围] [选项] 查找文件,不写范围默认在当前目录下
tar zcvf 压缩文件
tar zxvf 解压文件
\ 换行符
&& 操作多个命令
halt 关机

防火墙相关

systemctl status firewalld 查看防火墙状态
systemctl start firewalld 开启防火墙
systemctl restart firewalld 重启防火墙
systemctl stop firewalld 关闭防火墙
systemctl disable firewalld 关闭开机启动防火墙
systemctl-cmd --list-all 查看开放的端口
netstat -lnpt 查看监听的端口
firewall-cmd --add-service=http --permanent 开放http权限
firewall-cmd --add-port=3306/tcp --permanent 永久开放端口
firewall-cmd --reload 重启防护墙,但是不会中断用户连接,不丢失状态
telnet ip [端口]   windows 检查是否能连接linux的端口

rpm

wget [链接] 下载软件,默认放在当前目录
rpm -hiv 默认安装在当前目录
rpm -qa 查询文件是否安装
rpm -ql 查看安装的位置
rpm -e --nodenps 删除及依赖

yum

配置yum 更新为阿里云

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum list|grep 查看yum服务器上是否有指定软件安装包
yum install [name] 带依赖安装软件
yum list installed 查看已经安装的软件
yum update 更新yum源同时升级已经安装的软件
yum reintall [name] 重信安装软件
yum remove [name] 卸载
yum clean all 清理yum源
yum makecache 清理缓存
- y 默认yes

安装vim

yum -y install vim*

安装wget

yum install wget

安装netstat

yum install net-tools


进程指令

ps -ef |grep 查看后台运行文件
pstree -p 树状结构显示运行
top 动态显示运行的进程
kill [pid] 杀死进程

网络指令

端口监听

netstat -lnpt # 列出所有在监听显示进程ID,tcp形式的套接字, n显示端口号
netstat -lpnt |grep 5672
netdiscover -r 192.168.10.0/24 #扫描指定net-id中的主机, 型号 MAC地址

arp

  • arp

    不带任何参数, 默认查看当前主机arp目录

    这里显示网关的MAC地址。当前主机与目标主机不在同一个网段,ARP机制将网关地址给到当前主机。当在同一网段,ARP机制将目标主机MAC地址给到当前主机

  • arp -d <address>

    删除当前arp表目中的指定地址的记录

  • arp -s <address, hw>

    设置一条表目

  • arp -v

    统计表目条数

  • arp -a

    不显示列,以行显示

这里的ether指的是网卡类型时以太网,eth0对应接口

磁盘

lsblk  查看硬盘与分区
fdisk  MBR磁盘管理器
df -h  以认类可读的形式展示磁盘的使用情况,不会显示没有挂载
df -T  查看挂载的分区的文件系统
mount <source> <directory> 挂载磁盘到指定文件
umount <source> <directory> 取消挂载
dd if=<input file> of=<output file> 将if中的内容写入of,一般用于制作启动盘  

gcc

GNU Compiler Collection(gcc) GNU编译套件,可以编译多种语言(c,c++,JAVA,Go,Object-c,etc)。现有的很多IDE继承了gcc。

gcc会自动根据文件的后缀名来编译文件

例如:gcc test.c ,会自动将文件编译

gcc --version 查看gcc版本
gcc <file> 编译自动生成a.out, 类似于javac
gcc -o <file> <file> 指定编译生成的文件,文件名可以任意
gcc -S <file> 生成指定文件的汇编文件,类似于javap <filename>

grep

管道符作用是将左侧的命令的stdout做为右侧的stdin

egrep 就是 grep - E ,POSIX 默认使用 -E

删除当前文件夹下匹配正则的文件

[root@chz Desktop]# ls | egrep 'test*'
test1
test2
[root@chz Desktop]# ls | grep  '^test*'
test1
test2

xargs

参考:

https://www.ruanyifeng.com/blog/2019/08/xargs-tutorial.html

由于只有少数命令支持标准输出做为标准输入,只接收命令行参数,xargs是将标准输出转为命令行参数,一般和rm,mkdir,ls一起使用

[root@chz Desktop]# echo 'xargs'|xargs mkdir 
[root@chz Desktop]# ls
minikube  test  test.bak  test.ttt   xargs

将当前目录下所有符合条件的文件删除

[root@chz Desktop]# find . -name 'test*'|xargs rm
或
[root@chz Desktop]# ls|grep test
test1
test2
[root@chz Desktop]# ls|grep test|xargs rm 
[root@chz Desktop]# ls
file1  minikube   xargs

参数

  • -p

    显示具体命名,并提示用户是否继续执行

    [root@chz Desktop]# echo 'xargs'|xargs -p mkdir 
    mkdir xargs ?...y
    

tee

将stdin输出到stdout和file中,使用-a参数不会覆盖源文件内容,使用ctrl + D表示终止输入

[root@chz Desktop]# tee file1
hello world
hello world
java
java
c++
c++
[root@chz Desktop]# cat file1 
hello world
java
c++

可以使用管道符,将内容写入文件

ls | tee out.txt
ls > out.txt
posted @ 2020-08-19 13:57  CyberPelican  阅读(231)  评论(0编辑  收藏  举报