Script file to copy files

Dear all,
I have an external hard disk with lots of big files and a lot of small matlab script files .m.

I would like to grab all the files inside that harddisk that have the .m extension or the *.mat file extension (both are matlab files).

Of course this is a
-first-find the *.m files script and
-then copy the files into the hard disk.

What I do not know is how I can also keep the structure of the folders containing the *.m and *.mat files when I will copy them in my local hard disk.

As this external hard disk contains 2TB of data it is not possible to copy all the files first and then remove the unnecessary.
So I have to find and copy only the files I need but with also keeping the tree structure that the external hard disk has .

Can you help me find out an easy way to do that?


Of course it should have been iin Programming/Scripting. But I am not moving it because of the wrath of the NTTP users.

This should get you started, I added echos so you can see what the script will be doing. Once you are happy with the script remove the echos

cd /your/external/drive
for FILE in $(find . -type f | grep -e ".m$\|.mat$")
   THISDIR=`dirname ${FILE} | sed s/"^."//`
   echo "mkdir -p /local/drive${THISDIR}"
   echo "cp ${FILE} /local/drive${THISDIR}"

Good luck,

I am sorry for that :frowning:
what are the nttp users?

Never mind, I shouldn’t have posted that here. My fault. The only thing is that you are requested to post things about programming/scripting in the correct sub-forum next time. The people who love solving problems like yours are lurking there!

On 04/06/2011 05:06 PM, hcvv wrote:
>> what are the nttp users?
> Never mind

ok, i will answer him:

nntp users are those of a naturally superior intellect, extremely good
looking, friendly demeanor and impeccable manner…like myself :wink:

ok here is the truth: nntp is just a different method of accessing these
forums…it is a much older method and unlike the web experience (with
colors, and blinkies, and colored text etc etc) it is pretty
plain…just plain text mostly…like non-html email…

some people find nntp a quicker way to ask or answer/help, others find
it not only dull but far slower to use…

it is all in what you are used to…

unfortunately, some folks wanna generalize all nntp (or http) users to
be cut from the same cloth…which ain’t the case because i heard
someone say that they met an ugly nntp user—but, i don’t believe it!!


by the way Alex, hcvv wasn’t ‘mad’ at you, he was just giving me a hard
time…in jest…and you misunderstood…

CAVEAT: [NNTP via openSUSE 11.3 + KDE4.5.5 +
Thunderbird3.1.8] Can you believe it? This guy Ralph wins $181 million
in the lottery last Wednesday, and then finds the love of his life just
2 days later. Talk about LUCK!

I know that he was not mad with me :slight_smile: