linux的一些基本操作命令

本文详细介绍了Linux CentOS7系统中的一些基本操作,包括安装和卸载JDK,查询磁盘内存使用情况,设置文件的软硬链接,以及使用vim编辑器进行文件编辑和读取。通过实例展示了如何使用rpm和yum命令安装和卸载程序,以及df命令查询磁盘空间。此外,还探讨了ln命令创建软硬链接的区别。最后,演示了使用vim编辑器创建和读取文件内容的基本步骤。
摘要由CSDN通过智能技术生成

1.环境准备

linux版本: centos 7

2.基本命令

2.1.安装和卸载程序

示例:安装和卸载JDK
安装JDK

[root@VM-0-14-centos /]# cd /home/yangzhenwei
[root@VM-0-14-centos yangzhenwei]# ls
apache-tomcat-9.0.45.tar.gz  jdk-8u211-linux-x64.tar.gz  jdk-8u281-linux-x64.rpm
[root@VM-0-14-centos yangzhenwei]# rpm  -ivh jdk-8u281-linux-x64.rpm 
warning: jdk-8u281-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk1.8-2000:1.8.0_281-fcs        ################################# [100%]
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...
[root@VM-0-14-centos yangzhenwei]# java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
[root@VM-0-14-centos yangzhenwei]# 

卸载JDK

[root@VM-0-14-centos /]# rpm -qa|grep jdk
jdk1.8.0_121-1.8.0_121-fcs.x86_64
[root@VM-0-14-centos /]# yum -y remove jdk1.8.0_121-1.8.0_121-fcs.x86_64
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.0_121.x86_64 2000:1.8.0_121-fcs will be erased
--> Finished Dependency Resolution
centos-sclo-rh/x86_64                  | 3.0 kB     00:00     
epel/7/x86_64                          | 4.7 kB     00:00     
epel/7/x86_64/updateinfo               | 1.0 MB     00:00     
epel/7/x86_64/primary_db               | 6.9 MB     00:00     
extras/7/x86_64                        | 2.9 kB     00:00     
extras/7/x86_64/primary_db             | 232 kB     00:00     
os/7/x86_64                            | 3.6 kB     00:00     
updates/7/x86_64                       | 2.9 kB     00:00     

Dependencies Resolved

==============================================================
 Package       Arch    Version               Repository  Size
==============================================================
Removing:
 jdk1.8.0_121  x86_64  2000:1.8.0_121-fcs    installed  263 M

Transaction Summary
==============================================================
Remove  1 Package

Installed size: 263 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2000:jdk1.8.0_121-1.8.0_121-fcs.x86_64     1/1 
  Verifying  : 2000:jdk1.8.0_121-1.8.0_121-fcs.x86_64     1/1 

Removed:
  jdk1.8.0_121.x86_64 2000:1.8.0_121-fcs                      

Complete!

2.2.查询磁盘内存

[root@VM-0-14-centos home]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          930176       0    930176   0% /dev
tmpfs             941096      24    941072   1% /dev/shm
tmpfs             941096     540    940556   1% /run
tmpfs             941096       0    941096   0% /sys/fs/cgroup
/dev/vda1       51473868 6039652  43236972  13% /
tmpfs             188220       0    188220   0% /run/user/0
[root@VM-0-14-centos home]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        909M     0  909M   0% /dev
tmpfs           920M   24K  920M   1% /dev/shm
tmpfs           920M  540K  919M   1% /run
tmpfs           920M     0  920M   0% /sys/fs/cgroup
/dev/vda1        50G  5.8G   42G  13% /
tmpfs           184M     0  184M   0% /run/user/0
[root@VM-0-14-centos home]# 

2.3.设置连接

软连接:ln -s f1 f3 ,设置的链接f3,当源文件f1删除之后,链接f3无效
硬链接:ln f1 f2 ,设置的链接f2,当源文件f1删除之后,链接f2有效

[root@VM-0-14-centos etc]# cd ..
[root@VM-0-14-centos /]# cd /home
[root@VM-0-14-centos home]# touch f1
[root@VM-0-14-centos home]# ls
ceshi  f1  redis  www  zhenwei
[root@VM-0-14-centos home]# ln f1 f2
[root@VM-0-14-centos home]# ls
ceshi  f1  f2  redis  www  zhenwei
[root@VM-0-14-centos home]#  ln -s f1 f3
[root@VM-0-14-centos home]# ls
ceshi  f1  f2  f3  redis  www  zhenwei
[root@VM-0-14-centos home]# echo "i love learn teachlolegy" >> f1
[root@VM-0-14-centos home]# cat f1
i love teachlolegy
[root@VM-0-14-centos home]# cat f3
i love teachlolegy
[root@VM-0-14-centos home]# cat f2
i love teachlolegy
[root@VM-0-14-centos home]# ls
ceshi  f1  f2  f3  redis  www  zhenwei

2.5.文件编辑和读取

文件编辑:
文件编辑器 vim
编辑文件操作:
1.命令:vim 文件名
2.打开文件之后,ctrl + i 进入编辑模式;
3.完成输入之后按esc键进入功能模式,输入:之后,输入wq可以保存编辑的文件并且推出

[root@VM-0-14-centos home]# vim 1.txt

文件读取:
cat 文件名

[root@VM-0-14-centos home]# cat 1.txt 
我喜欢吃西瓜
喜欢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞扬晴雪

学习的路上,感谢你的支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值