zoukankan      html  css  js  c++  java
  • Linux 日常常用指令

       最近搞了一个阿里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即可上传下载。

      

  • 相关阅读:
    241. Different Ways to Add Parentheses java solutions
    89. Gray Code java solutions
    367. Valid Perfect Square java solutions
    46. Permutations java solutions
    116. Populating Next Right Pointers in Each Node java solutions
    153. Find Minimum in Rotated Sorted Array java solutions
    判断两颗树是否相同
    求二叉树叶子节点的个数
    求二叉树第k层的结点个数
    将二叉排序树转换成排序的双向链表
  • 原文地址:https://www.cnblogs.com/rekent/p/7355548.html
Copyright © 2011-2022 走看看