I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.[wW][mM][vV]).
I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.[wW][mM][vV])
Use "find":
Note that you have to change into the directory first, because "find" will find ./file, which can used in the cp-command directly, while with an absolute path you'd get the absolute path /path/to/sourcedir/file which you'd need to modify first.
Your solutions are correct as per the requirement i mentioned in my post. My bad, I missed to mention that the directory has sub-directories (and further sub-directories) too which have *.wmv files. The solution you offered working only for non-recursive directories. I tried cp -r with find but it copies all wmv as its parent directory doesn't wmv.
Please suggest a solution for the scenario where I have *.wmv files in sub-directories (any depth) too. Thanks a lot.
Unless there is something else you haven't told us, bakunin's script does exactly what you have requested: find all files in or under a source directory with names not ending in *.wmv or *.WMV and copy them into a single destination directory. (I would have used + instead of \; to terminate the -exec to make it run much faster when copying thousands of files, but that only affects speed; not which files will be copied.)
Oops, I take it back, he missed a key point. His script copied directories as well as regular files. And, you can't use -exec ... + when {} is not the last argument. Try:
Last edited by Don Cragun; 07-27-2014 at 08:25 PM..
Reason: Missed that bakunin's script was copying subdirectories... and + won't work in this case.
You should also have a look at some of the options available to the cp command in the manual.
You will need to make some decisions on what you want to do with any file links, file/directory permissions/ACLs, date/time stamps owners and groups for directories and files in the tree.
gnutar has quite a sensible set of defaults for all this stuff and the following has a good chance of doing what you want:
This User Gave Thanks to Chubler_XL For This Post:
Oops, I take it back, he missed a key point. His script copied directories as well as regular files.
True - my bad. My only excuse is one shouldn't answer threads before the second coffee.
This will probably not work either, because now the directory hierarchy will not become copied and some files (the one in sub-subdirectories) will have no proper targets. I suggest to do it in a two-pass way:
The first pass creates a copy of the directory structure, the second copies all the files. If you need to copy filemodes, ownerships, etc. too, you need to modify the "cp"-command accordingly: "cp -p ...".
@Chubler_XL: using "tar" for that was my first impulse, but it would limit the solution to a system where the GNU-tar is available.
Is it possible to only copy selected files+its directories when you are copying recursively?
find /OriginalFolder/* -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \; -print
From the above line, I want to only copy *txt and *ini files from /OriginalFolder/*
... (4 Replies)
he following are the files available in my directory
RSK_123_20141113_031500.txt
RSK_123_20141113_081500.txt
RSK_126_20141113_041500.txt
RSK_126_20141113_081800.txt
RSK_128_20141113_091600.txt
Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
How to copy files from one directory to another directory with the subfolders copied.
If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*.
I do not want to create sub folders in folder2.
Can copy command create them automatically?
I tried cp -a and cp -R but did... (4 Replies)
I have directory that has some billion file inside , i tried copy some files for specific date but it's always did not respond for long time and did not give any result.. i tried everything with find command and also with xargs..
even this command find . -mtime -2 -print | xargs ls -d did not... (2 Replies)
Hi all:
Here's my dilemma: to identify files of a specific type, copy them to a new location while preserving the original file attributes (date, time, full path, etc), and at the same time capture the count of the number of files identified as a variable for later reporting.
Here's where I... (9 Replies)
I hope this isn't as silly as it sounds from the title of the thread.
I have software that outputs files where the name starts with a real number followed by underscore as a prefix to an input file name. These will list in the directory with the file with the smallest real number prefix as the... (5 Replies)
Hello,
I have several files in a specific directory.
A specific string in one file can occur in another files.
If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string.
Example.
file1
ShortName "Blue... (2 Replies)
Hi
I am a shell-script newbie and am looking to synchronize certain files in two directory structures.
Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over.
I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)