[thechat] unix command problem

Garrett Coakley garrett at polytechnic.co.uk
Mon Aug 12 06:11:14 CDT 2002


On Tue, 6 Aug 2002 17:54:35 -0400 "Anil Garg" <anilg at niksun.com> wrote:

> Hi,
>
> i get a list of files when i say
> ls *.php | grep doc
>
> now i want to remove all these files which i get (on doing ls *.php |
> grep doc) from command line and if possible then by using a single
> command.

'find' is probably an easier way of doing this:

find ./ -name *doc*.php -exec rm '{}' \;

Which basically translates to: find all files in the current directory
and below (the ./ bit) that have the php extension and contain 'doc' in
their file name. Take these files and remove them (the -exec rm '{}'
bit).

The '{}' gets replaced by each file name found by find and the \; just
tells it that this is the end of the command.

Remember to back up the files before you use this though *:)

G.


--
-----------------------------------------------------------------------
WORK: http://www.gencon.co.uk
PLAY: http://polytechnic.co.uk



More information about the thechat mailing list