123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- % Shell Usage
- # 用sudo重新执行上一条命令 | Re-call last input with sudo
- sudo !!
- # 帮助 | Help
- help cd / help dir (...)
- # 查找帮助 | Finding Help
- apropos directory / apropos search (...)
- # 定义自定义启动屏幕 | Define custom startup screen
- sudo nano /etc/motd
- # 以后台进程运行脚本 | Run a script as background process
- <process> &
- # 列出所有正在运行的进程 | List all running processes
- ps -A
- # 终止正在运行的进程 | Kill a running process
- killall <Process-name>
- % Shell System
- # 获取当前路径 | Get the current path
- pwd
- # 获取当前主机名 | Get the current hostname
- hostname
- # 获取当前用户 | Get the current users
- users
- # 显示日历 | Show calendar
- cal
- # 显示当前日期 | Show today's date
- date
- # 退出终端 | Exit terminal
- exit
- % Shell Permissions
- # 使用-R选项递归更改权限 | Use -R option to change permissions recursively.
- ps -ef | grep apache | grep -v grep
- # 更改组 | Change group
- chgrp <group-name-from> <group-name-to>
- % Shell Directories
- # 列出目录内容 | List directory contents
- ls
- # 列出所有目录内容 | List all directory contents
- ll
- # 按编辑时间列出所有目录内容 | List all directory contents sorted by time edited
- ls -alt
- # 列出目录(通配符匹配) | List directory (wildcard matching)
- ls *.<txt>
- # 列出指定类型的所有文件 | List all files of type
- find . -name '*.<txt>' -print
- # 返回上一个目录 | Go back to previous directory
- cd -
- # 创建(空)目录 | Make (empty) directory
- mkdir <dirname>
- # 删除(空)目录 | Remove (empty) directory
- rmdir <dirname>
- # 无提示删除目录及其所有内容 | Remove directory with all contents without prompt
- rm -rf <dirname>
- # 删除目录内容但保留目录 | Remove directory contents and keep directory
- rm -rf *
- # 切换目录 | Change directory
- cd <dirname>
- % shell Symlinks
- # 创建符号链接 | Create symlink
- ln -s <source-dirname> <destination-dirname>
- # 更新符号链接 | Update symlink
- ln -sfn <source-dirname> <destination-dirname>
- # 删除符号链接 | Remove symlink
- unlink <sample-dirname>
- % Shell Files
- # 创建(空)文件 | Make (empty) file
- touch <filename-txt>
- # 复制文件 | Duplicate file
- cp <filename> <file-copyname>
- # 复制/分页文件夹及其内容 | Copy/Page folder with content
- cp -a <old-folder>/ <new-folder>
- # 移动/重命名文件 | Move/Rename file
- mv <current-filename-path> <new-filename-path>
- # 移动/重命名文件并在覆盖现有文件前提示 | Move/Rename file and prompt before overwriting an existing file
- mv -i <current-filename> <new-filename>
- # 删除文件 | Remove file
- rm <filename-txt>
- # 写入文件(将覆盖现有内容) | Write to file (will overwrite existing content)
- cat > <filename-txt>
- # 在当前目录中搜索文件名(非内容) | Search for a filename-(not content!) in the current directory
- find <filename-txt>
- # 在当前目录和子目录的所有文件中搜索字符串 | Search for a string inside all files in the current directory and subdrectories
- grep -r <string> *
- # 在文件中搜索并替换 | Search and replace within file
- sed -i s/<original-text>/<new-text>/g <filename-txt>
- # 文件的MD5哈希值 | MD5 hash for files
- md5 <filename-txt>
- # 文件夹的MD5哈希值 | MD5 hash for folders
- tar c <folder> | md5sum
- # 加密文件 | Encrypt file
- openssl enc -aes-256-cbc -e -in <sample-filename-txt> -out <sample-encrypted-txt>
- # 解密文件 | Decrypt file
- openssl enc -aes-256-cbc -d -in <sample-encrypted> -out <sample-filename>
- % Shell Server
- # 通过ssh访问 | Access via ssh
- ssh <username_remote>
- # 从服务器复制文件到本地 | Copy file from server to local
- scp <username_remote>:<file-to-send-path> <path-to-recieve>
- # 从本地复制文件到服务器 | Copy file from local to server
- scp <file-to-send> <username_remote>:<where-to-put>
- # 转义文件名中的空格 | Escape files with spaces in name like this
- <path-to-file>\\\ <name-png>
- $ username_remote: cat ~/.ssh/config | grep -i "host "|sed 's/^[ \t]*//g' | awk '{print $2}'
- % Shell System
- # 显示磁盘空间 | Show disc space
- df -h
- # 显示磁盘空间(inode) | Show disc space (inodes)
- df -i
- # 显示当前目录的磁盘空间 | Show disc space for current directory
- du -hs
- # 当前进程(包括CPU使用率) | Current processes (also CPS usage)
- top or htop
- # 显示正在运行的php进程 | Show running php processes
- ps aux | grep php
- # 监控错误日志(实时显示文件增长) | Monitor error log (stream as file grows)
- tail error.log -f -n 0
- % Shell Apps
- # 启动应用程序 | Start appliction
- xdg-open <programme>
- # 用当前文件夹打开Finder | Open finder with current folder
- open .
- % Shell Variables
- # 注册变量 | Register variable
- export <TESTING>=<Variable-text>
- # 输出变量 | Echo variable
- echo $<Variable>
- # 取消设置变量 | Unset variable
- unset <Variable>
- % Shell Output & Redirects
- # 写入文件 | Write to file
- echo <Hello> > <hello-txt>
- # 将一个文件的内容追加到另一个文件 | Append content from a file to another file
- cat <file1-txt> >> <file2-txt>
- # 将行数、单词数和字符数添加到<file2-txt> | Add the amount of lines, words, and characters to <file2-txt>
- cat <file1-txt> | <word-count> | cat > <file2-txt>
- # 对文件内容进行排序(类似cat) | Sort the content of a file (like cat)
- sort <hello-txt>
- # 将排序后的内容保存到新文件 | Save to sorted content to a new file
- cat <file1-txt> | sort > <sorted-file1-txt>
- # 排序并去重后保存到新文件 | Sort and remove duplicates and save to a new file
- sort <file1-txt> | uniq > <uniq-file1-txt>
|