SSH remote login, .sh file suffix run, ll command results show, VIM mode switch

SSH remote login, .sh file suffix run, ll command results show, VIM mode switch

Remote SSH login

  • SSH is a network protocol, specifically for remote login session, and other network services security protocol for encrypted login between computers, the data is encrypted.

  • SSH is mainly used for remote login, the main login password and public key login, password login now simply under the basic usage:

    #使用root账户登录远程主机  默认端口是22 可以修改端口为其它的
    [root@localhost ~]# ssh root@ip  -p 22

.sh file suffix run

  • Basic instructions: in linux .sh file is a script file, mostly bash script. Therefore you need to be "in writing .sh file #!/bin/bash" beginning of the line, before the symbol "#!" Is used to indicate parameters that follow it Linux system is a program used to execute the file.
    Run the file command: sh xxx.sh" ." You can also switch to the directory where the file is executed directly.

  • Goal: to create in your home directory test folder, and the folder is created in the test practice.sh file, the file executed goal is to create a new folder test1 in / test folder.

  • Specific ways:

    #切换到根目录下
    root@iZ2zeakeu2oah20tpsqcp5Z:~# cd /
    #在/下创建目录test
    root@iZ2zeakeu2oah20tpsqcp5Z:/# mkdir test
    #查看是否创建成功
    root@iZ2zeakeu2oah20tpsqcp5Z:/# ll
    #切换到刚创建的目录下
    root@iZ2zeakeu2oah20tpsqcp5Z:/# cd test
    #创建文件practice.sh
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# touch practice.sh
    #进入vim编辑模式
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# vim practice.sh
      #按下字母i,由“正常模式“进入到”插入模式“,编写以下三行,按下esc回到正常模式,按下“:”进入到命令模式,输入“wq”, 退出编辑模式。
          #! /bin/bash
          cd /test
          mkdir test1
    #使用ll(ls -l)命令,看当前用户是否有执行权限 如果没有 需要给当前用户添加权限
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# ll
    #添加执行权限
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# chmod +x practice.sh
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# ll
    #执行该文件  可以看到/test目录下有test1目录
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# ./practice.sh
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# ll
    #查看文件大小  du命令用于显示目录或文件的大小。  
    #-s或--summarize 仅显示总计。 
    #-h或--human-readable 以K,M,G为单位,提高信息的可读性。
    root@iZ2zeakeu2oah20tpsqcp5Z:/test# du -sh *
    • Specific implementations of command pictures

    • Check the file size of the picture the way

    image-20191011225825527

ll command results show

  • llNot a command is ls -lan alias.

  • lsThat list, show the contents of the directory.

  • -l option: long output format list, can demonstrate is a file or directory, its size, owner and modification date and time, the name of the file or directory and file permissions on it.

  • ll ls and output the result of discrimination

  • ll lists all the file information in the files, including hidden files, and ls -l list only explicit document describing these two commands are equivalent to or not!

  • The result of input ll command in detail.

  • As shown, after the current user has permission to view the operation performed and gives practice.sh current user performs an operation, an input result display ll command follows:

    image-20191012095124802

  • After performing practice.sh file (/ test directory Add test1 directory), each field is as follows:

    File Properties Number of files owner group belongs File size Filing date file name
    drwxr-xr-x 3 root root 4096 Oct 11 19:23 ./
    drwxr-xr-x 23 root root 4096 Oct 11 14:54 ../
    -rwxr-xr-x 1 root root 34 Oct 11 14:58 practice.sh*
    drwxr-xr-x 2 root root 4096 Oct 11 15:00 test1/
    • 文件的三个属性:可读(r:Read),可写(w:Write),可执行(x:eXecute)。

      • 在文件属性列共十个格子,将其分为1-3-3-3
      • 1:特殊表示格,表示目录连结文件
        • d表示目录,例如drwxr-xr-x;
        • l表示连结文件;
      • 横“-”表示,则表示这是文件,例如-rwxr-xr-x。

      • 3-3-3 以drwxr-xr-x为例,d-->rwx(Owner)r-x(Group)r-x(Other);
        • 原因:Linux是多用户多任务系统,一个文件可能同时被许多人使用,因此要设好每个文件的权限。
        • 表示的意思:
          • 使用者自己可读,可写,可执行;
          • 同一组的用户可读,不可写,可执行;
          • 其它用户可读,不可写,可执行。
    • 文件数中:如果是目录,表示它的第一级子目录的个数;实际目录计算方法:看到的值减2。

      • 例如/test目录下,只有一个子目录test1,所以应该是1,这里却显示3,这是因为要加上.目录和..目录。在linux下,.目录表示当前目录,..目录表示上一级目录。
    • 颜色
      • practice.sh:亮绿色表示可执行文件;
      • 灰白色表示普通文件;
      • 亮红色表示压缩文件;
      • test1:灰蓝色表示目录;
      • 亮蓝色表示链接文件;
      • 亮黄色表示设备文件

VIM模式切换

  • vim的四种模式
    • 正常模式 (Normal-mode)
    • 插入模式 (Insert-mode)
    • 命令模式 (Command-mode)
    • 可视模式 (Visual-mode)
  • 模式切换
    • 使用vim进入文件中后,默认正常模式。其他模式切换到正常模式:ESC键。
    • 正常模式转换到插入模式:按下I、i、a、A键。
    • 正常模式转换到命令模式:按下:冒号键。
  • 在插入模式下输入完文本后,按下:ESC键后进入命令模式:

    #保存文件,退出vi编辑器
    :wq
    #强制保存文件,退出vi编辑器
    :wq!
    #保存文件,但不退出vi编辑器
    :w
    #强制保存文件
    :w!
    #退出vi编辑器 如果文件有变化,会提示
    :q
    #不保存文件,退出vi编辑器
    :q! 
    #放弃所有修改,从上次保存文件开始再编辑命令历史
    :e! 

原创不易,欢迎转载,转载时请注明出处,谢谢!
作者:潇~萧下
原文链接:https://www.cnblogs.com/manongxiao/p/11669037.html

Guess you like

Origin www.cnblogs.com/manongxiao/p/11669037.html