简体   繁体   中英

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. 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?

PS : I am trying to implement rollback mechanism in Jenkins. I will copy artifacts from old build and transfer them to server using ssh. But this will be a copy operation. So I want to delete previous files before starting copy using SSH.

您可以使用find

find ! \( -name 'name1' -o -name  'name2' \) -exec rm -r {} +

尝试使用此命令

rm !(<filename>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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