Linux 终端

[toc]

shell 和 终端 的概念区别

  • 终端 termimal,作用是提供一个命令的输入输出环境,在 linux 下使用组合键 ctrl+alt+T 打开的就是终端。
  • shell 是一个命令行解释器,是 linux 内核的一个外壳,负责外界与 linux 内核的交互。shell 接收用户或者其他应用程序的命令,然后将这些命令转化成内核能理解的语言并传给内核,内核执行命令完成后将结果返回给用户或者应用程序。

也就是说,当你打开一个 terminal 时,操作系统会将 terminal 和 shell 关联起来。terminal 从用户这里接收输入(键盘、鼠标等输入设备),扔给 shell,然后把 shell 返回的结果展示给用户(比如通过显示器);shell 从 terminal 拿到用户输入的命令,解析后交给操作系统内核去执行,并把执行结果返回给 terminal。

终端命令行快捷键

  • ctrl + a 回到命令行的行首
  • ctrl + e 回到命令行的行尾
  • ctrl + c 取消当前行输入的命令,并重新到下一行
  • ctrl + r 出现命令历史记录搜索提示,输入字符后会自动匹配命令
  • ctrl + b 向后退一个字符,相当于向左方向键
  • ctrl + f 向前进一个字符,相当于向右方向键
  • ctrl + p 向上翻以前的输入命令,相当于向上方向键
  • ctrl + n 向下翻以前的输入命令,相当于向下方向键
  • alt + b 向后跳一个字
  • alt + f 向前进一个字
  • ctrl + w 从光标位置向后删除一个字
  • ctrl + y 粘贴最后一个删除的字
  • ctrl + d 删除当前光标位置的一个字符
  • ctrl + u 从光标当前位置删除所有字符至行首
  • ctrl + k 从光标当前位置删除所有字符至行尾,相当于长按 ctrl + d

history – 历史命令

1
2
# 在历史中搜索 start的命令
history |grep start

mv 移动文件

1
2
# The `mv` command doesn't have an `-R` flag, it moves folders recursively
sudo mv fromPath/ toPath/

参考资料

tar 文件解压缩

  • The tar command allows you to create and extract tar archives. The tar command auto-detects compression type and extracts the archive.
  • Bzip2 is one of the most popular algorithms for compressing tar files. By convention, the name of a tar archive compressed with bzip2 ends with either .tar.bz2 or .tbz2.
1
tar -xf archive.tar.bz2

参考资料

Reference