第二章_常见指令以及权限理解

1. ls 指令

ls(英文全拼:list files): 列出目录及文件名

语法:

  • -a :全部的文件,连同隐藏文件( 开头为 . 的文件) 一起列出来(常用)
  • -d :仅列出目录本身,而不是列出目录内的文件数据(常用)
  • -l :长数据串列出,包含文件的属性与权限等等数据;(常用)

例如

1.1 列出目录及文件名

[FirstUser@VM-12-12-centos ~]$ ls
a.out  Code  mttest.c  mytest.c

1.2 列出全部的文件

[FirstUser@VM-12-12-centos ~]$ ls -a
.  ..  a.out  .bash_history  .bash_logout  .bash_profile  .bashrc  .cache  Code  .config  mttest.c  mytest.c

1.3 仅列出目录本身

[FirstUser@VM-12-12-centos ~]$ ls -d
.

1.4 长数据串列出

[FirstUser@VM-12-12-centos ~]$ ls -l
total 24
-rwxrwxr-x 1 FirstUser FirstUser 8360 May 20 16:24 a.out
drwxrwxr-x 3 FirstUser FirstUser 4096 May 20 16:34 Code
-rw-rw-r-- 1 FirstUser FirstUser   70 May 20 16:19 mttest.c
-rw-rw-r-- 1 FirstUser FirstUser   70 May 20 16:23 mytest.c

2.cd 指令

cd是Change Directory的缩写,这是用来变换工作目录的命令。

语法:cd [相对路径或绝对路径]

2.1 使用 mkdir 命令创建 newdir 目录

[FirstUser@VM-12-12-centos Code]$ mkdir newdir

查看当前目录

[FirstUser@VM-12-12-centos /]$ pwd
/

2.2 使用绝对路径切换到 newdir 目录

[FirstUser@VM-12-12-centos /]$ cd /home/FirstUser/Code/newdir

查看当前目录

[FirstUser@VM-12-12-centos newdir]$ pwd
/home/FirstUser/Code/newdir

2.3 使用相对路径切换到 newdir 目录

返回上层目录

[FirstUser@VM-12-12-centos newdir]$ cd ..

查看当前目录

[FirstUser@VM-12-12-centos Code]$ pwd
/home/FirstUser/Code

进入newdir 目录

[FirstUser@VM-12-12-centos Code]$ cd newdir/

查看当前目录

[FirstUser@VM-12-12-centos newdir]$ pwd
/home/FirstUser/Code/newdir

2.4 回到家目录

[FirstUser@VM-12-12-centos newdir]$ cd ~

查看当前目录

[FirstUser@VM-12-12-centos ~]$ pwd
/home/FirstUser

2.5 回到上层目录

[FirstUser@VM-12-12-centos ~]$ cd ..

查看当前目录

[FirstUser@VM-12-12-centos home]$ pwd
/home

3. pwd 指令

pwd 是 Print Working Directory 的缩写,也就是显示目前所在目录的命令。

显示当前目录

[FirstUser@VM-12-12-centos home]$ pwd
/home

4. mkdir 指令

mkdir (make directory),创建新的目录。

语法:mkdir [目录名称]

选项与参数:

  • -p :从该目录起,一次创建多级新目录

4.1 创建单层目录

创建newdir2目录

[FirstUser@VM-12-12-centos ~]$ mkdir newdir2

进入newdir2目录

[FirstUser@VM-12-12-centos ~]$ cd newdir2/

查看当前目录

[FirstUser@VM-12-12-centos newdir2]$ pwd
/home/FirstUser/newdir2

4.2 创建多层目录

[FirstUser@VM-12-12-centos newdir2]$ mkdir -p test1/test2/test3/test4

进入test4目录

[FirstUser@VM-12-12-centos newdir2]$ cd test1/test2/test3/test4/

查看当前目录

[FirstUser@VM-12-12-centos test4]$ pwd
/home/FirstUser/newdir2/test1/test2/test3/test4

5.rmfir 指令

语法: rmdir [目录名称]

选项与参数:

  • -p :从该目录起,一次删除多级空目录

5.1 删除单层目录

返回上层目录

[FirstUser@VM-12-12-centos test4]$ cd ..

查看当前目录

[FirstUser@VM-12-12-centos test3]$ pwd
/home/FirstUser/newdir2/test1/test2/test3

删除test4目录

[FirstUser@VM-12-12-centos test3]$ rmdir test4/

查看当前目录

[FirstUser@VM-12-12-centos test3]$ pwd
/home/FirstUser/newdir2/test1/test2/test3

5.2  删除多层目录

连续三次返回上层目录,再查看当前目录

[FirstUser@VM-12-12-centos test3]$ cd ..
[FirstUser@VM-12-12-centos test2]$ cd ..
[FirstUser@VM-12-12-centos test1]$ cd ..
[FirstUser@VM-12-12-centos newdir2]$ pwd
/home/FirstUser/newdir2

删除test1、test2、test3目录

[FirstUser@VM-12-12-centos newdir2]$ rmdir -p test1/test2/test3/

查看当前目录

[FirstUser@VM-12-12-centos newdir2]$ pwd
/home/FirstUser/newdir2

再次进入test1目录时,test1目录已经不存在

[FirstUser@VM-12-12-centos newdir2]$ cd tes1/
-bash: cd: tes1/: No such file or directory

注意:rmdir 指令只能删除空目录

6.touch 指令

语法:touch [文件名]

创建一个文本文件

[FirstUser@VM-12-12-centos ~]$ touch test01.txt

创建两个文本文件

[FirstUser@VM-12-12-centos ~]$ touch test02.txt test03.txt

创建多个文本文件

[FirstUser@VM-12-12-centos ~]$ touch test{04..10}.txt

查看当前目录下的文件

[FirstUser@VM-12-12-centos ~]$ ls
test01.txt  test02.txt  test03.txt  test04.txt  test05.txt  test06.txt  test07.txt  test08.txt  test09.txt  test10.txt

7.rm 指令

语法: rm [文件或目录]

选项与参数:

  • -f :就是 force 的意思,忽略不存在的文件,不会出现警告信息;
  • -i :互动模式,在删除前会询问是否确定要删除文件
  • -r :递归删除。

7.1 删除一个文件

查看当前目录下的文件

[FirstUser@VM-12-12-centos ~]$ ls
test01.txt  test02.txt  test03.txt  test04.txt  test05.txt  test06.txt  test07.txt  test08.txt  test09.txt  test10.txt

删除test10.txt,再次查看当目录下的文件

[FirstUser@VM-12-12-centos ~]$ rm test10.txt

[FirstUser@VM-12-12-centos ~]$ ls
test01.txt  test02.txt  test03.txt  test04.txt  test05.txt  test06.txt  test07.txt  test08.txt  test09.txt
7.2批量删除文件,再次查看当目录下的文件
[FirstUser@VM-12-12-centos ~]$ rm test{01..09}.txt
[FirstUser@VM-12-12-centos ~]$ ls

8.nano 指令

8.1 创建一个test.c文件

[FirstUser@VM-12-12-centos ~]$ touch test.c

8.2 使用nano编辑代码

[FirstUser@VM-12-12-centos ~]$ nano test.c
#include <stdio.h>
int main()
{ 
 printf("Hello World\n");
 return 0;
}

8.3 按ctrl+x,输入Y(y),按回车建,完成编辑

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?                                                                                                                                                   
 Y Yes
 N No           ^C Cancel

8.4 使用gcc对test.c进行编译

[FirstUser@VM-12-12-centos ~]$ gcc test.c

8.5输出结果

[FirstUser@VM-12-12-centos ~]$ ./a.out
Hello World

9. man 指令

9.1 使用man man 查看man的使用方法

①输入man man指令

-bash-4.2$ man man

②看到如下信息

 ③上面图片中有9个指令手册

④按q键退出

⑤输入 man 3 printf 查看第3个手册的内容

(注意:若没有显示如下内容,则需要在root用户下输入 yum install -y man-pages 指令来安装手册)

⑥使用如下指令来翻页,这里不再演示

向后翻一屏:space(空格键)      向前翻一屏:b

向后翻一行:Enter(回车键)       向前翻一行:k

10. cat、cp 指令

cat(英文全拼:concatenate)命令用于连接文件并打印到标准输出设备上

cp(英文全拼:copy file)命令主要用于复制文件或目录

10.1 输出文件

①输入pwd查看当前目录

-bash-4.2$ pwd 
/home/FirstUser/Code

②输入ls查看当前目录下的文件

-bash-4.2$ ls
2022_05_20

③输入 touch 2022_05_27.txt 创建一个新文本文件,并查看当前目录

-bash-4.2$ touch 2022_05_27.txt 
-bash-4.2$ ls
2022_05_20  2022_05_27.txt

④输入 cat 2022_05_27.txt<

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值