Linux文件和目录管理

(1) 实验目的:

1. 熟悉 Linux 命令的一般格式;

2. 掌握 Linux 常用文件操作命令;

3. 掌握 Linux 常用目录操作命令;

4. 掌握 Linux 的其他方面的应用命令;

5. 理解 Linux 的工作原理及应用;

6. 熟悉 Linux 的字符界面的工作原理及操作方法。

(2) 实验内容:

1. 文件操作命令: touch cat more less head tail cp ln mv rm

2. 目录操作命令: cd pwd mkdir ls rmdir rm

3. 文件规档命令: tar

4. 在文件中查找指定字符串命令: grep

5. 切换用户命令: su ;查看当前用户命令: whoami

6. 清屏命令: clear ;信息回显命令: echo 帮助命令: man info

(3) 实验原理:

Linux 操作系统工作原理及 shell 工作原理

(4) 实验步骤:

1. 文件操作命令: touch cat more less head tail cp ln mv rm

1 touch 建立文件

[root@localhost ~]# touch haha

[root@localhost ~]# ll

2 cat 查看文档

[root@localhost ~]# cat jinjiawei01

Hello

3 more 分页查看

[root@localhost ~]# more haha

4 less 分页查看

[root@localhost ~]# less haha

5 head 查看文件头部

[root@localhost ~]# head haha

6 tail 查看文件尾部

[root@localhost ~]# tail haha

7 cp 复制文档

[root@localhost ~]# cp haha haha1

[root@localhost ~]# ll

8 ln****命令用于创建链接。在 Linux 中,链接分为硬链接和符号链接(也称为软链接

[root@localhost ~]# ln haha data // 硬链接

[root@localhost ~]# ln -s haha data1 // 软链接

9 mv 移动或重命名文件或目录

[root@localhost ~]# mv /root/haha /etc/

[root@localhost ~]# cd /etc/

[root@localhost etc]# ll

现在位置:

原来位置:

[root@localhost ~]# mv haha1 haha

[root@localhost ~]# ll

10 rm 删除文件或目录

删除文件

[root@localhost ~]# touch haha2

[root@localhost ~]# ll

[root@localhost ~]# rm -r haha2

rm :是否删除普通空文件 'haha2' y

删除目录

[root@localhost ~]# mkdir -p open1/loading/compation

[root@localhost ~]# ll

[root@localhost ~]# rm open1/

rm: 无法删除 'open1/': 是一个目录

[root@localhost ~]# rm -r open1/

rm :是否进入目录 'open1/'? y

rm :是否进入目录 'open1/loading'? y

rm :是否删除目录 'open1/loading/compation' y

rm :是否删除目录 'open1/loading' y

rm :是否删除目录 'open1/' y

或者

[root@localhost ~]# rm -rf open1/ // 强制删除,但在工作中最好不要用

2. 目录操作命令: cd pwd mkdir ls rmdir rm

1 cd 进入目录

[root@localhost ~]# cd /etc/pam.d/

[root@localhost pam.d]# cd ~

[root@localhost ~]#

2 pwd 查看当前路径的绝对路径

[root@localhost ~]# cd /dev/dri/

[root@localhost dri]# pwd

/dev/dri

3 mkdir 创建目录

[root@localhost ~]# mkdir -p open1/loading/compation

4 ls 查看目录下的文件

[root@localhost ~]# ls

5 rmdir 删除目录

[root@localhost ~]# mkdir -p open1/loading/compation

[root@localhost ~]# cd open1/

[root@localhost open1]# cd loading/

[root@localhost loading]# ll

总用量 0

drwxr-xr-x. 2 root root 6 4 24 23:32 compation

[root@localhost loading]# rmdir compation/

[root@localhost loading]# ll

总用量 0

[root@localhost loading]#

6)rm删除不需要的目录及文件

跟上面的 1 里里面的 10 )一样,在这里就不进行叙述了。

3. 文件规档命令: tar

1 tar 用于备份文件的工具 , 可以进行打包、解包、压缩、解压缩

打包文件:

[root@localhost ~]# touch file.txt

[root@localhost ~]# touch file1.txt

[root@localhost ~]# tar -cvf archive.tar file.txt file1.txt

file.txt

file1.txt

[root@localhost ~]# ll

打包目录:

[root@localhost ~]# tar -cvf dir1.tar open1/

open1/

open1/loading/

[root@localhost ~]# ll

打包并压缩文件(一般使用这个):

[root@localhost ~]# tar -czvf archive.tar.gz file.txt file1.txt

file.txt

file1.txt

[root@localhost ~]# ll

打包并压缩目录(一般使用这个):

[root@localhost ~]# tar -czvf dir1.tar.gz open1/

open1/

open1/loading/

[root@localhost ~]# ll

解包文件:

[root@localhost ~]# tar -xvf archive.tar -C open1/

file.txt

file1.txt

[root@localhost ~]# cd open1/

[root@localhost open1]# ll

总用量 0

-rw-r--r--. 1 root root 0 4 25 15:15 file1.txt

-rw-r--r--. 1 root root 0 4 25 15:14 file.txt

解压缩文件:

[root@localhost ~]# tar -xzvf archive.tar.gz -C open1/loading/

file.txt

file1.txt

[root@localhost ~]# ll open1/loading/

总用量 0

-rw-r--r--. 1 root root 0 4 25 15:15 file1.txt

-rw-r--r--. 1 root root 0 4 25 15:14 file.txt

向归档文件中添加文件:

[root@localhost ~]# touch file3.txt

[root@localhost ~]# tar -rvf archive.tar file3.txt

file3.txt

查看归档文件中的内容:

[root@localhost ~]# tar -tvf archive.tar

-rw-r--r-- root/root 0 2024-04-25 15:14 file.txt

-rw-r--r-- root/root 0 2024-04-25 15:15 file1.txt

-rw-r--r-- root/root 0 2024-04-25 15:37 file3.txt

4. 在文件中查找指定字符串命令: grep

grep搜索特定模式的文本,并将匹配的行打印出来

[root@localhost ~]# grep 'ho' haha

| Return True if the string is a valid Pyt ho n identifier, False otherwise.

| The string w ho se method is called is inserted in between each given string.

5. 切换用户命令: su ;查看当前用户命令: whoami

[root@localhost ~]# su fox

[fox@localhost root]$ whoami

fox

6. 清屏命令: clear ;信息回显命令: echo 帮助命令: man info

1 clear 清屏命令 (ctrl+l 也可以清屏 )

2 echo 信息回显命令

[root@localhost ~]# echo "hello world"

hello world

3 )帮助命令: man info ,还有一个 ---help

[root@localhost ~]# man grep

[root@localhost ~]# info grep

[root@localhost ~]# grep --help

相关推荐
石像鬼₧魂石5 小时前
内网渗透靶场实操清单(基于 Vulhub+Metasploitable 2)
linux·windows·学习·ubuntu
Danileaf_Guo5 小时前
256台H100服务器算力中心的带外管理网络建设方案
运维·服务器
橘子真甜~6 小时前
C/C++ Linux网络编程15 - 网络层IP协议
linux·网络·c++·网络协议·tcp/ip·计算机网络·网络层
拾贰_C7 小时前
【Linux | Windows | Terminal Command】 Linux---grep | Windows--- findstr
linux·运维·服务器
阿华hhh8 小时前
Linux系统编程(标准io)
linux·开发语言·c++
虹科网络安全8 小时前
艾体宝洞察 | 利用“隐形字符”的钓鱼邮件:传统防御为何失效,AI安全意识培训如何补上最后一道防线
运维·网络·安全
石像鬼₧魂石8 小时前
Kali Linux 网络端口深度扫描
linux·运维·网络
alengan8 小时前
linux上面写python3日志服务器
linux·运维·服务器
yBmZlQzJ9 小时前
免费内网穿透-端口转发配置介绍
运维·经验分享·docker·容器·1024程序员节
JH30739 小时前
docker 新手入门:10分钟搞定基础使用
运维·docker·容器