shell / bash / 命令行的基本命令总结

150 阅读1分钟

进入和退出 Bash

  • 如果你的 Shell 不是 Bash,可以输入 bash 命令启动 Bash:
    $ bash
    
  • 退出 Bash 环境,可以使用 exit 命令,或者按 Ctrl + d
    $ exit
    

Bash 基本命令

  • pwd(print working directory):显示当前所在的目录
  • ls(list):显示当前文件夹的内容
    • ls -l(long):long list format(显示更多细节)
    • ls -a(all):显示所有的文件(包括以 . 开头的文件)
  • cd(change directory):进入某个文件夹
    • cd . :保持原地不动
    • cd .. :回到上一层
      • cd ../.. :回到上上层(以此类推)
  • more <filename> :查看文件内容
  • clear :清空界面
  • mkdir <folder_name>(make directory):新建文件夹
    • mkdir <folder>/<new_folder_name> :在更深的层级新建文件夹
  • echo :print anything to the terminal
    • echo text >> filename :print to a file
  • touch <filename> :新建文件
  • cp <file> <destination> (copy):复制文件至某处
    • cp -r(copy directories recursively):复制整个文件夹
  • rm <filename>(remove):移除文件
    • rm -r (remove directories and their contents recursively):移除文件夹和里面的文件
  • rmdir <directory_name>(remove directory):移除文件夹(当文件夹为空时见效)
  • mv <filename> <new_filename> (move):重命名 rename something
  • mv <file> <destination> (move):move something
    • <destination> 可以是文件路径
      • .. :表示移动到上一层文件夹
    • mv <file_path> <destination>:移动并不位于当前文件夹的文件
  • find <folder_name> :查看某个文件夹的文件树(层次),直接输入 find 会展示当前文件夹的文件树
    • find -name <filename>/<folder_name> : search for something

获取帮助

  • 大多数命令可以跟一个 --help 来获取帮助