Linux 日常常用指令及应用小结
程序员文章站
2023-09-03 09:27:04
最近搞了一个阿里ecs,centos7,涉及到一些基本的linux指令,在这里总结一下,在搭环境中常用的一些指令,熟悉这些指令就基本能够使用centos进行日常操作了。...
最近搞了一个阿里ecs,centos7,涉及到一些基本的linux指令,在这里总结一下,在搭环境中常用的一些指令,熟悉这些指令就基本能够使用centos进行日常操作了。
更多的可以参考系统自带的 “cammand --help” ,很实用。
目录相关指令
/*cd指令 *跳至到xx目录下,从xshell远程登陆进去的目录是/root *cd .. 返回上一层目录 */ [root@lettiy ~]# cd /usr/local /*ls 显示当前目录下的所有文件 */ [root@lettiy local]# ls aegis bin etc games include lib lib64 libexec sbin share src /*mkdir 新建,可以是目录,可以是文件 */ [root@lettiy ~]# mkdir mytest [root@lettiy ~]# ls mytest [root@lettiy mytest]# mkdir text.txt [root@lettiy mytest]# ls text.txt
文件处理指令(移动,删除,复制<cp 基本操作类似于mv>)
/*mv 可用于改名、也可用于移动 */ [root@lettiy mytest]# mv text.txt newname.txt [root@lettiy mytest]# ls newname.txt [root@lettiy mytest]# mv newname.txt newdir [root@lettiy mytest]# ls newdir [root@lettiy mytest]# cd newdir [root@lettiy newdir]# ls newname.txt /*rm 用于删除文件 普通删除文件用rm -f xx 普通目录删除 rm -rf xx 批量删除同一名字 rm -v xx* (此处*类似于通配符) */ [root@lettiy newdir]# ls new1 new2 new3 new4 newname.txt [root@lettiy newdir]# rm -f newname.txt [root@lettiy newdir]# ls new1 new2 new3 new4 [root@lettiy newdir]# rm -rf new4.txt [root@lettiy newdir]# ls new1 new2. new3 [root@lettiy newdir]# rm -rf -v new* removed directory: ‘new1' removed directory: ‘new2' removed directory: ‘new3'
文件下载与解压
/*wget 文件下载 wget url即可 */ [root@lettiy newdir]# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7.0.79.tar.gz --2017-08-13 23:35:56-- http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7.0.79.tar.gz resolving mirrors.hust.edu.cn (mirrors.hust.edu.cn)... 202.114.18.160 connecting to mirrors.hust.edu.cn (mirrors.hust.edu.cn)|202.114.18.160|:80... connected. http request sent, awaiting response... 200 ok length: 8975395 (8.6m) [application/octet-stream] saving to: ‘apache-tomcat-7.0.79.tar.gz 100%[================================================================================>] 8,975,395 19.3kb/s in 4m 36s 2017-08-13 23:40:33 (31.8 kb/s) - ‘apache-tomcat-7.0.79.tar.gz' saved [8975395/8975395] /*tar 对于tar.gz文件进行解压,解压为rpm文件再安装 tar -zxvf */ [root@lettiy newdir]# ls apache-tomcat-7.0.79.tar.gz [root@lettiy newdir]# tar -zxvf apache-tomcat-7.0.79.tar.gz apache-tomcat-7.0.79/bin/catalina.sh apache-tomcat-7.0.79/bin/configtest.sh apache-tomcat-7.0.79/bin/daemon.sh apache-tomcat-7.0.79/bin/digest.sh …… [root@lettiy newdir]# ls apache-tomcat-7.0.79 apache-tomcat-7.0.79.tar.gz
文件安装与卸载
centos集成了yum,可配置源(repository)进行安装
/*yum 安装/卸载 yum install software yum remove software */ [root@lettiy newdir]# yum install postgresql /*查看yum可安装的软件包,可配合grep进行关键字查询,例如‘java'*/ [root@lettiy newdir]# yum list [root@lettiy newdir]# yum list|grep 'java' /*rpm 刚刚解压tar得到的rpm文件则需要使用rpm 安装rpm -ivh 删除rpm -e 查看已经安装rpm -qa */ [root@lettiy newdir]# rpm -ivh software.rpm
文件更改/查看
/*文件查看 cat指令、more指令、vi指令三者都可以实现查看 */ [root@lettiy newdir]# cat /etc/profile # /etc/profile # system wide environment and startup programs, for login setup # functions and aliases go in /etc/bashrc # it's not a good idea to change this file unless you know what you # are doing. it's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${path}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then path=$path:$1 else path=$1:$path fi esac } if [ -x /usr/bin/id ]; then if [ -z "$euid" ]; then # ksh workaround euid=`/usr/bin/id -u` uid=`/usr/bin/id -ru` fi user="`/usr/bin/id -un`" logname=$user mail="/var/spool/mail/$user" fi # path manipulation if [ "$euid" = "0" ]; then pathmunge /usr/sbin pathmunge /usr/local/sbin else pathmunge /usr/local/sbin after pathmunge /usr/sbin after fi hostname=`/usr/bin/hostname 2>/dev/null` histsize=1000 if [ "$histcontrol" = "ignorespace" ] ; then export histcontrol=ignoreboth else export histcontrol=ignoredups fi export path user logname mail hostname histsize histcontrol # by default, we want umask to get set. this sets it for login shell # current threshold for system reserved uid/gids is 200 # you could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $uid -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge export java_home=/usr/develop/java/jdk1.8.0_144 export path=$java_home/bin/:$path export classpath=$java_home/jre/lib/ext:$java_home/lib/tools.jar export catalina_home=/usr/develop/tomcat/apache-tomcat-8.5.20 /*vi vi directory 如果目录下存在则打开 如果不存在则新建一个空文件 */
如果要修改,进入按 i ,即可进入insert模式,进行更改;
保存:先esc,然后输入:
wq:保存退出
q!:不保存退出
主要用于修改配置文件 ,例如:etc/proflie
端口和进程监控常用
/*ps 检测软件是否运行 或查看正在运行的进程 ps -ef|grep 'name' 例如:检测tomcat的运行状况 */ [root@lettiy newdir]# ps -ef|grep 'tomcat' root 19785 1 0 aug12 ? 00:01:05 /usr/develop/java/jdk1.8.0_144/bin/java -djava.util.logging.config.file=/usr/develop/tomcat/apache-tomcat-8.5.20/conf/logging.properties -djava.util.logging.manager=org.apache.juli.classloaderlogmanager -djdk.tls.ephemeraldhkeysize=2048 -djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/develop/tomcat/apache-tomcat-8.5.20/bin/bootstrap.jar:/usr/develop/tomcat/apache-tomcat-8.5.20/bin/tomcat-juli.jar -dcatalina.base=/usr/develop/tomcat/apache-tomcat-8.5.20 -dcatalina.home=/usr/develop/tomcat/apache-tomcat-8.5.20 -djava.io.tmpdir=/usr/develop/tomcat/apache-tomcat-8.5.20/temp org.apache.catalina.startup.bootstrap start root 22647 22470 0 23:58 pts/0 00:00:00 grep --color=auto tomcat /*netstat netstat -tl 查看当前tcp监听端口 netstat -tlp 查看当前tcp监听端口, 需要显示监听的程序名,当不清楚mysql的监听端口时比较好用 netstat -tl | grep 34006 只查看mysql的监听端口,当前启动的mysql端口为34006,明确知道mysql监听端口时使用 */
本地文件上传
需利用lrzsz
yum install lrzsz
然后使用rz sz即可上传下载。
总结
以上所述是小编给大家介绍的linux 日常常用指令及应用小结,希望对大家有所帮助