LinuxQuestions.org
Help answer threads with 0 replies.
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 05-31-2007, 05:28 PM   #1
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 2,300

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
How do I write a script to copy all files beginning with A to a directory named 'a'.


The title says it all.
 
Old 05-31-2007, 05:59 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
mkdir a (if it does not already exist)
cp A* a

OR
cp -R A* a (to also copy all directories beginning with A)

Now my guess is that you wanted all the A* files on the whole system---so maybe:

cp `find / -name "A*"` a (those are backticks, not single quotes)
 
Old 06-01-2007, 10:24 AM   #3
linuxlastslonge
Member
 
Registered: Jun 2002
Location: Franklin, IN
Distribution: Debian, CentOS, Mac OS X
Posts: 158

Rep: Reputation: 30
alternately, you could do:


find . -iname "a*" -exec cp -v {} /some/other/dir \;


this will find, starting in the current directory and go through all subdirectories, files that start with "A" or "a". it will then take each file that it finds and copy it to /some/other/dir.


hope i could help!

cheers,

linuxlastslonger
 
  


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
need script to copy all files containing a certain string to a directory dc6463 Programming 21 04-18-2013 01:56 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 11:51 AM
how to write a script to move files from one directory to another myeire Linux - Newbie 7 02-25-2005 10:01 AM
how to write a script to create a directory mgam Linux - Newbie 1 10-29-2003 12:08 PM


All times are GMT -5. The time now is 05:47 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