Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
08-23-2017, 08:18 AM
|
#1
|
Member
Registered: Jan 2016
Posts: 254
Rep:
|
Clear all lines in a csf deny file that contains text: Added by Fail2Ban
Hello
I am looking for an easy way to clear all lines like:
Code:
123.456.789.000 # Added by Fail2Ban for nginx-get-f5 - Wed Aug 23 13:02:55 2017
from:
by checking the text: Added by Fail2Ban
How can i do that with a simple command from ssh on my Centos server?
Thank you
|
|
|
08-23-2017, 08:29 AM
|
#2
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,892
|
Suggest you look up the 'd' option for the sed command.
|
|
|
08-23-2017, 08:32 AM
|
#3
|
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,504
|
Code:
grep -v Fail2Ban /etc/csf/csf.deny > /tmp/csf.deny;mv /tmp/csf.deny /etc/csf/csf.deny
You're welcome....
|
|
|
08-23-2017, 08:44 AM
|
#4
|
Member
Registered: Jan 2016
Posts: 254
Original Poster
Rep:
|
I think that can be done direct to the file without creating another file in /tmp folder and so on...... ?
|
|
|
08-23-2017, 08:47 AM
|
#5
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,892
|
Quote:
Originally Posted by bmxakias
I think that can be done direct to the file without creating another file in /tmp folder and so on...... ?
|
I agree, and ...
Quote:
Originally Posted by rtmistler
Suggest you look up the 'd' option for the sed command.
|
|
|
|
08-23-2017, 08:48 AM
|
#6
|
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,504
|
Quote:
Originally Posted by bmxakias
I think that can be done direct to the file without creating another file in /tmp folder and so on...... ?
|
Sure, go read rtmistler's reply and read up on sed
Edit: I never said my method was the best, simply an alternative.
Last edited by TenTenths; 08-23-2017 at 08:52 AM.
|
|
|
08-23-2017, 12:55 PM
|
#7
|
Member
Registered: Jan 2016
Posts: 254
Original Poster
Rep:
|
@TenTenths
No offense and thanks for your reply
@rtmistler
Thanks i will try to find a way to do it.....
|
|
|
08-23-2017, 01:01 PM
|
#8
|
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,504
|
Quote:
Originally Posted by bmxakias
@TenTenths
No offense and thanks for your reply
|
None taken.
|
|
|
08-23-2017, 01:22 PM
|
#9
|
Member
Registered: Jan 2016
Posts: 254
Original Poster
Rep:
|
Can't find a sample with sed -d option on how to do that
Any help please?
Any sample?
|
|
|
08-23-2017, 02:21 PM
|
#11
|
Member
Registered: Jan 2016
Posts: 254
Original Poster
Rep:
|
Quote:
sed '/Added by Fail2Ban/d' /etc/csf/csf.deny
|
Like this?
Last edited by bmxakias; 08-23-2017 at 02:25 PM.
|
|
|
08-23-2017, 02:26 PM
|
#12
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,892
|
Quote:
Originally Posted by bmxakias
Like this?
|
Yes and try it. Because the output result will go to stdout and in fact to get it to that file, you'd need to use the -i flag for sed or pipe the result to a file. The -i flag will perform the changes "in place", however it is a great idea to see the outcome piped to stdout first to validate your syntax. I believe you may need a leading 's', as in:
|
|
|
08-23-2017, 02:29 PM
|
#13
|
Member
Registered: Jan 2016
Posts: 254
Original Poster
Rep:
|
Maybe like this then?
Quote:
sed -i 's/Added by Fail2Ban/d' /etc/csf/csf.deny
|
Last edited by bmxakias; 08-23-2017 at 10:57 PM.
|
|
|
08-25-2017, 01:22 AM
|
#14
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Posts: 2,917
|
Like the s command in sed (substitute)
there is the d command (delete).
|
|
|
08-25-2017, 06:24 AM
|
#15
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Posts: 2,917
|
Quote:
Originally Posted by bmxakias
Like this?
|
Yes like this.
Add -i option to direct the output back to the file.
Code:
sed -i '/Added by Fail2Ban/d' /etc/csf/csf.deny
Last edited by MadeInGermany; 08-25-2017 at 06:26 AM.
|
|
|
All times are GMT -5. The time now is 12:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|