LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   mv and regular expressions, mv file(_*).foo folder (https://www.linuxquestions.org/questions/linux-newbie-8/mv-and-regular-expressions-mv-file-_%2A-foo-folder-716131/)

jmcejuela 04-01-2009 02:14 PM

mv and regular expressions, mv file(_*).foo folder
 
How to do something like:

mv file(_*).foo folder

that is, move file.foo and, and optionally if existing, file_*.foo to folder

Does mv accept regular expressions like this? How is it done? It certainly accepts [] or other special characters, but not the brackets.


Thank you for your time

emetib 04-01-2009 02:20 PM

mv file*.foo folder

don't use the brackets
you can also use quotes if you have special characters

mv "file*.foo" folder

David1357 04-01-2009 04:20 PM

Quote:

Originally Posted by jmcejuela (Post 3495210)
It certainly accepts [] or other special characters, but not the brackets.

"mv" never sees the "[]" characters. They are expanded by the shell. Read up on "Pattern Matching" in the man page for bash.

Assuming you are using bash, you can get what you want using
Code:

[user@machine:~]:shopt -s extglob
[user@machine:~]:mv file?(_*).foo folder


synss 04-01-2009 04:35 PM

If you want to restrict to the filenames you mention, go with
Code:

mv file{,_*}.foo folder


All times are GMT -5. The time now is 06:36 PM.