目录
一、常见命令
1.创建和删除目录。
(1)创建目录(文件夹)是命令mkdir。
[root@rhel1 ~]# mkdir dir 第一种方式
[root@rhel1 ~]# mkdir -p dir1/dir2 第二种方式
- -p:选项的意思,如果dir1不存在,会打dir1也创建出来。
(2)删除目录的命令如下。
[root@rhel1 ~]# rmdir dir 删除dir目录
[root@rhel1 ~]# rm -rf dir 强行删除
2.cd命令的用法。
(1)创建测试目录,{11,22}的意思是在ff目录里面创建11,22这两个目录。
[root@rhel1 ~]# mkdir -p aa/bb/cc/dd/ee/ff/{11,22}
(2)查看这个目录的结构。
[root@rhel1 ~]# tree aa 查看aa目录结构
aa
└── bb
└── cc
└── dd
└── ee
└── ff
├── 11
└── 22
(3)使用cd命令切换目录。
[root@rhel1 ~]# cd aa/bb/cc/dd/ee/ff/11/ 切换
[root@rhel1 11]# pwd 查看当前所在的目录
/root/aa/bb/cc/dd/ee/ff/11
[root@rhel1 11]# cd 返回根目录
3.cp复制命令,mv移动命令。
(1)创建测试目录。
[root@rhel1 ~]# touch bdqn.exe 创建bdqn.exe文本
(2)使用cp命令把bdqn.exe文本复制到/mnt目录里面。
[root@rhel1 ~]# cp bdqn.exe /mnt/ 复制到/mnt目录
[root@rhel1 ~]# ls /mnt/ 查看/mnt目录
bdqn.exe hgfs
[root@rhel1 ~]# cp bdqn.exe /mnt/www.exe 重命名为www.exe
[root@rhel1 ~]# ls /mnt/ 查看
bdqn.exe hgfs www.exe
(3)mv命令移动目录。
[root@rhel1 ~]# mkdir bdqn 创建bdqn目录
[root@rhel1 ~]# mv bdqn /opt/ 把bdqn移动到/opt目录里面
4.常见命令。
(1)用file命令来判断/etc/hosts是什么类型的文件。
[root@rhel1 ~]# file /etc/hosts
/etc/hosts: ASCII text 这里显示/etc/hosts是个文本文件
(2)用wc统计文件的行数、单词数、字符数。
[root@rhel1 ~]# wc /etc/hosts 统计
2 10 158 /etc/hosts 结果
[root@rhel1 ~]# wc -l /etc/hosts 只查看行数
[root@rhel1 ~]# wc -w /etc/hosts 只查看单词数
[root@rhel1 ~]# wc -c /etc/hosts 只查看字符数
- 2表示/etc/hosts有2行,10表示/etc/hosts有10个单词,158表示/etc/hosts一共有158个字
符。
(3)用alias命令创建别名,用unalias命令取消别名。
[root@rhel1 ~]# alias xx='ifconfig' 为ifconfig设置一个别名为xx
[root@rhel1 ~]# xx 用xx查看网络
[root@rhel1 ~]# unalias xx 取消xx这个别名
(4)cat用于查看比较小的(文本)文件。
[root@rhel1 ~]# cat /etc/hosts 查看/etc/hosts文本
(5)more命令用于查看比较大的文本看,按b向上翻一屏,按q退出文本。
[root@rhel1 ~]# more /etc/passwd