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 |
Using find with ! seems to work ok.
For example: Code:
find /home/Image -type f ! \( -name '*.txt' -o -name '*.doc' \) \ |
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? |
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. |
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.
|
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/ \; find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression] Any ideas?? Thanks |
Quote:
|
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!! |
All times are GMT -5. The time now is 09:43 PM. |