shell.cheat 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. % Shell Usage
  2. # 用sudo重新执行上一条命令 | Re-call last input with sudo
  3. sudo !!
  4. # 帮助 | Help
  5. help cd / help dir (...)
  6. # 查找帮助 | Finding Help
  7. apropos directory / apropos search (...)
  8. # 定义自定义启动屏幕 | Define custom startup screen
  9. sudo nano /etc/motd
  10. # 以后台进程运行脚本 | Run a script as background process
  11. <process> &
  12. # 列出所有正在运行的进程 | List all running processes
  13. ps -A
  14. # 终止正在运行的进程 | Kill a running process
  15. killall <Process-name>
  16. % Shell System
  17. # 获取当前路径 | Get the current path
  18. pwd
  19. # 获取当前主机名 | Get the current hostname
  20. hostname
  21. # 获取当前用户 | Get the current users
  22. users
  23. # 显示日历 | Show calendar
  24. cal
  25. # 显示当前日期 | Show today's date
  26. date
  27. # 退出终端 | Exit terminal
  28. exit
  29. % Shell Permissions
  30. # 使用-R选项递归更改权限 | Use -R option to change permissions recursively.
  31. ps -ef | grep apache | grep -v grep
  32. # 更改组 | Change group
  33. chgrp <group-name-from> <group-name-to>
  34. % Shell Directories
  35. # 列出目录内容 | List directory contents
  36. ls
  37. # 列出所有目录内容 | List all directory contents
  38. ll
  39. # 按编辑时间列出所有目录内容 | List all directory contents sorted by time edited
  40. ls -alt
  41. # 列出目录(通配符匹配) | List directory (wildcard matching)
  42. ls *.<txt>
  43. # 列出指定类型的所有文件 | List all files of type
  44. find . -name '*.<txt>' -print
  45. # 返回上一个目录 | Go back to previous directory
  46. cd -
  47. # 创建(空)目录 | Make (empty) directory
  48. mkdir <dirname>
  49. # 删除(空)目录 | Remove (empty) directory
  50. rmdir <dirname>
  51. # 无提示删除目录及其所有内容 | Remove directory with all contents without prompt
  52. rm -rf <dirname>
  53. # 删除目录内容但保留目录 | Remove directory contents and keep directory
  54. rm -rf *
  55. # 切换目录 | Change directory
  56. cd <dirname>
  57. % shell Symlinks
  58. # 创建符号链接 | Create symlink
  59. ln -s <source-dirname> <destination-dirname>
  60. # 更新符号链接 | Update symlink
  61. ln -sfn <source-dirname> <destination-dirname>
  62. # 删除符号链接 | Remove symlink
  63. unlink <sample-dirname>
  64. % Shell Files
  65. # 创建(空)文件 | Make (empty) file
  66. touch <filename-txt>
  67. # 复制文件 | Duplicate file
  68. cp <filename> <file-copyname>
  69. # 复制/分页文件夹及其内容 | Copy/Page folder with content
  70. cp -a <old-folder>/ <new-folder>
  71. # 移动/重命名文件 | Move/Rename file
  72. mv <current-filename-path> <new-filename-path>
  73. # 移动/重命名文件并在覆盖现有文件前提示 | Move/Rename file and prompt before overwriting an existing file
  74. mv -i <current-filename> <new-filename>
  75. # 删除文件 | Remove file
  76. rm <filename-txt>
  77. # 写入文件(将覆盖现有内容) | Write to file (will overwrite existing content)
  78. cat > <filename-txt>
  79. # 在当前目录中搜索文件名(非内容) | Search for a filename-(not content!) in the current directory
  80. find <filename-txt>
  81. # 在当前目录和子目录的所有文件中搜索字符串 | Search for a string inside all files in the current directory and subdrectories
  82. grep -r <string> *
  83. # 在文件中搜索并替换 | Search and replace within file
  84. sed -i s/<original-text>/<new-text>/g <filename-txt>
  85. # 文件的MD5哈希值 | MD5 hash for files
  86. md5 <filename-txt>
  87. # 文件夹的MD5哈希值 | MD5 hash for folders
  88. tar c <folder> | md5sum
  89. # 加密文件 | Encrypt file
  90. openssl enc -aes-256-cbc -e -in <sample-filename-txt> -out <sample-encrypted-txt>
  91. # 解密文件 | Decrypt file
  92. openssl enc -aes-256-cbc -d -in <sample-encrypted> -out <sample-filename>
  93. % Shell Server
  94. # 通过ssh访问 | Access via ssh
  95. ssh <username_remote>
  96. # 从服务器复制文件到本地 | Copy file from server to local
  97. scp <username_remote>:<file-to-send-path> <path-to-recieve>
  98. # 从本地复制文件到服务器 | Copy file from local to server
  99. scp <file-to-send> <username_remote>:<where-to-put>
  100. # 转义文件名中的空格 | Escape files with spaces in name like this
  101. <path-to-file>\\\ <name-png>
  102. $ username_remote: cat ~/.ssh/config | grep -i "host "|sed 's/^[ \t]*//g' | awk '{print $2}'
  103. % Shell System
  104. # 显示磁盘空间 | Show disc space
  105. df -h
  106. # 显示磁盘空间(inode) | Show disc space (inodes)
  107. df -i
  108. # 显示当前目录的磁盘空间 | Show disc space for current directory
  109. du -hs
  110. # 当前进程(包括CPU使用率) | Current processes (also CPS usage)
  111. top or htop
  112. # 显示正在运行的php进程 | Show running php processes
  113. ps aux | grep php
  114. # 监控错误日志(实时显示文件增长) | Monitor error log (stream as file grows)
  115. tail error.log -f -n 0
  116. % Shell Apps
  117. # 启动应用程序 | Start appliction
  118. xdg-open <programme>
  119. # 用当前文件夹打开Finder | Open finder with current folder
  120. open .
  121. % Shell Variables
  122. # 注册变量 | Register variable
  123. export <TESTING>=<Variable-text>
  124. # 输出变量 | Echo variable
  125. echo $<Variable>
  126. # 取消设置变量 | Unset variable
  127. unset <Variable>
  128. % Shell Output & Redirects
  129. # 写入文件 | Write to file
  130. echo <Hello> > <hello-txt>
  131. # 将一个文件的内容追加到另一个文件 | Append content from a file to another file
  132. cat <file1-txt> >> <file2-txt>
  133. # 将行数、单词数和字符数添加到<file2-txt> | Add the amount of lines, words, and characters to <file2-txt>
  134. cat <file1-txt> | <word-count> | cat > <file2-txt>
  135. # 对文件内容进行排序(类似cat) | Sort the content of a file (like cat)
  136. sort <hello-txt>
  137. # 将排序后的内容保存到新文件 | Save to sorted content to a new file
  138. cat <file1-txt> | sort > <sorted-file1-txt>
  139. # 排序并去重后保存到新文件 | Sort and remove duplicates and save to a new file
  140. sort <file1-txt> | uniq > <uniq-file1-txt>