Re: Delete files in directoy and sub-directories

From: Bela Lubkin (belal_at_sco.com)
Date: 11/27/03


Date: Thu, 27 Nov 2003 00:58:09 GMT
To: scomsc@xenitec.ca

Jean-Pierre Radley wrote:

> Jirtme VUIBERT typed (on Wed, Nov 26, 2003 at 06:06:12PM +0100):
> | Is there an easy line command to delete all file (let say the ones with the
> | .txt extension) present in a directory and its sub-directories without
> | deleting the directories.
>
> find /the/directory/you/want -type f ! -name "*.txt" | xargs rm

I believe JP misread the question. Jirtme asked to delete all
files "with the .txt extension" and I think JP understood that as
"with_out_ the .txt extension". The above command will delete all files
except *.txt.

The command Jirtme asked for would be:

  find /the/directory/you/want -type f -name "*.txt" | xargs rm

For safety, I would recommend experimenting with `find` first, e.g.:

  find /the/directory/you/want -type f -name "*.txt"

This will just print a list of filenames. If it looks sensible then you
can go on to piping it to "| xargs rm", which actually deletes the
files.

>Bela<