Unix Shell - bash, delete the content of a directory

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2007 > bash, delete the content of a directory





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author bash, delete the content of a directory
di0rz`

2007-05-25, 7:17 am

hi, everyone
i am looking for a tip to delete the content of a directory without
deleting the actual directory with bash

thank you

SiKing

2007-05-25, 7:17 am

di0rz` wrote:
> i am looking for a tip to delete the content of a directory without
> deleting the actual directory with bash


$ man rm

Try:
$ rm -rf <directory>/*
$ rm -rf <directory>/.* # if you also want to hit dot-files

Or is there something that I missed?


--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
------END GEEK CODE BLOCK------
Chris F.A. Johnson

2007-05-26, 7:21 am

On 2007-05-25, di0rz` wrote:
> hi, everyone
> i am looking for a tip to delete the content of a directory without
> deleting the actual directory with bash


shopt -s dotglob
rm -rf "$dir"/*

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
di0rz`

2007-05-28, 7:19 pm

thanks it's working


On May 25, 8:11 am, SiKing <nos...@noway.invalid> wrote:
> di0rz` wrote:
>
> $ man rm
>
> Try:
> $ rm -rf <directory>/*
> $ rm -rf <directory>/.* # if you also want to hit dot-files
>
> Or is there something that I missed?
>
> --
> -----BEGIN GEEK CODE BLOCK-----
> Version: 3.1
> GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
> PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
> ------END GEEK CODE BLOCK------



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com