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 )
Advertisement
Answer
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