LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-06-2011, 07:18 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
copy files from hard disk


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?

Regards
Alex
 
Old 04-06-2011, 07:43 AM   #2
biggerbug
LQ Newbie
 
Registered: May 2007
Posts: 8

Rep: Reputation: 2
try this:

find -name *.m > flst
find -name *.mat >> flst
rsync -av --files-from=flst . /destination/dir/
 
1 members found this post helpful.
Old 04-06-2011, 09:29 AM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by biggerbug View Post
try this:

find -name *.m > flst
find -name *.mat >> flst
rsync -av --files-from=flst . /destination/dir/
Good Idea

I tried first this one

rsync -av --files-from=~/Documents/Documents-rn/Measurement\ campaign/hias\ Code/allmfileslist.txt ~/Documents/Documents-rn/Measurement\ campaign/hias\ Code/

which returns the error below
rsync error: syntax or usage error (code 1) at options.c(1652) [client=3.0.7]


afterwards I removed the destination from the command just to see if rsync will complain

which returned

rsync: failed to open files-from file ~/Documents/Documents-rn/Measurement campaign/hias Code/allmfileslist.txt: No such file or directory
rsync error: syntax or usage error (code 1) at main.c(1437) [client=3.0.7]

but the file is there.
ls ~/Documents/Documents-rn/Measurement\ campaign/hias\ Code/allmfileslist.txt
/home/apa/Documents/Documents-rn/Measurement campaign/hias Code/allmfileslist.txt


For me it seems that rsync can not read paths with spaces (even if there is an escape character at the beginning).

Regards
Alex

Last edited by alaios; 04-06-2011 at 09:30 AM.
 
Old 04-06-2011, 10:35 AM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by alaios View Post
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).
Change to the root of the tree you wish to copy. Then, duplicate the directory structure using
Code:
find . -depth -type d -exec mkdir -p -- '/where/to/copy/{}' ';'
Then copy the desired files using
Code:
find . -depth -name '*.m' -or -name '*.mat' -exec cp -vi -- '{}' '/where/to/copy/{}' ';'
If you want to remove any empty directories afterwards, run
Code:
find /where/to/copy/ -depth -type d -exec rmdir -- '{}' ';'
it'll complain about not being able to remove the directories with files, but that's okay; just ignore the warnings. It will only remove the empty directories.

The double dashes above tell the commands that even if the file or directory names begin with a dash, they're still names, not options.
 
Old 04-08-2011, 02:35 AM   #5
biggerbug
LQ Newbie
 
Registered: May 2007
Posts: 8

Rep: Reputation: 2
Quote:
Originally Posted by alaios View Post
rsync: failed to open files-from file ~/Documents/Documents-rn/Measurement campaign/hias Code/allmfileslist.txt: No such file or directory
rsync error: syntax or usage error (code 1) at main.c(1437) [client=3.0.7]

but the file is there.
ls ~/Documents/Documents-rn/Measurement\ campaign/hias\ Code/allmfileslist.txt
/home/apa/Documents/Documents-rn/Measurement campaign/hias Code/allmfileslist.txt


For me it seems that rsync can not read paths with spaces (even if there is an escape character at the beginning).
Oww spaces in file names... you should avoid that .
But maybe this works:

rsync -av --filter="+ */" --filter="+ *.m" --filter="+ *.mat" --filter="- *" --prune-empty-dirs 'your source dir/with space' destination/

You may also put \ behind spaces.

Cheers!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot copy files to VFAT32 usb hard disk casualzone Linux - Newbie 3 01-26-2010 03:52 AM
Copy of IBM Server hard disk data to Another USB External Hard disk mazharcdn Linux - Server 2 09-02-2009 12:41 AM
mounting linux files from another hard disk(IDE) to current hard disk(sata) the lord protector Linux - Hardware 5 05-04-2008 11:30 AM
How can I copy files from my linux machine to an external hard disk? hello321_1999 Linux - Newbie 3 05-08-2006 02:00 PM
Copy files from partition to partition too slow, SATA hard disk.What should I do£¿ Ryanlee SUSE / openSUSE 20 10-31-2005 07:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration