![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Rename to move files | snufse | UNIX for Dummies Questions & Answers | 1 | 04-09-2008 09:57 AM |
| how to move files | monicasgupta | Shell Programming and Scripting | 1 | 03-14-2008 01:53 PM |
| move files | uniksbro | UNIX for Advanced & Expert Users | 4 | 07-31-2007 08:42 AM |
| move files | ust | Shell Programming and Scripting | 5 | 07-03-2005 11:41 PM |
| move files | mta | UNIX for Dummies Questions & Answers | 2 | 01-16-2004 10:22 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to move all files except one?
Hello,
I have to move all files, except one, from one directory to another. I tried it with mv and find: mv -f $(find $SOURCE -maxdepth 1 ! -name "FileNotToMove") $TARGET It nearly worked out, but unfortunately not only the content of the $SOURCE directory got moved, but also the directory itself. I am just a beginner and don't have any ideas left how to do it in a proper way. Last edited by Kim Walisch; 01-21-2008 at 07:45 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
mv -f $(find $SOURCE -maxdepth 1 ! -name "FileNotToMove" -type f) $TARGET |
|
#3
|
|||
|
|||
|
Ok, so I cannot use this variation. Is there an other way to do it, without using for or while and comparing each filename?
|
|
#4
|
|||
|
|||
|
i think you could use :
find $SOURCE -type f ! -name "FileNotToMove" -exec mv {} $TARGET \; You will not have the ARG_MAX problem. Hope it helps Olivier |
|
#5
|
||||
|
||||
|
bash:
Code:
shopt -s extglob mv "$SOURCE"/!(FileNotToMove) "$TARGET" Code:
mv "$SOURCE"/!(FileNotToMove) "$TARGET" the same as bash, only change shopt ... to setopt kshglob |
||||
| Google The UNIX and Linux Forums |