01 - shell基础知识

shell是什么?

  • shell是一个命令行解释器,它为用户提供了一个面向linux内核发送请求以便运行程序的界面系统级程序,用户可以使用shell来启动、挂起、停止甚至是编写一些程序。
  • shell还是一个相当强大的编程语言,易编写、易调试,灵活性较强。shell是解释执行的脚本语言,在shell中能直接调用linux系统命令。
shell在linux系统中的地位

shell是用户与linux内核之间的解释器

  • 常见的shell解释器
    • /bin/bash
    • /bin/sh
    • /bin/csh
    • /bin/tcsh
  • 解释器负责将用户的指令翻译为内核可以识别的指令
  • 通过usermod、chsh可以更改登录shell

查看当前系统支持的shell

~ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

修改当前用户解释器为zsh

chsh -s `which zsh`

指定test用户的登录shell为tcsh

usermod -s /bin/tcsh test

bash基本特性

  • 快捷键、Tab键补齐
  • 命令历史(history)
  • 命令别名(aliase)ll: ls -l
  • 标准输入与输出的重定向(>、>>、2>、2>>、&>)
 day01 ls a.txt xxyzz.txt
ls: a.txt: No such file or directory
ls: xxyzz.txt: No such file or directory
➜  day01 ls a.txt xxyzz.txt 2> b.txt
➜  day01 ls a.txt xxyzz.txt b.txt 2> b.txt
b.txt
➜  day01 ls a.txt xxyzz.txt b.txt &> b.txt
  • 管道(|)

shell执行命令的方式

  • 交互式(命令式)
    • 人工干预
    • 逐条解释执行、效率低
  • 非交互式(脚本)
    • 需要提前设计
    • 批量执行、效率高
#非交互式修改密码
echo 'password' | passwd --stdin username

小结

  • 区分shell和bash
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容