Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 3666  / 2 Years ago, thu, april 21, 2022, 7:37:16

I'm trying to move all files from one folder to another, except some specific folders.



I tried this to move all files except the .git, assets or build folders:



find .. ! -regex '(.git|assets|build)' | xargs mv -t ../build



What I except this command to do:




  • Find all files/folders in parent folder that are not .git, assets or build.

  • Move those files/folders to ../build



The folder structure is like this:



.
├── application
├── assets
├── build
├── download_files
├── images
├── mybb
├── system
└── tools


My working directory is the tools folder.



If I execute find .. ! -regex '(.git|assets|build)' it still shows .git, assets and build.



What's wrong with my command?


More From » bash

 Answers
3

You may have missed some wildcard characters, try



find .. ! -regex '(.*/.git.*|.*/assets.*|.*/build.*)'


I also included the path separator (/) so that assets or build appearing as part of a path doesn't match.


[#36349] Saturday, April 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jectedrin

Total Points: 491
Total Questions: 105
Total Answers: 111

Location: Netherlands
Member since Mon, Jun 7, 2021
3 Years ago
;