第三章 了解RHEL8常见命令

本文详细介绍了Linux系统中的常见命令,如创建和删除目录、cd命令的用法、cp和mv文件操作、文件类型判断、行数统计、别名设置以及查看文件内容的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、常见命令

1.创建和删除目录。

2.cd命令的用法。

3.cp复制命令,mv移动命令。

4.常见命令。

一、常见命令

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值