% 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 & # 列出所有正在运行的进程 | List all running processes ps -A # 终止正在运行的进程 | Kill a running process killall % 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 % 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 *. # 列出指定类型的所有文件 | List all files of type find . -name '*.' -print # 返回上一个目录 | Go back to previous directory cd - # 创建(空)目录 | Make (empty) directory mkdir # 删除(空)目录 | Remove (empty) directory rmdir # 无提示删除目录及其所有内容 | Remove directory with all contents without prompt rm -rf # 删除目录内容但保留目录 | Remove directory contents and keep directory rm -rf * # 切换目录 | Change directory cd % shell Symlinks # 创建符号链接 | Create symlink ln -s # 更新符号链接 | Update symlink ln -sfn # 删除符号链接 | Remove symlink unlink % Shell Files # 创建(空)文件 | Make (empty) file touch # 复制文件 | Duplicate file cp # 复制/分页文件夹及其内容 | Copy/Page folder with content cp -a / # 移动/重命名文件 | Move/Rename file mv # 移动/重命名文件并在覆盖现有文件前提示 | Move/Rename file and prompt before overwriting an existing file mv -i # 删除文件 | Remove file rm # 写入文件(将覆盖现有内容) | Write to file (will overwrite existing content) cat > # 在当前目录中搜索文件名(非内容) | Search for a filename-(not content!) in the current directory find # 在当前目录和子目录的所有文件中搜索字符串 | Search for a string inside all files in the current directory and subdrectories grep -r * # 在文件中搜索并替换 | Search and replace within file sed -i s///g # 文件的MD5哈希值 | MD5 hash for files md5 # 文件夹的MD5哈希值 | MD5 hash for folders tar c | md5sum # 加密文件 | Encrypt file openssl enc -aes-256-cbc -e -in -out # 解密文件 | Decrypt file openssl enc -aes-256-cbc -d -in -out % Shell Server # 通过ssh访问 | Access via ssh ssh # 从服务器复制文件到本地 | Copy file from server to local scp : # 从本地复制文件到服务器 | Copy file from local to server scp : # 转义文件名中的空格 | Escape files with spaces in name like this \\\ $ 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 # 用当前文件夹打开Finder | Open finder with current folder open . % Shell Variables # 注册变量 | Register variable export = # 输出变量 | Echo variable echo $ # 取消设置变量 | Unset variable unset % Shell Output & Redirects # 写入文件 | Write to file echo > # 将一个文件的内容追加到另一个文件 | Append content from a file to another file cat >> # 将行数、单词数和字符数添加到 | Add the amount of lines, words, and characters to cat | | cat > # 对文件内容进行排序(类似cat) | Sort the content of a file (like cat) sort # 将排序后的内容保存到新文件 | Save to sorted content to a new file cat | sort > # 排序并去重后保存到新文件 | Sort and remove duplicates and save to a new file sort | uniq >