Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move all files not starting from a specific letter

Tags:

linux

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 )

like image 969
Abhishek dot py Avatar asked Dec 05 '22 09:12

Abhishek dot py


2 Answers

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
like image 152
fedorqui 'SO stop harming' Avatar answered Dec 17 '22 20:12

fedorqui 'SO stop harming'


how about this:

mv [a-b,d-z]* destination
like image 42
Thomas Kühn Avatar answered Dec 17 '22 20:12

Thomas Kühn