| 命令 | 解释 | 示例 | 备注 |
|---|---|---|---|
| pwd | print name of current/working directory | ||
| cd | change the working directory | cd ~ 回到当前用户的home目录 cd .. 回到上一级目录 cd /D/demo 转到绝对路径 |
当你迷路了就先pwd后cd ~
|
| mkdir 目录名 | make directories | mkdir demo mkdir "demo 1" |
文件名有空格要加引号 |
| mkdir -p 目录路径 | -p, --parents no error if existing, make parent directories as needed |
mkdir -p demo1/demo2/demo3 | 创建嵌套目录(注意第一个目录名前没有 / ) |
| whoami | print effective userid | ||
| -- | -- | -- | -- |
| ls | list directory contents | 显示当前目录内容 | |
| ls 路径 | 显示指定路径内容 | ls demo1 ls /D/download |
|
| ls -a 路径 | -a, --all do not ignore entries starting with . |
显示隐藏文件(以 . 开头) | |
| ls -l 路径 | -l use a long listing format | 显示更多信息 | |
| ls -la 路径 | 综上,以上路径都可为空或相对路径或绝对路径
|
||
| -- | -- | -- | -- |
| echo "hello" > 文件路径 | 重定向,创建文件 | echo "hello" > 1.txt | |
| echo "hello" >! 文件路径 | 强制创建文件 | echo "hello" >! 1.txt | windows不支持 |
| echo "hello" >> 文件路径 | 追加文件内容 | echo "more" >> 1.txt | |
| touch 文件名 | 创建文件 | touch 2.txt | |
| touch 已存在文件名 | change file timestamps 改变文件更新时间 | touch 2.txt | |
| -- | -- | -- | -- |
| cp 源路径 目标路径 | 复制文件 | cp 1.txt 2.txt cp 1.txt /D/demo |
|
| cp -r 源目录 目标目录 | 复制目录 | cp -r /C/demo1 /D/demo2 | 不要忘记-r
|
| -- | -- | -- | -- |
| mv 源路径 目标路径 | move (rename) files | mv 1.txt /D/2.md mv demo1 demo_1 |
文件或文件夹都适用 |
| -- | -- | -- | -- |
| man | an interface to the on-line reference manuals | man rm 查看rm操作手册 |
windows不支持 |
| -- | -- | -- | -- |
| rm 文件路径 | 删除文件 | rm 1.txt | |
| rm -f 文件路径 | -f, --force ignore nonexistent files, never prompt |
rm -f 1.txt | |
| rm -r 目录路径 | -r, -R, --recursive remove directories and their contents recursively |
rm -r demo | |
| rm -rf 目录路径 | 强制删除目录 | ||
| -- | -- | -- | -- |
| tree | 查看目录结构 | windows不支持 | |
| ln -s 真实文件 链接 | make links between files建立软链接 make links between files -s, --symbolic make symbolic links instead of hard links |
windows不支持 | |
| -- | -- | -- | -- |
| curl -L https://www.baidu.com > baidu.html | 下载文件 | ||
| wget -p -H -e robots=off https://www.baidu.com | 拷贝网页 | windows不支持 | |
| df -kh | -k like --block-size=1K -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) |
||
| du -sh . | -s, --summarize display only a total for each argument 当前目录大小 |
||
| du -h | 各文件大小 | ||
| -- | -- | -- | -- |
| less | Open a file for interactive reading, allowing scrolling and search | 按q退出 | |
| more | Open a file for interactive reading, allowing scrolling and search (in forward direction only) | 按q退出 | |
| cat | concatenate files and print on the standard output | cat 1.txt cat 1.txt 2.txt 3.txt cat 1.txt 2.txt > 3.txt cat 1.txt 2.txt >> 3.txt |
|
| exit | cause the shell to exit | 关掉bash |
小技巧
-
↑↓键翻阅历史命令 -
Tab自动补全命令








网友评论