Abhishek dot py
Abhishek dot py

Reputation: 939

Move all files not starting from a specific letter

I am trying to move files from a folder to another location. I want to move all files except those which start with 'c'.

This is what I am trying

mv a* b* d*...............z*

Obviously this is a wrong way. Can anyone tell me the right way? I am using linux ( RHEL 6 )

Upvotes: 4

Views: 5036

Answers (2)

fedorqui
fedorqui

Reputation: 290305

Since [^c] means "everything that is not c", you can use the following expression:

mv [^c]* another_dir

What if I have to left two letters? mv [^c]* [^d]* another_dir?

In that case use the following:

mv [^cd]* another_dir

Tests

See the output of ls when using these regexs:

$ ls
a23  abc  b23  bd23  c23  cd23  d23
$ ls [^c]*
a23  abc  b23  bd23  d23
$ ls [^cd]*
a23  abc  b23  bd23

Upvotes: 15

Thomas Kühn
Thomas Kühn

Reputation: 9820

how about this:

mv [a-b,d-z]* destination

Upvotes: 2

Related Questions