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?


22

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 ...


15

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

Since nginx 0.8.25 named captures can be used in server_name. You should use them. Here, the sub-domain will be stored in a variable called $sub. Then you will be able to reuse it in the rewrite directive : server { listen 80; server_name ~^(?<sub>\w+)\.olddomain\.com$; rewrite ^ $scheme://$sub.doma.in$request_uri? permanent; } Alternatively, ...


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; hostname,...


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.


9

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 ~* ^/dir/...


8

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


8

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


8

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 ...


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'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 ...


8

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


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.


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

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

Try this location ~ "^/[\d]{5}" { # ... } ~ means the a regex location ^ means the beginning of the line [\d] is shorthand for character class matching digits {5} shows that the digits must be exactly five, no more, no less and () parentheses are not necessary if you do not want then to use grouping, $1, for example Double quotes because curley ...


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 /usr/share/doc/logcheck-...


6

It tells you that the URI in the proxy pass directive can't be used in a regex location. This is because nginx can't replace the part of the URI matching the regex in the location block with the one passed in the proxy_pass directive a generic way. Simply imagine your location regex is /foo/(.*)/bar, and you specify proxy_pass http://server/test, nginx ...



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