Linux文件和目录管理

embedded/2024/10/18 12:25:43/

(1)实验目的:

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

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

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

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

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

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

(2)实验内容:

1.文件操作命令:touchcatmorelessheadtailcplnmvrm

2.目录操作命令:cdpwdmkdirlsrmdirrm

3.文件规档命令:tar

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

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

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

(3)实验原理:

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

(4)实验步骤:

1.文件操作命令:touchcatmorelessheadtailcplnmvrm

1touch建立文件

[root@localhost ~]# touch haha

[root@localhost ~]# ll

2cat查看文档

[root@localhost ~]# cat jinjiawei01

Hello

3more分页查看

[root@localhost ~]# more haha

4less分页查看

[root@localhost ~]# less haha

5head查看文件头部

[root@localhost ~]# head haha

6tail查看文件尾部

[root@localhost ~]# tail haha

7cp复制文档

[root@localhost ~]# cp haha haha1

[root@localhost ~]# ll

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

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

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

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

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

[root@localhost ~]# cd /etc/

[root@localhost etc]# ll

现在位置:

原来位置:

[root@localhost ~]# mv haha1 haha

[root@localhost ~]# ll

10rm删除文件或目录

删除文件

[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.目录操作命令:cdpwdmkdirlsrmdirrm

1cd进入目录

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

[root@localhost pam.d]# cd ~

[root@localhost ~]#

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

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

[root@localhost dri]# pwd

/dev/dri

3mkdir创建目录

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

4ls 查看目录下的文件

[root@localhost ~]# ls

5rmdir删除目录

[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

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

打包文件:

[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 Python identifier, False otherwise.

 |      The string whose 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帮助命令:maninfo

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

2echo信息回显命令

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

hello world

3)帮助命令:maninfo,还有一个—help

[root@localhost ~]# man grep

[root@localhost ~]# info grep

[root@localhost ~]# grep --help


http://www.ppmy.cn/embedded/16608.html

相关文章

NLP Step by Step -- How to use pipeline

正如我们在摸鱼有一手:NLP step by step -- 了解Transformer中看到的那样,Transformers模型通常非常大。对于数以百万计到数千万计数十亿的参数,训练和部署这些模型是一项复杂的任务。此外,由于几乎每天都在发布新模型&#xff0c…

Mysql面试题

今年环境越来越难了, 准备了一些面试题分享一下,持续更新中!着急的可看最后, 话不多说,五一消费节,先搞个3块钱,能省则省,再继续看文吧 1. 说说mysql的优点 数据存储:可…

【Github】sync fork后,意外关闭之前提交分支的pr申请 + 找回被关闭的pr请求分支中的文件

【Github】sync fork后,意外关闭之前提交分支的pr申请 找回被关闭的pr请求分支中的文件 写在最前面原因解析提交pr,pr是什么?rebase 或者 merge 命令 找到分支中被删除的文件找到被关闭的提交请求pr方法1:在公共仓库被关闭的pr中…

Linux基础命令[24]-su

文章目录 1. su 命令说明2. su 命令语法3. su 命令示例3.1 不加参数3.2 -(登录)3.3 -c(执行命令) 4. 总结 1. su 命令说明 su:以用户身份执行命令,基本信息如下: Usage:su [options] [-] [USE…

学习STM32第十九天

PWR电源控制 一、电源系统 STM32F4xx电源供电结构框图如下 电压管理器(Voltage Regulator)共有三种模式 run mode 此模式下,电压管理去稳定向核心、内存和外设提供1.2V电压,输出电压可由软件变换。stop mode 此模式下&#xf…

Java冒泡排序

Java冒泡排序算法是一种简单的排序算法,它通过多次比较和交换相邻元素的方式将最大(或最小)的元素逐步移动到数组的末尾。以下是Java冒泡排序算法的实现步骤: 遍历数组,从第一个元素开始,依次比较相邻的两…

Node.js使用

Node.js是一个基于Chrome V8引擎的JavaScript运行环境,它使得JavaScript能够脱离浏览器,直接在服务器端运行。Node.js的异步I/O模型使其在处理高并发请求时表现出色,适用于构建网络应用、实时应用等。以下是对Node.js使用的总结: …

设计模式:合成复用原则(Composite Reuse Principle,CRP)介绍

合成复用原则(Composite Reuse Principle,CRP)是面向对象设计原则之一,它强调通过组合已有的对象来实现新的功能,而不是通过继承已有的类来实现。合成复用原则的核心思想是尽量使用对象组合而不是类继承,从…