LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-15-2011, 05:25 PM   #1
frumpus
Member
 
Registered: Feb 2010
Posts: 38

Rep: Reputation: 0
hopefully simple 'cp' question


I want to copy all files with the extension .afm from:

/usr/local/texlive/2011/texmf-dist/fonts/afm

...into a single directory. The problem is that they are split into several levels of subdirectories under that directory. There are TONS of subdirectories and levels in that /afm directory and I don't want to have to drill down into each one to copy the files out. Surely there is a simple way to do this but I am not finding it.

I have tried:

cp *.afm /home/username/afm-files

but it doesn't find any afm files to copy as it only looks in the top level directory.

can anyone tell me what I'm missing here?
 
Old 08-15-2011, 05:33 PM   #2
frumpus
Member
 
Registered: Feb 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Oh I have also tried cp -r which I thought would check the subdirectories but no luck there either.

This is the error I get.

Code:
username@username [/usr/local/texlive/2011/texmf-dist/fonts/afm]
$ cp -r *.afm /home/username/afm-fonts
cp: cannot stat `*.afm': No such file or directory
 
Old 08-15-2011, 05:42 PM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
You can use the find command
Code:
find startdirectory -iname "filetype" -exec cp {} target_dir \;
Kind regards
 
1 members found this post helpful.
Old 08-15-2011, 05:44 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
This is a perfect case to use the find command:
Code:
find /usr/local/texlive/2011/texmf-dist/fonts/afm -name "*.afm" -exec cp '{}' /home/username/afm-files \;
This will search in the directory /usr/local/texlive/2011/texmf-dist/fonts/afm recursively for files that match the name *.afm and pass the filenames to the cp command, which will copy the files to /home/username/afm-files.
For more info have a look at
Code:
man find
 
1 members found this post helpful.
Old 08-15-2011, 05:49 PM   #5
frumpus
Member
 
Registered: Feb 2010
Posts: 38

Original Poster
Rep: Reputation: 0
I will give that a try, thanks!
 
Old 08-15-2011, 05:55 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
You have to escape the curly brackets, that can simply be done with single quotes '{}'. You also forget the ; at the end of the command, this has also to be escaped, you can do this with single quotes also ';', or you use the backslash \;.
For matching the filename you also need the wildcard *.
Code:
find /usr/local/texlive/2011/texmf-dist/fonts/afm -iname "*.afm" -exec cp '{}' /home/username/afm-fonts \;
 
1 members found this post helpful.
Old 08-15-2011, 06:00 PM   #7
frumpus
Member
 
Registered: Feb 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Thanks guys, 'find' was exactly what I needed!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple Question - needing a simple answer plz linuxnoob_sowhut Linux - Distributions 1 12-01-2010 04:54 AM
Two things: (Probably Simple) Grub question, and a gDesklets question Wilffo Linux - Software 3 05-20-2006 02:33 PM
Ubuntu Fluxbox simple question, simple answer? generallimptoes Linux - Software 3 09-26-2005 03:03 PM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 10:03 PM
simple question seeking simple answer enzo250gto Linux - Newbie 1 10-27-2001 05:08 AM


All times are GMT -5. The time now is 11:42 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration