1

I have a query on unix move for files not matching pattern. Example below:

Directory listing

 20150325
 20150326
 20150327
 20150328
 archieve

Now, I want to move all the files not matching 20150328 into archieve directory with a single command. Please help......

2
  • Assuming they're all in the same folder (you haven't said!) for x in 2015* ; do if [ ! "$x" = "20150328" ] ; then mv $x archieve; fi ; done Commented Mar 30, 2015 at 13:47
  • stackoverflow.com/questions/4612157/… Commented Mar 30, 2015 at 13:48

2 Answers 2

2

find with the -name parameter and the ! negation operator:

find . -type f ! -name 20150328 -exec mv {} archieve \;

The {} matches the file just found, and the escaped semi-colon terminates the exec'ed command. To exclude multiple files, just repeat the ! -name filename clause

Sign up to request clarification or add additional context in comments.

3 Comments

This one worked .. but with some warning message like below: mv: 0653-405 ./archieve/20150327 and archieve/20150327 are identical. for all the files
Also how about multiple files. I want to move all the files leaving files with 2 conditions... say .. as per above example I want to keep 20150328 and 20150327.
@Bhabani Shankar see my added sentence about multiple exclusions. I'm not sure why you're getting warnings about identical files., Are all your source files in one directory with unique names?
1

execute: shopt -s extglob after that do: mv !(20150328) "destination"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.