[Techtalk] copying similar files in one command

gebhard dettmar gebhard.dettmar at student.hu-berlin.de
Mon Nov 1 04:13:59 EST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sunday 31 October 2004 17:12, Finne Boonen wrote:
> On Sun, 31 Oct 2004 16:55:35 +0100, Magni Onsoien
>
> <magnio+lc-techtalk at pvv.ntnu.no> wrote:
> > On 2004-10-31 05:21:38 -0600, percila orphan said:
> > > I need help with the cp command.
> > > Sometimes I'm have to copy a lot of files that
> > > have something in thier names in common.
> > > For example, if they all have the word "ed" in them.
> > > /home/ed/ ls -l | grep "ed"  displays all the files with the word
> > > "ed" in them within that directory /home/ed/
> > > I want to copy those files to the directory  /usr/temp
> > > Can I copy them all with one command? What might
> > > that be?
> >
> > You may use wildchars and let your shell take care of finding the
> > files for you (this is called file expansion):
> >
> > cp *ed* /home/newdir
> >
> > will copy all files with *ed* in them; if you also want the
> > directories copied, you'll have to use 'cp -r' in stead. And you can
> > also use this for other commands, like mv (move) or scp (remote copy
> > via ssh).
>
> you can get better results with more specification, eg
>
> copy all files ending with ed
> cp *ed /home/newdir
>
> copy all files beginning with ed
> cp ed* /home/newdir
>
> copy all files ending with ed and beginning with be
> cp be*ed /home/newdir
>
>
> Basically * stands for whatever charachter and multiple ones at that
> If there's only one character difference you could try something like
>
> copy ed1 eda ed4 edt edT ....
> cp ed? /home/newdir
>
> ? stands for exactly one character never mind wich one
>
> If you need more information, you can lookup regular expressions, wich
> is what makes the command line so powerfull from time to time.
> With regular expression you can specify what kinds of characters
> should be in there and how many, and even wich characters should not
> be in there and so on and so on.
And so on ;-) Exactly. RegExes are pure magic and if you often deal with 
editing text files it is highly recommendable to spent some time and 
effort in them. It can save you from work that would drive you nuts 
without using them. I got me the book: Jeffrey Friedl, Mastering Regular 
Expressionsm, 1997 O'Reilly. Better to read than the man page :-)
> Finne
regards
gebhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBhR1X9EYTTD7FjIERAmoYAJ0boidmkmGcqM1vmNj/813GqcOrhACdGuBH
8CRqCdLAzIRJro33/CdV4KI=
=GGkv
-----END PGP SIGNATURE-----


More information about the Techtalk mailing list