LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-21-2007, 08:29 PM   #1
pccdrussell
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 62

Rep: Reputation: 15
Moving Files except a few


Hello, I am working on a way to try and figure out how to move files to another directory except a few. For example.....

Say I have a directory /home/testuser/stuff and...
1. I have lets say 50 files in that directory...
2. file1, file2, file3,....... file50
3 And I make a direcotry inside ~/stuff called oldstuff
4. Then I want to move all the files in there to oldstuff except files 1 and 2 with one command..

I realize I could move them all in there and then go into "oldstuff" and pull back out the ones I want to the original folder like (#mv file1 file2 ../), but what I am actually doing is working on a more involved than that example, (Just thought that example might help explain better) So I guess Im wondering if there is "except" sort of substitution for the mv command.

Any help would me much appreciated!
Thank You
 
Old 07-21-2007, 08:52 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Using find with ! seems to work ok.
For example:
Code:
find /home/Image -type f ! \( -name '*.txt' -o -name '*.doc' \) \
-exec mv {} /home/test \;
 
Old 07-21-2007, 09:15 PM   #3
pccdrussell
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 62

Original Poster
Rep: Reputation: 15
Hello, thanks for the reply. I guess Im still somewhat of a newb. I understand the majority of that command, but not all. However, how would that apply to my example? What if for example, all files in that directory where .txt, and I wanted to move all but file1.txt and file2.txt to the other folder with that command. Would I need a -not? Like for example,

#find /home/testuser/stuff -not \ ( -name "file1.txt" -o "file2.txt" \)-exec mv {} /home/testuser/stuff/oldstuff \;

Could you possibly explain what the ! does for you. Or does that example command seem close?
 
Old 07-21-2007, 09:46 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
The ! is like saying not
Spacing in the command is important, looks like you don't have a space after the last )
When posting code on the forum, it is easier for people to see how your code actually looks if you put it inside code or quote thingys.
The # thing up in the tool bar can be used for code.
 
Old 07-21-2007, 10:08 PM   #5
pccdrussell
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 62

Original Poster
Rep: Reputation: 15
Thanks alot Homey for all your replies. That was some good info, I will play around with it a bit and see what I come up with. Thanks also for the # tip. I just saw that in the toolbar as I am replying to this.
 
Old 07-21-2007, 10:33 PM   #6
pccdrussell
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 62

Original Poster
Rep: Reputation: 15
Well shoot, Ive been trying this for the last 15 minutes on a practice run. I made a fake scenario with a folder test and testorig and made a 5 files and tried to move 3 of them but not the first two..... heres, what Im trying...

Code:
find /home/user/Desktop/test/ -type f ! \( -name 'file1' -o -name 'file2' \) \ -exec mv {} /home/user/Desktop/test/testorig/ \;
I am getting this error.....

find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

Any ideas??
Thanks
 
Old 07-21-2007, 10:52 PM   #7
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Quote:
Originally Posted by pccdrussell
Code:
find /home/user/Desktop/test/ -type f ! \( -name 'file1' -o -name 'file2' \) \ -exec mv {} /home/user/Desktop/test/testorig/ \;
there's a stray backslash
 
Old 07-21-2007, 11:03 PM   #8
pccdrussell
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 62

Original Poster
Rep: Reputation: 15
Im not seeing the stray backslash, ive actually tried it every way taking one out at a time and get a syntax error near unexpected token error. Can you please point out where you think I have it wrong?
Thanks!!

EDIT Sorry, replied to soon. Its the backslash before the "-exec" I thought I tried getting rid of that, but guess not. Thanks to all for your replies, it works great!!

Last edited by pccdrussell; 07-21-2007 at 11:10 PM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help moving files. EYEdROP Linux - Newbie 26 03-07-2007 10:20 PM
moving files Baghdad Linux - Newbie 5 01-22-2006 01:39 AM
Moving files UmneyDurak Fedora 4 08-28-2005 05:52 PM
moving files pantera Programming 2 08-23-2005 05:58 AM
Moving Files jhotchkiss Linux - Newbie 5 09-16-2003 03:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:50 AM.

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
Open Source Consulting | Domain Registration