简体   繁体   English

如何在Linux中使用rm命令删除除一组目录之外的所有文件?

[英]How to delete all files apart from a set of directories using rm command inlinux?

I want to delete all the files in a folder apart from my LOG directory and my reports directory. 我想删除除我的LOG目录和报告目录之外的文件夹中的所有文件。 Is there a way to do that in Linux terminal using rm command ? 有没有一种方法可以在Linux终端中使用rm命令执行此操作?

I want to delete all the files in a folder apart from my LOG directory and my reports directory. 我想删除除我的LOG目录和报告目录之外的文件夹中的所有文件。

rm -rf !(LOG|reports)

Make sure that you have extglob option enabled: 确保已启用extglob选项:

shopt -s extglob
$rm -rf [your directory path to delete]

此命令将删除所选目录以及其中的所有文件和文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用rm -rf从目录中删除文件? - How to delete files from directory using rm -rf? 如何使用单个命令删除linux中不同目录中的文件 - How to delete files in different directories in linux with a single command 从 Ansible Playbook 中删除服务器所有目录中的特定文件夹/文件 - Delete specific folder/files in all the directories of the server from the Ansible Playbook 删除所有文件和目录-除非指定 - Delete all files and directories - except specified 我想删除linux中的所有文件和目录 - I wanna to delete all files and directories in linux 如何“在多个目录(文本文件)中查找所有xml文件并删除” - How to "find all xml files in multiple directories (textfile) and delete" Linux:如何删除目录本身(不是子目录)内的所有文件(不是目录) - Linux: How to delete all of the files (not directories) inside a directory itself (not childs) 如何使用 find 命令和 wc 命令查找目录和所有子目录中所有 .txt 文件的数量? - How do I find the number of all .txt files in a directory and all sub directories using specifically the find command and the wc command? 如何从目录中删除名称奇怪的文件? - How can I delete files with odd names from directories? 删除除两个特定目录之外的所有文件/目录 - Delete all files/directories except two specific directories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM