Linux入门删除目录

简介: Linux入门删除目录

Linux provides different commands in order to remove or delete directories and files. But in some cases, this may not work as expected and we can get a message like rmdir: 'dir' Directory no empty which simply means when we try to delete a directory with rmdir command it is not completed. In this tutorial, we will learn how to remove and delete an empty or full directory.

Linux提供了不同的命令以删除或删除目录和文件。 但是在某些情况下,这可能无法按预期工作,并且我们会收到类似rmdir: 'dir' Directory no empty的消息rmdir: 'dir' Directory no empty ,这仅意味着当我们尝试使用rmdir命令删除目录时,该目录尚未完成。 在本教程中,我们将学习如何删除和删除空目录或完整目录。

用rm -Rf命令删除 (Remove with rm -Rf Command)

The most used command to delete a directory with its content is rm command. But rm command is not enough without options -Rf. This will force the deletion of given directories in a recursive manner. In this example, we will delete the directory named backup

删除目录及其内容最常用的命令是rm命令。 但是,如果没有选项-Rfrm命令是不够的。 这将强制以递归方式删除给定目录。 在此示例中,我们将删除名为backup的目录

$ rm -Rf backup

使用详细信息删除 (Remove with Verbose Information)

Deleting directory with its children will not provide verbose information by default. But we can print detailed information about the operation with the verbose option -v like below.

默认情况下,删除带有子目录的目录不会提供详细信息。 但是,我们可以使用如下详细选项-v打印有关该操作的详细信息。

$ rm -Rf -v backup

Remove with Verbose Information使用详细信息删除

删除/删除目录之前进行确认(Confirm Before Removin/Deleting Directory)

If we will delete directories those contain some sensitive ones we may need to confirm before deleting them. We can use -i option which will ask for a removal for confirmation. In this example, we will delete the directory named poftut1 which is not empty. For each directory and files inside poftut1 the remove directory FILE or DIRECTORY NAME will be asked to use. In order to approve, we can enter y or yes to deny we can use empty answer which is just enter or n or no.

如果我们要删除包含敏感目录的目录,则在删除目录之前可能需要确认。 我们可以使用-i选项,该选项将要求删除以进行确认。 在此示例中,我们将删除名为poftut1的目录,该目录不为空。 对于poftut1中的每个目录和文件,将要求使用删除目录FILE或DIRECTORY NAME。 为了批准,我们可以输入yyes来拒绝我们可以使用仅是enter或nno空答案。

$ rm -r -i poftut1

Confirm Before Deleting Directory删除目录前先确认

一次删除/删除多个目录(Remove/Delete Multiple Directories At Once)

We may want to remove multiple directories with a single rm command. We do not have to run rm command multiple times for different directory names. We can provide all directories we want to remove in a single rm command. We can also provide the path of the directory like /mnt/test etc.

我们可能想用一个rm命令删除多个目录。 对于不同的目录名,我们不必多次运行rm命令。 我们可以在一个rm命令中提供要删除的所有目录。 我们还可以提供目录的路径,例如/mnt/test等。

$ rm -rf -v Templates poftut1/Case poftut1/Database /home/ismail/SocialFish/

Remove Multiple Directories At Once一次删除多个目录

根特权删除/删除(Remove/Delete with Root Privileges)

In order to delete a file or directory, we need privileges. If the directory is owned by the root user and we are not we can not delete the directory. So we need to get root privileges with sudo command like below.

为了删除文件或目录,我们需要特权。 如果目录由root用户拥有,而我们不是,则无法删除目录。 因此,我们需要使用sudo命令获得root特权,如下所示。

$ sudo rm -Rf backup

用Python删除 (Remove with Python)

We can also use some python script or commands in order to delete a directory please look following example where we will use os module remove() function.

我们也可以使用一些python脚本或命令来删除目录,请看下面的示例,我们将使用os模块remove()函数。

LEARN MORE  How To Remove Files Older Than 1 Day/1 Week/1 Month Recursively

了解更多信息如何以递归方式删除早于1天/ 1周/ 1个月的文件

How To Delete and Remove File and Directory with Python?

如何使用Python删除和删除文件和目录?

import os 
os.remove("/home/ismail/trash")

使用find命令删除/删除目录 (Remove/Delete Directory with find Command)

find command is a command used to search and find different types of files and directories the specified path. Find command provides different useful features like regular expression search, extension search or file attribute search, etc. We can also use the find command in order to delete or remove specified directories. We will use the -exec feature of the find command which will run given command for the matched files and folders. We will match the directory type with the -type d option and provide the name or name pattern with the -name '*cache' .

find命令是用于搜索和查找指定路径的不同类型文件和目录的命令。 Find命令提供了各种有用的功能,例如正则表达式搜索,扩展名搜索或文件属性搜索等。我们还可以使用find命令来删除或删除指定的目录。 我们将使用find命令的-exec功能,该功能将为匹配的文件和文件夹运行给定命令。 我们将使用-type d选项匹配目录类型,并使用-name '*cache'提供名称或名称模式。

$ find /var -type d -name '*cache*' -exec rm -r {} +

We can also use the -delete option of the find command which will automatically delete matched files and folders. In the following example we will directly delete the

我们还可以使用find命令的-delete选项,它将自动删除匹配的文件和文件夹。 在以下示例中,我们将直接删除

$ find /home/ismail -type d -delete

使用文件管理器删除/删除目录 (Remove/Delete Directory with File Manager )

Linux and Linux Desktop Enviroments provides different file managers which is used for different operations like add, remove, change files and directories. We can also use file manager in order to remove or delete directory. We will just right-click t the folder or directory we want to delete and find the item like Move to Trash , Delete , Remove , Send to Trash etc. and click.

Linux和Linux桌面环境提供了不同的文件管理器,用于不同的操作,例如添加,删除,更改文件和目录。 我们还可以使用文件管理器来删除或删除目录。 我们将在要删除的文件夹或目录上单击鼠标右键,然后找到“ Move to Trash ,“ Delete ,“ Remove ,“ Send to Trash等项目,然后单击。

目录
相关文章
|
1月前
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
201 73
|
16天前
|
机器学习/深度学习 Linux 编译器
Linux入门3——vim的简单使用
Linux入门3——vim的简单使用
43 1
|
16天前
|
Linux Shell Windows
Linux入门1——初识Linux指令
Linux入门1——初识Linux指令
23 0
Linux入门1——初识Linux指令
|
4月前
|
存储 Linux Android开发
Volatility3内存取证工具安装及入门在Linux下的安装教程
Volatility 是一个完全开源的工具,用于从内存 (RAM) 样本中提取数字工件。支持Windows,Linux,MaC,Android等多类型操作系统系统的内存取证。针对竞赛这块(CTF、技能大赛等)基本上都是用在Misc方向的取证题上面,很多没有听说过或者不会用这款工具的同学在打比赛的时候就很难受。以前很多赛项都是使用vol2.6都可以完成,但是由于操作系统更新,部分系统2.6已经不支持了,如:Win10 等镜像,而Volatility3是支持这些新版本操作系统的。
|
13天前
|
存储 数据可视化 Linux
Linux 基础入门
Linux 基础入门
|
16天前
|
Linux Go 数据安全/隐私保护
Linux入门2——初识Linux权限
Linux入门2——初识Linux权限
23 0
|
2月前
|
Java Shell Linux
【Linux入门技巧】新员工必看:用Shell脚本轻松解析应用服务日志
关于如何使用Shell脚本来解析Linux系统中的应用服务日志,提供了脚本实现的详细步骤和技巧,以及一些Shell编程的技能扩展。
47 0
【Linux入门技巧】新员工必看:用Shell脚本轻松解析应用服务日志
|
2月前
|
存储 Ubuntu Linux
Linux基础入门
Linux基础入门
27 1
|
2月前
|
Ubuntu Linux Shell
Linux 终端入门
Linux 终端入门
25 0
|
2月前
|
安全 网络协议 Linux
保护你的 Linux VPS:入门指南
保护你的 Linux VPS:入门指南
26 0