简体   繁体   English

如何在Linux中扫描特定的存储库/文件夹并删除生成的所有其他内容

[英]How to scan a a specific repos/folders in linux and delete everything else that gets generated

In my software build process , I am generating specific files inside 2 specific folder. 在我的软件构建过程中,我正在2个特定的文件夹内生成特定的文件。 These two specific folders exist inside a repo (eg x/y/folder1 & x/y/folder2). 这两个特定的文件夹位于存储库中(例如x / y / folder1和x / y / folder2)。 Now after my build process is finished I see some files also generated inside 'x/y' folder (eg x/y/file1 & x/y/file2 &..). 现在,在完成构建过程之后,我看到在“ x / y”文件夹中也生成了一些文件(例如,x / y / file1和x / y / file2&..)。 These files are irrelevant. 这些文件无关。 How can I scan my folder after build process is finished and remove everything (all files eg x/y/file1 & x/y/file2 &..) except x/y/folder1 & x/y/folder2. 构建过程完成后,如何扫描我的文件夹并删除所有文件(所有文件,例如x / y / file1和x / y / file2&..),除了x / y / folder1和x / y / folder2。 I would like to include this check point in my build script itself (after build process is finished) to first scan for the relevant folder (eg x/y) and remove everything except x/y/folder1 & x/y/folder2 to give a cleaner result. 我想将此检查点包括在我的构建脚本本身中(在构建过程完成之后),以便首先扫描相关文件夹(例如x / y),并删除x / y / folder1和x / y / folder2以外的所有内容,以便更干净的结果。

I am using : Red Hat Enterprise Linux Server release 5.11 我正在使用:Red Hat Enterprise Linux Server版本5.11

find . 找 。 -type f ! 型f! -path "./folder1/ " ! -path“ ./folder1/ ”! -path "./folder2/ " | -path“ ./folder2/ ” | xargs rm -f xargs rm -f

or this id you would like to remove files and folders and just keep the ones you want 或此ID,您想删除文件和文件夹,只保留想要的文件和文件夹

find . 找 。 ! -path "./folder1/" ! -路径“ ./folder1/”! -path "./folder2/" -exec rm -rf {} \\; -path“ ./folder2/” -exec rm -rf {} \\;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM