Commands using egrep (204)

  • Where COMMAND is the process(es) name. I prefer to get all states but you may add ESTABLISHED in the grep regex. lsof -c apache2 | egrep -o 'TCP.*ESTABLISHED.*$' -nP flags are optional and UDP is irrelevant for established connections Similar but using the process id: lsof -nP -p PID | egrep -o '(TCP|UDP).*$' Show Sample Output


    0
    lsof -nP -c COMMAND | egrep -o '(TCP|UDP).*$' | sort -u
    forcefsck · 2011-01-25 12:04:13 0
  • Shorter way to find the device for a given mountpoint


    -1
    df /media/mountpoint |egrep -o '^[/a-z0-9]*'
    DaveQB · 2011-01-24 21:14:55 0
  • scrot, curl, egrep, sed, xsel, libnotify-bin must be installed. P.S. Sorry for so long command Show Sample Output


    0
    scrot $1 /tmp/screenshot.png && curl -s -F file1=@/tmp/screenshot.png -F submit="OMPLOAD\!" http://ompldr.org/upload | egrep '(View file: <a href="v([A-Za-z0-9+\/]+)">)' | sed 's/^.*\(http:\/\/.*\)<.*$/\1/' | xsel -b -i ? (full in a sample output)
    artleg · 2011-01-15 11:33:43 0
  • [Update! Thanks to a tip from ioggstream, I've fixed both of the bugs mentioned below.] You, yes, 𝙔𝙊𝙐, can be the terror of the Internet! Why use normal, boring bullet points in your text, when you could use a ROTATED HEAVY BLACK HEART BULLET (❥)!? (Which would also be an awesome band name, by the way).  This script makes it easy to find unusual characters from the command line. You can then cut and paste them or, if you're using a GTK application, type Control+Shift+U followed by the code point number (e.g., 2765) and then a SPACE.  USAGE: Put this script in a file (I called mine "ugrep") and make it executable. Run it from the command line like so,  ugrep heart  The output will look like this,  ☙ U+2619 REVERSED ROTATED FLORAL HEART BULLET ♡ U+2661 WHITE HEART SUIT ♥ U+2665 BLACK HEART SUIT ❣ U+2763 HEAVY HEART EXCLAMATION MARK ORNAMENT ❤ U+2764 HEAVY BLACK HEART ❥ U+2765 ROTATED HEAVY BLACK HEART BULLET ❦ U+2766 FLORAL HEART ❧ U+2767 ROTATED FLORAL HEART BULLET ⺖ U+2E96 CJK RADICAL HEART ONE ⺗ U+2E97 CJK RADICAL HEART TWO ⼼ U+2F3C KANGXI RADICAL HEART  You can, of course, use regular expressions. For example, if you are looking for the "pi" symbol, you could do this:  ugrep '\bpi\b'  REQUIREMENTS: Although this is written in Bash, it assumes you have Perl installed because it greps through the Perl Unicode character name module (/usr/lib/perl5/Unicode/CharName.pm). Note that it would not have made more sense to write this in Perl, since the CharName.pm module doesn't actually include a subroutine for looking up a character based on the description. (Weird.)  BUGS: In order to fit this script in the commandlinefu limits, a couple bugs were added. ① Astral characters beyond the BMP (basic multilingual plane) are not displayed correctly, but see below. ② Perl code from the perl module being grepped is sometimes extraneously matched.  MISFEATURES: Bash's printf cannot, given a Unicode codepoint, print the resulting character to the terminal. GNU's coreutils printf (usually "/usr/bin/printf") can do so, but it is brokenly pedantic about how many hexadecimal digits follow the escape sequence and will actually die with an error if you give the wrong number. This is especially annoying since Unicode code points are usually variable length with implied leading zeros. The CharNames.pm file represents BMP characters as 4 hexits, but astral characters as 5. In the actual version of this script that I use, I've kludged around this misfeature by zero-padding to 8 hexits like so,  /usr/bin/printf "\U$(printf "%08x" 0x$hex)"  TIP 1: The author recommends "xsel" for command line cut-and-paste. For example,  ugrep biohazard | xsel  TIP 2: In Emacs, instead of running this command in a subshell, you can type Unicode code points directly by pressing Control-Q first, but you'll likely want to change the default input from octal to hexadecimal. (setq read-quoted-char-radix 16).  TIP 3: Of course, if you're using X, and you want to type one of the more common unusual characters, it's easiest of all to do it with your Compose (aka Multi) key. For example, hitting [Compose] <3 types ♥. Show Sample Output


    12
    egrep -i "^[0-9a-f]{4,} .*$*" $(locate CharName.pm) | while read h d; do /usr/bin/printf "\U$(printf "%08x" 0x$h)\tU+%s\t%s\n" $h "$d"; done
    hackerb9 · 2010-12-31 16:47:59 5
  • Apply to almost linux distroes. Show Sample Output


    0
    cat /etc/services | egrep [[:blank:]]<port_number>/
    xutale · 2010-11-25 08:04:31 2
  • Returns any file in the folder which would be rejected by Gmail, if you were to send zipped version. (Yes, you could just zip it and knock the extension off and put it back on the other side, but for some people this just isn't a solution) Show Sample Output


    -1
    find | egrep "\.(ade|adp|bat|chm|cmd|com|cpl|dll|exe|hta|ins|isp|jse|lib|mde|msc|msp|mst|pif|scr|sct|shb|sys|vb|vbe|vbs|vxd|wsc|wsf|wsh)$"
    poulter7 · 2010-11-23 16:53:55 0

  • 0
    lynx -dump http://www.domain.com | awk '/http/{print $2}' | egrep "^https{0,1}"
    xutale · 2010-11-10 11:05:52 0
  • Get the IP of a hostname.


    4
    ping -c 1 google.com | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
    BruceLEET · 2010-10-26 01:11:01 2
  • Just a few minor changes. First the usage of lynx instead of curl so no sed is needed to revert the spaces. Then the usages of egrep instead of grep -e to save a few characters and last the removal of the extra 0. Show Sample Output


    0
    findlocation() {place=`echo $@`; lynx -dump "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | egrep "address|coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}
    houghi · 2010-10-18 21:59:26 0
  • Useful for grepping an IP range from the maillog. When for instance dealing with a spam-run from a specific IP range, or when errors occur from or to a specific IP-range. In the example above the IP range 183.0.0.0/10 (183.0.0.0 - 183.63.255.255) To grep the IP range 124.217.224.0/19 (124.217.224.0 - 124.217.255.255) from the maillog: egrep '124\.217\.2(2[4-9]|[34][0-9]|5[0-5])' -J /var/log/maillog* NOTE: the location of the maillog may vary based upon operating system and distribution.


    0
    egrep '183\.([0-9]|(1[0-6]|2[0-3]))' -J /var/log/maillog*
    wazigster · 2010-10-17 21:44:57 0
  • Just an alternative :)


    -2
    links2 -dump http://checkip.dyndns.com| egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
    lokutus25 · 2010-10-08 10:53:33 1
  • Somtime one wants to kill process not by name of executable, but by a parameter name. In such cases killall is not suitable method.


    4
    kill -9 `ps ax | egrep [f]elix.jar | egrep -o -e '^ *[0-9]+'`
    yababay · 2010-09-30 16:45:47 0

  • 2
    svn log 2>&1 | egrep '^r[0-9]+' | cut -d "|" -f2 | sort | uniq -c
    cicatriz · 2010-09-06 15:13:48 2

  • -2
    lynx -dump http://domaim.com | egrep -o -e 'http://[/0-9a-z.]+html'
    yababay · 2010-09-04 17:49:12 0
  • searches through the linux dictionary for the word you're trying to spell (you can use regular expressions, e.g. "< /usr/share/dict/words egrep bro[c]+o[l]+i" ) Show Sample Output


    0
    < /usr/share/dict/words egrep onomatopoeia
    smop · 2010-08-13 00:12:39 1

  • -3
    ls -la | grep $(date +%Y-%m-%d) | egrep -v -e '\.{1,2}' | sed "s/.*\:[0-9]\{2\} \(.\+\)$/\\1/g"
    cicatriz · 2010-07-29 14:37:51 0

  • -3
    netstat -l -p --tcp | egrep -e 'www.*[0-9]{3,4}\/(apache2|httpd)' | awk '{print$7}'
    cicatriz · 2010-07-26 12:52:07 2

  • -2
    egrep '(\[error\])+.*(PHP)+' /var/log/apache2/error.log
    cicatriz · 2010-07-26 12:42:09 0
  • Really, you deserve whatever happens if you have a whitespace character in a file name, but this has a small safety net. The truly paranoid will use '-i'.


    -1
    rm $( ls | egrep -v 'abc|\s' )
    dbbolton · 2010-07-18 10:59:15 1
  • I have this as a file called deletekey in my ~/bin. Makes life a little easier.


    -13
    echo "${1}" | egrep '^[[:digit:]]*$' ; if [ "$?" -eq 0 ] ; then sed -i "${1}"d $HOME/.ssh/known_hosts ; else printf "\tYou must enter a number!\n\n" ; exit 1 ; fi
    DaveQB · 2010-07-11 23:09:11 0
  • Quicker way to search man pages of command for key word Show Sample Output


    0
    function mg(){ man ${1} | egrep ${2} | more; }
    quincymd · 2010-07-01 21:14:24 0
  • This should do the same thing and is about 70 chars shorter. Show Sample Output


    8
    aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
    dbbolton · 2010-06-10 21:23:00 4

  • -3
    find . -type f | sed 's,.*,stat "&" | egrep "File|Modify" | tr "\\n" " " ; echo ,' | sh | sed 's,[^/]*/\(.*\). Modify: \(....-..-.. ..:..:..\).*,\2 \1,' | sort
    pepin · 2010-05-27 22:30:18 0
  • Requires aria2c but could just as easily wget or anything else. A great way to build up a nice font collection for Gimp without having to waste a lot of time. :-) Show Sample Output


    10
    d="www.dafont.com/alpha.php?";for c in {a..z}; do l=`curl -s "${d}lettre=${c}"|sed -n 's/.*ge=\([0-9]\{2\}\).*/\1/p'`;for((p=1;p<=l;p++));do for u in `curl -s "${d}page=${p}&lettre=${c}"|egrep -o "http\S*.com/dl/\?f=\w*"`;do aria2c "${u}";done;done;done
    lrvick · 2010-05-18 07:38:54 0
  • If you have lots of subversion working copies in one directory and want to see in which repositories they are stored, this will do the trick. Can be convenient if you need to move to a new subversion server. Show Sample Output


    0
    (for i in `find . -maxdepth 2 -name .svn | sed 's/.svn$//'`; do echo $i; svn info $i; done ) | egrep '^.\/|^URL'
    jespere · 2010-05-09 11:54:37 0
  • ‹ First  < 3 4 5 6 7 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: