Hot answers tagged

32

There's no reason that's preferable syntax on its own. It's sometimes used as a hack when "grepping" for a process (e.g., ps aux | grep [a]pache). Using that syntax prevents grep from matching its own command line in the process list. See How to prevent "ps" reporting its own process?


20

According to nginx documentation: Then regular expressions are checked, in the order of their appearance in the configuration file. The search of regular expressions terminates on the first match, and the corresponding configuration is used. In your configuration, the following location is defined before the one with the proxy_pass and it matches ...


14

It figures you're starting the contents of the location block. It figures wrong. Wrap it in quotes: location ~ "^/i/gallery2/(\d{1,4})(.*)$" {


13

There is, unsurprisingly, a tool for this: grepcidr. It is not included by default with any system I'm aware of, but you can download it from here, and it is in both the Ubuntu package repository and the FreeBSD ports collection as well. (Version 2.0 works with IPv6 networks too)


12

I used to write perl scripts to do this, until I discovered the rename command. It accepts a perl regex to do the rename: for this, I just typed two commands: rename 's/(\w+)-(\w+)-(\d\d)-(\d{4})-NODATA.txt\$1.$4$3$2.log$//' * rename 'y/A-Z/a-z/' *.log


12

You should use anchor, and in rsync the anchor character is '/'. So in your string should be: rsync -a --include="/.includeme" --exclude="/.*" ./ DEST


11

You probably want sed 's/exp1/exp2/g' foo.txt > foo2.txt Read more at Sed tutorial, Another tutorial, and A small tutorial at Linux HOWTOs


11

GNU find by default uses emacs regular expressions, you can change that type with -regextype option (see man find). If you use -regextype posix-egrep your expression seems to work. You could then also probably reduce the pattern to ^.+(jpg|gif|exe)$ With emacs: find . -regex '.+\(jpg\|gif\|exe\)$' . See this section of emacs manual for those specific ...


11

Well, after almost a day of hair pulling, I finally understand a) how to do it and b) a misconception I have about sec. In reading the sec man page and it describes desc= as essentially showing the match. So in my mind, that meant it should show whatever was matched in pattern. Well, yes, that is true, in this case the match in that pattern is the; ...


10

Because when you grep for [j]ava, the process is named 'grep [j]ava'. '[j]ava' doesn't match the regex '[j]ava', and thus doesn't show up in the results.


8

This is what I use: for GUI grepWin: link text for superfast commandline: gsar.exe from link text


8

These appear to be settings internal to the PCRE engine in order to limit the maximum amount of memory/time spent on trying to match some text to a pattern. The pcreapi manpage does little to explain it in layman's terms: The match_limit field provides a means of preventing PCRE from using up a vast amount of resources when running patterns that are ...


8

First thought is "Don't block websites". This is fundamentally a management/HR problem, not a technical one. If you really have problems with employees screwing-off instead of getting their work done, time for new employees. No that isn't a pleasant process, but I absolutely guarantee you'll be happier, more productive, and more profitable in the long run. ...


8

I believe that this website may help you greatly: http://regex101.com/r/uP4nT1


8

A small addition to the great answer from Xaviar: If you happen to be not so well acquainted with nginx, there's an important difference between adding the slash to the end of the the proxy_pass directive. The following does not work: location ~* ^/dir/ { rewrite ^/dir/(.*) /$1 break; proxy_pass http://backend/; but this one does: location ~* ...


7

Use the -o option in grep. Eg: $ echo "foobarbaz" | grep -o 'b[aeiou]r' bar


7

DNS doesn't. But the most popular bind9 nameserver daemon supports this kind of syntax in its zone files: $GENERATE 1-99 www$ CNAME www$.other-domain.com. Beware that this is incompatible with other DNS server software.


7

Just use the -v option: myproc | grep -v requests


7

Use bash variables and a for loop: for i in *;do mv $i ${i%0000777};done when you surround the variable name with {} and add a % sign, it returns the value of the variable with everything after the % removed. If you use a # sign it will remove from the beginning of the string. so for i in *;do mv $i ${i#thumb_};done Would strip the thumb_ off the front.


7

I'm not sure why that doesn't work but this does: echo '[123]' | sed 's/\(\[\|\]\)//g' or this: echo '[123]' | sed -r 's/(\[|\])//g' You can also try a different approach and match the string inside the brackets (assuming the string can be matched easily and is not defined by the brackets): echo '[123]' | egrep -o "[0-9]+" I'm having the same ...


6

cut might be useful: $ echo hello | cut -c1,3 hl $ echo hello | cut -c1-3 hel $ echo hello | cut -c1-4 hell $ echo hello | cut -c4-5 lo Shell Builtins are good for this too, here is a sample script: #!/bin/bash # Demonstrates shells built in ability to split stuff. Saves on # using sed and awk in shell scripts. Can help performance. shopt -o nounset ...


6

In rewrite you match against URL's path part only. Which means, $1 will not contain the query string. By default, Nginx appends original query string to the rewrite replacement. So, it should be safe to write rewrite ^(.*)$ $1?locale=de-de break; In the case you do not want Nginx to append the original query string, simply specify ? in the end of ...


6

You might be better off using a tool like awk. awk '/^----+$/ {flag=1;next} /Disconnected from Server/{flag=0} flag {print}' See: http://nixtip.wordpress.com/2010/10/12/print-lines-between-two-patterns-the-awk-way/


6

Define another failregex (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:.*)$ I tested this regex with fail2ban-regex and is working.


6

You have to escape the regex. ack 'console\.log\(foo' (You should escape the . so that you don't match "consoleflog", because . matches any single character) You can use Perl's `\Q' metacharacter to quote the entire string: ack '\Qconsole.log(foo' And if you would rather not do that, do this: ack -Q 'console.log(foo' The -Q takes its letter from ...


6

$ url=git://github.com/some-user/my-repo.git $ basename=$(basename $url) $ echo $basename my-repo.git $ filename=${basename%.*} $ echo $filename my-repo $ extension=${basename##*.} $ echo $extension git


6

As of logcheck 1.1.9.1 (which was released in 2002), blank lines, lines that only consist of [:space:] characters, and comments (lines that begin with #) are filtered out before the rule files are passed to egrep. This is mentioned in passing in the "WRITING RULES" section of docs/README.logcheck-database, which is available in ...


6

You can use this rule: ^%(__prefix_line)sReceived disconnect from <HOST>: 11: (Bye Bye)? \[preauth\]$ To test it with fail2ban-regex or egrep, you can just strip off the ^%(__prefix_line)s from the beginning. Add this line to the failregex variable in your /etc/fail2ban/filter.d/sshd.conf. A run with fail2ban-regex gave me these results, confirming ...


5

Short version is: why, yes, you can pipe output from the shell, like any other program. From there, you can use whatever you like, like, say $ bash | sed "$(echo -e "s@dog@\e[31mdog\e[0m@g; s@more here@more here@g;")" Thought I'd add my 'rainbow'. Enjoy: for((b=0;$b<8;b++)); do echo -ne "\e[4${b}m4$b : "; \ for((f=0;$f<8;f++)); do echo -ne ...



Only top voted, non community-wiki answers of a minimum length are eligible