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命令。 但是,如果没有选项-Rf rm命令是不够的。 这将强制以递归方式删除给定目录。 在此示例中,我们将删除名为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

删除/删除目录之前进行确认(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中的每个目录和文件,将要求使用删除目录FILEDIRECTORY NAME 为了批准,我们可以输入yyes来拒绝我们可以使用仅是enternno空答案。

$ rm -r -i poftut1

一次删除/删除多个目录(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/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()函数。

使用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.

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

相关文章
|
1月前
|
大数据 Linux 程序员
软件开发常见流程之服务器+Linux部署项目,会用服务器+Linux部署项目资料
软件开发常见流程之服务器+Linux部署项目,会用服务器+Linux部署项目资料
|
2月前
|
网络协议 安全 Linux
心得经验总结:搭建UEFIPXE基于linux相关资料
心得经验总结:搭建UEFIPXE基于linux相关资料
18 0
|
11月前
|
存储 网络协议 Ubuntu
Linux环境下使用SVN快速访问资料库?试试使用cpolar端口映射
SVN分为服务端和客户端,服务端主要是做数据资料存储,客户端主要是图形化工具连接服务端获取服务端数据资料,下面介绍在ubuntu系统安装服务端,在通过客户端远程访问。
115 0
Linux环境下使用SVN快速访问资料库?试试使用cpolar端口映射
|
Java 应用服务中间件 Linux
Linux复习资料——一篇文章学会安装Java(免环境配置)以及tomcat服务
Linux复习资料——一篇文章学会安装Java(免环境配置)以及tomcat服务
115 0
Linux复习资料——一篇文章学会安装Java(免环境配置)以及tomcat服务
|
Shell Linux
Linux复习资料——一篇文章学会sh脚本的编写(3)
Linux复习资料——一篇文章学会sh脚本的编写
86 0
Linux复习资料——一篇文章学会sh脚本的编写(3)
|
Shell Linux 开发工具
Linux复习资料——一篇文章学会sh脚本的编写(2)
Linux复习资料——一篇文章学会sh脚本的编写
113 0
Linux复习资料——一篇文章学会sh脚本的编写(2)
|
Shell Linux
Linux复习资料——一篇文章学会sh脚本的编写(1)
Linux复习资料——一篇文章学会sh脚本的编写
159 0
Linux复习资料——一篇文章学会sh脚本的编写(1)
|
关系型数据库 MySQL Linux
Linux复习资料——CentOS7下安装MySQL5.7.22(完整版本)
Linux复习资料——CentOS7下安装MySQL5.7.22(完整版本)
116 0
Linux复习资料——CentOS7下安装MySQL5.7.22(完整版本)
|
存储 Shell Linux
Linux复习资料(四)、Shell命令
Linux复习资料()、Shell命令
77 0
Linux复习资料(四)、Shell命令
|
Linux 网络安全 开发工具
Linux复习资料(三)、Linux基本操作
Linux复习资料(二)、Linux基本操作
110 0
Linux复习资料(三)、Linux基本操作