FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 10-17-2008, 04:46 PM
Ed Jabbour
 
Default Copy by extension

I'm looking for an app that will descend into a directory and its subs, find
all files with a .foo extension and copy them to the bar directory. There are
a lot of files, so doing it manually would be tiresome. If cp has that
functionality, I can't find it. Thanks.

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-17-2008, 04:52 PM
Rashkae
 
Default Copy by extension

Ed Jabbour wrote:
> I'm looking for an app that will descend into a directory and its subs, find
> all files with a .foo extension and copy them to the bar directory. There are
> a lot of files, so doing it manually would be tiresome. If cp has that
> functionality, I can't find it. Thanks.
>

Use the find command..

You'll have to research the man page, but the gist of it is, you want
find files based on name '*.foo' or maybe .*foo as a regexp.

Then use find's { } construct to use cp command on the files it finds.

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-17-2008, 05:01 PM
"Jason Crain"
 
Default Copy by extension

On Fri, October 17, 2008 11:46 am, Ed Jabbour wrote:
> I'm looking for an app that will descend into a directory and its subs,
> find all files with a .foo extension and copy them to the bar directory.
> There are a lot of files, so doing it manually would be tiresome. If
> cp has that functionality, I can't find it. Thanks.

Something like this should work:

find /source/dir/ -iname '*.foo' -exec cp "{}" /dest/dir/ ;


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-17-2008, 05:13 PM
Nils Kassube
 
Default Copy by extension

Ed Jabbour wrote:
> I'm looking for an app that will descend into a directory and its subs,
> find all files with a .foo extension and copy them to the bar
> directory. There are a lot of files, so doing it manually would be
> tiresome. If cp has that functionality, I can't find it. Thanks.

Use this:

find -name *.foo -exec cp {} bar ;

However if you might have multiple files with the same name you will end
up with only one of them in the bar directory. You can check if you have
that problem with this command:

find -name *.foo -exec basename {} ; | sort | uniq -d


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-21-2008, 07:57 AM
Neil
 
Default Copy by extension

On Fri, Oct 17, 2008 at 7:13 PM, Nils Kassube <kassube@gmx.net> wrote:
> Ed Jabbour wrote:
>> I'm looking for an app that will descend into a directory and its subs,
>> find all files with a .foo extension and copy them to the bar
>> directory. There are a lot of files, so doing it manually would be
>> tiresome. If cp has that functionality, I can't find it. Thanks.
>
> Use this:
>
> find -name *.foo -exec cp {} bar ;
>
> However if you might have multiple files with the same name you will end
> up with only one of them in the bar directory. You can check if you have
> that problem with this command:
>
> find -name *.foo -exec basename {} ; | sort | uniq -d
>
>
> Nils
>
> --
> ubuntu-users mailing list
> ubuntu-users@lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>

hi

just curious: would cp -R *.foo /path/to/destination/ do the trick? Or
would it recreate the directory structure in the destination
directory?

Neil

--
There are three kinds of people: Those who can count, and those who cannot count
-----------------------------------------------------------------------
** Hi! I'm a signature virus! Copy me into your signature, please! **
-----------------------------------------------------------------------

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-21-2008, 09:42 AM
Tim
 
Default Copy by extension

On Tue, 2008-10-21 at 09:57 +0200, Neil wrote:
> hi
>
> just curious: would cp -R *.foo /path/to/destination/ do the trick? Or
> would it recreate the directory structure in the destination
> directory?

No. cp -R will copy files *.foo from the current directory, and will
recursively copy ALL files in directories matching *.foo in the current
directory. It won't search the directory structure to match *.foo.
The find command, as used in the examples Nils provided, does the job
of searching the directory hierarchy for matching files.

If you wanted to copy the directory structure, you would use find and cpio in tandem:
cd /base/source/dir
find . -name '*.foo' -print | cpio -pvdmu /base/dest/dir

The cpio options mean:
p = pass-through (copy between directories, and don't create an archive)
v = verbose
d = create directories as needed
m = preserve modification times of copied files
u = unconditional - it will over-write existing files in the destination

You could also add the l option, to link files rather than copy them, if
the source and destination are on the same filesystem. This will save
both time and disk space if there are a lot of files and they need a lot
of space.

One note: the examples from Nils will work for gnu find (which is used
for all Linux distributions), because that will use the current
directory as a default search base, but they won't work on Solaris or
BSD-based systems, or other Unix systems that don't have gnu find. My
example explicitly sets the search base to the current directory, from
lots of years exposure to systems that don't have gnu find



Tim



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-21-2008, 02:28 PM
Nils Kassube
 
Default Copy by extension

Neil wrote:
> > Ed Jabbour wrote:
> >> I'm looking for an app that will descend into a directory and its
> >> subs, find all files with a .foo extension and copy them to the bar
> >> directory. There are a lot of files, so doing it manually would be
> >> tiresome. If cp has that functionality, I can't find it. Thanks.
>
> just curious: would cp -R *.foo /path/to/destination/ do the trick? Or
> would it recreate the directory structure in the destination
> directory?

If you are curious how the cp command works, why don't you just try what
it does? The experiment will give you a much better knowledge than any
answer from the list.

mkdir -p ~/test/source ~/test/destination
cd ~/test/source
mkdir -p dir1 dir2.foo/dir3
touch file1 file2.foo dir1/file3.foo dir2.foo/dir3/file3
cp -R *.foo ~/test/destination
find ~/test -exec ls -Fd {} ; | sort

Now if you can't find out _why_ it works the way it does, please come back
and ask again.


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 11:00 PM.

VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org