Tag Info

Hot answers tagged

33

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?


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

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


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.


10

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


9

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


9

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


9

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)


8

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


8

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


7

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


7

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


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

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/


5

You can show all listening ports with: netstat --protocol=ip -nlp About your command, grep works line by line. Where did you read this syntax, it seems belong to sed.


5

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


5

Let's see, how about... for f in *.mpg; do touch -r "$f" "${f}.m4v" done No need for regexps, just to take the problem from the right side. It's much easier to circle through *.mpg and add .m4v to them than the contrary, although you could also write it the other way without regexps (just for fun): for f in *.m4v; do touch -r "${f%\.m4v}" "$f" done ...


5

Your %d format specifier is forcing printf to print an integer value. If you change it to %f then it would print the full number. You can use %.nf to limit the number of decimal places printed so %.1f would print one decimal place.


5

You could also use awk instead. With awk you can easily use Boolean constructs. getsebool -a | awk '/ftp/ && /home/ {print}' # case insensitive getsebool -a | awk 'tolower($0)~/ftp/ && tolower($0)~/home/ {print}'


5

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.


4

find . -type f -print | xargs sed -i.bak 's#http://site.com/sites/etc#something else#g'


4

The * operator is greedy. This means that it will grab as much as it possibly can. In your example, the first (.*) block will match /funny/1. The second one will match nothing at all, but that's OK because * matches "zero or more" of the preceding character. Using a different block to match the parts in between the slashes will do the trick. Something ...


4

As this is always the same path I think it doesn't make sense to put effort into that. You could disable the bash feature (MAILCHECK=0) and put your own check code into PS1. But why bother, if alias new_mail="tail /var/spool/mail/root" does all you need?


4

Don't be lazy. Copy/paste is the standard solution for this. Of course, the example you give could be remediated with the mail command, but I understand that there may be other other examples that could benefit. For instance, I use the Eterm terminal on my Mac and Linux systems. It parses directory paths and URL's incredibly well (PuTTY doesn't). xterm ...


4

The recently released rgxg command line tool generates regular expressions that match all addresses in a CIDR block: $ rgxg cidr 192.168.128.0/18 192\.168\.(19[01]|1[3-8][0-9]|12[89])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]) or $ rgxg cidr 2001:db8:a:b:c:d::/112 ...


4

Maybe something like getsebool -a | egrep -i ".*(ftp.*home|home.*ftp).*" would work for you?


4

RewriteRule link/go/(.*)$ process.php?email=$1 This seems to work. You should do the email validation in process.php, not in the .htaccess rule for the sake of readability (plus, you can at least have a nice error message on the page). This works because anything after link/go/ will be matched (. matches any character, so .* means match any character as ...


4

If you just want to extract the file, I would use File::Basename


4

Use rewrite instead. Try something like RewriteEngine on RewriteCond %{HTTPS} =on RewriteCond %{REQUEST_URI} !^/system_ RewriteRule ^/(.*) http://exsite.tld/$1 [R=301,L] ought to do it. Please test it before implementing in live environment. What these rules state is: 1. enable rewrite engine, 2. check if HTTPS is on, 3. check if the URI path does not ...


4

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



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