Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Aug 2002 23:59:48 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Pascal Giannakakis <capm@gmx.net>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: smart file gobbling: exclude one file from list
Message-ID:  <20020802225948.GC54353@happy-idiot-talk.infracaninophi>
In-Reply-To: <001201c23a6e$17e78e60$0200a8c0@capm>
References:  <001201c23a6e$17e78e60$0200a8c0@capm>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Aug 02, 2002 at 11:46:43PM +0200, Pascal Giannakakis wrote:

> if i do "cp * /destination", all files in the current directory will be
> copied to /destination. What do i have to type, if i want to expand the '*'
> to all files, except of one? For example, if i wanted to exclude the file
> "notme" in the current directory?
> 
> I know i could hack it with grep, but this fails as all files are on one
> line. I wonder how you gurus would solve this! :)

i)

    mv notme /tmp
    cp * /destination
    mv /tmp/notme .

ii)

    for f in * ; do
        [ "$f" = "notme" ] || cp $f /destination
    done

iii)

    find . \! -name notme -maxdepth 1 -mindepth 1 -print0 | \
        xargs -0 -J % cp % /destination

iv)

    cp `ls -1d * | sed -e '/notme/d'` /destination

v)

    perl -MFile::Copy \
        -e 'for (@ARGV) { next if /notme/; copy $_, "/destination/$_"; }' *

vi)

    tar -cf - --exclude=notme . | ( cd /destination ; tar -xf - )

vii)

    zsh -c "setopt EXTENDED_GLOB ; cp (^(notme)) /destination"

zsh is in ports -- shells/zsh -- all the rest are commands from the
core system.

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
Tel: +44 1628 476614                                  Marlow
Fax: +44 0870 0522645                                 Bucks., SL7 1TH UK

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020802225948.GC54353>