LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2009, 02:14 PM   #1
jmcejuela
LQ Newbie
 
Registered: Apr 2009
Posts: 6

Rep: Reputation: 0
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
 
Old 04-01-2009, 02:20 PM   #2
emetib
Member
 
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
mv file*.foo folder

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

mv "file*.foo" folder
 
Old 04-01-2009, 04:20 PM   #3
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by jmcejuela View Post
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
 
Old 04-01-2009, 04:35 PM   #4
synss
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian, Gentoo, Mac OS X
Posts: 137

Rep: Reputation: 22
If you want to restrict to the filenames you mention, go with
Code:
mv file{,_*}.foo folder

Last edited by synss; 04-01-2009 at 04:39 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 04:23 AM
\{a,b\} regular expressions sycamorex Linux - General 10 10-18-2008 07:38 PM
Regular expressions aromes Linux - General 1 10-15-2003 01:29 PM
regular expressions? alaios Linux - General 2 06-11-2003 04:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration