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 07-12-2011, 07:07 PM   #1
nova49
Member
 
Registered: Nov 2010
Distribution: Slackware
Posts: 74

Rep: Reputation: 0
Regular Expressions


I've been doing a lot of work with zip files and I forget to extract them to a new directory. Basically I have a directory that is filled with files. I need to move all of them except for one using bash. I'm sure there is a way to negate one file being moved but I haven't found it yet. I though it might be with regular expressions but that seems to just be about character ranges.

Thanks in advance.
 
Old 07-12-2011, 07:58 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Have you considered moving everything and just putting
the one file back? :}


Code:
find -not -name <your-one-file> -exec mv {} /path/to/new/home \;

Cheers,
Tink
 
Old 07-12-2011, 08:04 PM   #3
nova49
Member
 
Registered: Nov 2010
Distribution: Slackware
Posts: 74

Original Poster
Rep: Reputation: 0
Thanks for that. I thought for sure that this was a regular expressions problem. One more question though. How come you use -exec ... I would think that this would be a good time for piping. Is there a physical limitation to using pipes here or is it just matter of preference.
 
Old 07-12-2011, 08:08 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Personal preference; it's slightly less typing.

Code:
find -not -name <your-one-file> | xargs -i mv {} /path/to/new/home
does the same thing, it's a tad longer.

Last edited by Tinkster; 07-12-2011 at 08:12 PM.
 
Old 07-13-2011, 07:05 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
You could also use bash extended globbing:

Code:
mv !(name-of-file-that-shouldnt-move) path/to/directory
Note that you need to enable extended globbing for this to work:

Code:
shopt -s extglob
 
  


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
\{a,b\} regular expressions sycamorex Linux - General 10 10-18-2008 06:38 PM
Regular Expressions ziggy25 Linux - Newbie 7 11-05-2007 06:57 AM
Regular Expressions markjuggles Programming 2 05-05-2005 11:39 AM
Regular expressions aromes Linux - General 1 10-15-2003 12:29 PM
regular expressions? alaios Linux - General 2 06-11-2003 03:51 PM


All times are GMT -5. The time now is 12:40 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