zoukankan      html  css  js  c++  java
  • shell简单用法笔记(一)

    一、linux中主要用的bash shell;查看linux系统中支持的shell种类可用

    vim /etc/shell

    执行shel脚步的方式:

    1、赋予脚步可执行权限,使用相对或绝对路径调用该脚本

    chmod  755  test.sh   #赋予该脚本可执行权限
    ./test.sh                     #以相对路径执行该命令
    ~/test.sh                   #一绝对路径执行该命令

    2、使用shell命令调用脚本(此时脚本可以不需要执行权限):

    bash  test.js     #使用bash shell执行
    sh      test.js     #使用sh执行

     注意:shell脚本以  #! /bin/bash 开头,表示一下写的是shell脚本(相当与php的<?php ?>)

    二、shell历史命令的查看

    运行:  history 可查看在该用户下已经使用的命令(通过上下箭头可以查看前一条或后一条执行的命令)

    通过  vim ~/.bash_history  可查看已经被保持的历史命令

    通过查看 /etc/profile  里可以查看到最多保存的历史记录的条数

    通过:  !n  可重复执行历史记录的第n条命令

    通过:    !str  可重复执行以str开头的最后一条历史命令

    三、shell定义别名

    alias  ls = "ls -l"   #定义ls -l 的别名为ls,当执行ls的时候实际上执行的是ls -l

    别名的配置(配置别名永久生效):

    编辑  ~/.bashrc

    四、输出重定向

    标准输出            /dev/stdin        0       键盘

    标准输出            /dev/stdout      1       显示器

    标准错误输出     /dev/strerr         2       显示器

    ls  >  aa     覆盖到aa

    ls >> aa    追加到aa

    ls  hahah  2>aa  将错误输出到aa(错误输出的两侧不能加空格)

    ls  &>  aa             将正确和错误输出到aa

    五、多命令执行

    cd ; ls ; date          #中断中输入后会顺序执行该3条命令
    ls  aaa && date      #前一条正确执行后,后面一条才执行
    ls  aaa ||  date       #前一条命令错误执行,后一条命令才执行
    ls aaa && echo yes || echo no          #ls aaa正确执行输出yes,执行错误输出no
    
    ls | grep  etc    #前一条命令的执行结果,作为后一条命令的执行条件

    六、变量

    1、变量分类

    • 本地变量
    • 环境变量
    • 位置参数变量
    • 预定义变量

     环境变量配置文件:

    /etc/profile

    /etc/bashrc

    ~/.bashrc

    ~/.bash_profile

    前两个针对所有用户生效,后两个针对指定用户生效

  • 相关阅读:
    python-super方法
    python--mixin
    python中将输出写入文件
    一致性hash算法
    mysql之触发器trigger
    python内置函数
    python3.5+Django2.2+pymysql+mysql
    File "D:PythonPython37-32libsite-packagesdjangoviewsdebug.py", line 332, in get_traceback_html   t = DEBUG_ENGINE.from_string(fh.read())
    RuntimeError: You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to po
    python:面向对象
  • 原文地址:https://www.cnblogs.com/liyuanhong/p/5655867.html
Copyright © 2011-2022 走看看