|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
mv --no-clobber option
Hi,
I'm writing a script in which I need to move files from one directory to another. However, some of the files have the same name, and I want to keep the older file, so I can't use --update. I'm moving files from the newer directory to the older directory, so what I'm looking for is a way to automatically not overwrite. Basically, I need the behavior of mv with the opposite of --force option. I can't use the --interactive option either, because I'm copying multiple files and I don't want mv to hang. There's no reason I must use mv, I just assumed it'd be the easiest way to accomplish what I need. If there's an easier way that doesn't involve mv I'm open for suggestions. After searching around a while I found this recent webpage which makes it seem as though mv will now have a --no-clobber option which will do exactly what I need. I'm running Ubuntu on this computer, so I'm sure the webpage is relevant, but mv doesn't like --no-clobber despite the fact that my system is updated. So basically what I need is explained in the first paragraph. I want a script to move files from one directory to another and automatically NOT overwrite: the oppsite of --force. Thanks in advance for any help or suggestions! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks, but it didn't work...
Thanks for the help, but I couldn't get it to work. I'm assuming your script is meant to be run from the "from" directory and that /path/to/destination/directory is meant to be replaced by the path to the "to" directory. Unfortunately, when I run the script, not only are the files in the destination directory overwritten by the files from the origin directory, but the copies in the origin directory are also deleted. That's more or less the exact opposite of the desired behavior. I need the copies in the destination directory to never be overwritten. I also would like to leave the duplicate copies in the original directory. Below is an example of the desired behavior: Code:
$ ls -a ~/from file1.ext file2.ext $ cat ~/from/file1.ext original file $ ls -a ~/to file1.ext $ cat ~/to/file1.ext destination file $ ~/magical_script.sh $ ls -a ~/from file1.ext $ cat ~/from/file1.ext original file $ ls -a ~/to file1.ext file2.ext $ cat ~/to/file1.ext destination file I hope that clarifies the desired behavior. As you can see, duplicates are left alone; only files that are not in the destination directory are copied. It doesn't look to me like what you posted should accomplish that considering you're using mv with a --force option. |
|
#4
|
||||
|
||||
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks! It worked.
Thank you. That did exactly what I needed.
|
| Sponsored Links | ||
|
![]() |
| Tags |
| move, no-clobber |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| g++ and the -R option | eternalflame | Programming | 0 | 04-14-2008 01:57 PM |
| option followed by : taking next option if argument missing with getopts | gurukottur | Shell Programming and Scripting | 2 | 03-17-2008 12:46 PM |
| -n option | ravi raj kumar | Shell Programming and Scripting | 1 | 01-03-2008 08:20 AM |
| cc option | kuldeep_bora | Programming | 4 | 06-02-2006 09:38 AM |
| cut -f option | 435 Gavea | UNIX for Dummies Questions & Answers | 1 | 11-10-2003 04:50 PM |
|
|