How to move (and overwrite) all files from one directory to another?
-
I know of the mv command to move a file from one place to another, but how do I move all files from one directory into another (that has a bunch of other files), overwriting if the file already exists?
-
Answer:
It's just mv srcdir/* targetdir/. If there are too many files in srcdir you might want to try something like the following approach: cd srcdir find -exec mv {} targetdir/ + In contrast to \; the final + collects arguments in an xargs like manner instead of executing mv once for every file.
Chris at Stack Overflow Visit the source
Other answers
In linux shell, many commands accept multiple parameters and therefore could be used with wild cards. So, for example if you want to move all files from folder A to folder B, you write: mv A/* B If you want to move all files with a certain "look" to it, you could do like this: mv A/*.txt B Which copies all files that are blablabla.txt to folder B Star (*) can substitute any number of characters or letters while ? can substitute one. For example if you have many files in the shape file_number.ext and you want to move only the ones that have two digit numbers, you could use a command like this: mv A/file_??.ext B Or more complicated examples: mv A/fi*_??.e* B For files that look like fi<-something->_<-two characters->.e<-something-> Unlike many commands in shell that require -R to (for example) copy or remove subfolders, mv does that itself. Remember that mv overwrites without asking (unless the files being overwritten are read only or you don't have permission) so make sure you don't lose anything in the process. For your future information, if you have subfolders that you want to copy, you could use the -R option, saying you want to do the command recursively. So it would look something like this: cp A/* B -R By the way, all I said works with rm (remove, delete) and cp (copy) too and beware, because once you delete, there is no turning back! Avoid commands like rm * -R unless you are sure what you are doing.
Shahbaz
Related Q & A:
- How do I loop through many files in one folder?Best solution by thespreadsheetguru.com
- How do I transfer my iTunes library from one computer to another?Best solution by Yahoo! Answers
- How to move completely move a folder to one place or another?Best solution by Stack Overflow
- How do I forward my Yahoo! messages from one account to another?Best solution by Yahoo! Answers
- How can I move bookmarks from one email to another one?Best solution by pcworld.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.