linucx的一些基本操作命令
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
我喜欢吃西瓜
喜欢!