Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to delete a specific config file for Awstats for every user on the box. What is the best way to delete them, and possibly, in one line?

All the files are under /home and have this structure:

/home/{username1}/domains/{domain1}/public_html/awstats/.data/awstats.{domain1}.conf
/home/{username1}/domains/{domain2}/public_html/awstats/.data/awstats.{domain2}.conf

/home/{username2}/domains/{domain1}/public_html/awstats/.data/awstats.{domain1}.conf

Some /home/{username}/domains/ folders have multiple domain subfolders.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Have you tried

rm /home/*/domains/*/public_html/awstats/.data/awstats.*.conf

?

Warning: if there is a file whose name is something like

/home/phred/domains/sci-fi/public_html/awstats/.data/awstats.fantasy.conf

i.e., the two occurrences of {domain1} don’t match, then the above command will delete it, too.  Is that a problem?

P.S. Unless verifying that the two occurrences of {domain1} match is what you’re asking about, or there’s something else that I’m missing, this question is not about regular expressions (regexs).  When *, ?, and [ (with a matching ]) are used on the shell command line, they are called wildcards.

share|improve this answer
    
Clearly I was thinking way too difficult with regular expressions and xargs! I haven't tried just using *'s in the command, but it seemed to work just fine. You saved me a lot of time. –  lemimique Jan 4 '13 at 11:12
    
Glad to help. May I draw your attention to the How do I ask questions? section of the Super User FAQ (Frequently Asked Questions) –– “When you have decided which answer is the most helpful to you, mark it as the accepted answer by clicking on the check box outline to the left of the answer.” If you do that, we both benefit. After you have earned some reputation, you can also vote up helpful answers by clicking the upward pointing arrow to the left of the answer. –  Scott Jan 4 '13 at 22:41

In /home run the following command

find . -name 'awstats*conf' | xargs rm

Before piping the result to xargs run the find . -name 'awstas*.conf by itself to verify that it lists only the files you want to remove. Pipe to xargs rm only after you confirm th is.

The find when used as shown above will recursively look for files that match the regex specified. For more information check the man pages for find and xargs.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.