[英]how to delete all files in directory except one folder and one file?
I have application which has one folder called vendor and one file called .env. 我有一个应用程序,该应用程序有一个名为vendor的文件夹和一个名为.env的文件。 When ever i automatically publish my source code files to folder, all old files should get deleted except these two.
每当我自动将源代码文件发布到文件夹时,除这两个文件外,所有旧文件都应删除。
How can i do this in linux by using shell? 我该如何在Linux中使用Shell?
PS : I am trying to implement rollback mechanism in Jenkins. PS:我正在尝试在Jenkins中实现回滚机制。 I will copy artifacts from old build and transfer them to server using ssh.
我将复制旧版本的工件,然后使用ssh将其传输到服务器。 But this will be a copy operation.
但这将是复制操作。 So I want to delete previous files before starting copy using SSH.
因此,我想在使用SSH开始复制之前删除以前的文件。
您可以使用find
:
find ! \( -name 'name1' -o -name 'name2' \) -exec rm -r {} +
尝试使用此命令
rm !(<filename>)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.