Portal Home > Knowledgebase > Articles Database > how to safely remove files from a directory
how to safely remove files from a directory
Posted by crazyaboutlinux, 01-16-2013, 07:58 AM |
Hi,
I have directory named "virusscan" under this direcotry i have so many files but i want to remove some specific files which has comman word in entire filename and that word is "hostname" how can i do that using rm or sed command ?
|
Posted by mike86, 01-16-2013, 08:31 AM |
cd to the directory and use this:
rm *.hostname*
or if you don't want to confirm every one:
rm -f *.hostname*
|
Posted by BestServerSupport, 01-16-2013, 10:01 AM |
OR else, you can also use below:
find /path/to/virusscan/ -name 'hostname*' -print -delete
|
Posted by m4rc3, 01-16-2013, 12:03 PM |
you missed an * there
BTW you can also just delete the folder with rm -rf and re-create it afterwards.
|
Posted by BestServerSupport, 01-16-2013, 12:43 PM |
Hmm. My Bad. Yes, you can also use rm -rf and re-create it afterwards.
|
Posted by kevincheri, 01-16-2013, 03:32 PM |
a slight different way, but purpose is same
find /path/to/virusscan/ -type f -name \*hostname\* -exec rm -f {} \;
|
Posted by crazyaboutlinux, 01-17-2013, 02:34 AM |
Thank you guys for sharing your experience and valuable time to this thread.
|
Add to Favourites Print this Article
Also Read
burst.net (Views: 779)