功能项 | 命令实例 | 作用 |
文件创建 | vi /opt/learn/hello.txt | 在目录/opt/learn下创建文件hello.txt并进入vi编辑界面 |
| touch /opt/learn/test | 在目录/opt/learn下创建空白文件test |
| cat > /opt/catfile | 创建文件catfile并在屏幕上输入内容,最后按 Ctrl + D 退出 |
| | |
文件查看 | vi /etc/passwd | 在vi编辑器中输出文本内容 |
| cat /etc/passwd | 在屏幕输出文本内容 |
| more /etc/passwd | 分屏输出文本内容 |
| less /etc/passwd | 分屏输出文本内容并按需加载文件(适用于大文件的查看) |
| head -n 10 /etc/passwd | 只输出文件的头10行 |
| tail -n 20 /etc/passwd | 只输出文件末尾的20行 |
| strings /bin/ls | 查看二进制文件中的可打印字符 |
| | |
文件操作 | cp hello.txt /opt/test | 把文件hello.txt复制到文件夹/opt/test下 |
| cp hello.txt /opt/test/hello.cp | 把文件hello.txt复制到文件夹/opt/test下并重命名为hello.cp |
| mv hello.txt /opt/test | 把文件hello.txt剪切到文件夹/opt/test下 |
| mv hello.txt /opt/test/hello.mv | 将文件hello.txt剪切到文件夹/opt/test下并重命名为hello.mv |
| mv hello.txt hello2.txt | 重命名 |
| rm /opt/test/hello.cp | 删除文件 |
| rm -f /opt/test/hello.mv | 强制删除文件,不会有提示信息 |
| du -sk hello.txt | 查看文件hello.txt的大小(以k为单位) |
| | |
链接 | In -s hello.txt shello | 为hello.txt文件创建一个名为shello的软链接(类似于快捷方式) |
| In -d hello.txt dhello | 为hello.txt文件创建一个名为dhello的硬链接(硬链接表示所有文件中更改任意一个,其他文件的所有属性会跟着变化,如大小,更新时间,权限等) |