Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
Excellent! Thanks a lot! – EsTeGe Aug 6 '12 at 14:40

You can also use bash's extended globs to filter those dirs. First make sure extglob is enabled.

shopt -s extglob


mv ../!(assets|build) ../build

The glob won't match files starting with ., so no need to filter out .git. However, if you want to move other files starting with ., then also enable the dotglob shell option.

shopt -s extglob dotglob
mv ../!(.git|assets|build) ../build
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.