Commands using egrep (209)

  • 25
    curl -Is | egrep '^X-(F|B|L)' | cut -d \- -f 2
    icco · 2009-03-23 19:58:10 8
  • Shows a file without comments (at least those starting by #) - removes empty lines - removes lines starting by # or "some spaces/tabs then #'" Useful when you want to quickly see what you have to customize on a freshly installed application without reading the comments that sometimes are a full 1000 lines documentation :) While posting, I saw this But it's dirty and incomplete, to my mind My original goal was to remove lines like "\t*#" but I can't figure out how to do a egrep '\t' on a command-line. Two workarounds if needed: egrep -v 'press control + V then TAB then #' /your/file or egrep -v -f some_file /your/file #where some_file contains what you want to exclude, example a really inserted TAB

    egrep -v "^$|^[[:space:]]*#" /etc/some/file
    michauko · 2009-05-12 07:14:48 4
  • I'm working in a group project currently and annoyed at the lack of output by my teammates. Wanting hard metrics of how awesome I am and how awesome they aren't, I wrote this command up. It will print a full repository listing of all files, remove the directories which confuse blame, run svn blame on each individual file, and tally the resulting line counts. It seems quite slow, depending on your repository location, because blame must hit the server for each individual file. You can remove the -R on the first part to print out the tallies for just the current directory. Show Sample Output

    svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{print $2}' | sort | uniq -c | sort -r
    askedrelic · 2009-07-29 02:10:45 6
  • [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/ Note that it would not have made more sense to write this in Perl, since the 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 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

    egrep -i "^[0-9a-f]{4,} .*$*" $(locate | 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
  • xargs can be used in this manner to download multiple files at a time, and xargs will in this case run 10 processes at a time and initiate a new one when the number running falls below 10. Show Sample Output

    wget -nv -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
    syssyphus · 2009-08-31 18:37:33 0

  • 10
    nmap -T4 -sP && egrep "00:00:00:00:00:00" /proc/net/arp
    wincus · 2010-01-22 20:36:43 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

    d="";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
  • This should do the same thing and is about 70 chars shorter. Show Sample Output

    aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
    dbbolton · 2010-06-10 21:23:00 4
  • Shows updated status in a terminal window for connections to port '80' in a human-friendly form. Use 'watch -n1' to update every second, and 'watch -d' to highlight changes between updates. If you wish for status updates on a port other than '80', always remember to put a space afterwards so that ":80" will not match ":8080". Show Sample Output

    watch 'netstat -anptu |egrep "^Proto|:80 "'
    Mozai · 2011-05-18 15:05:52 4

  • 6
    egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
    ferqwerty · 2009-02-17 11:12:26 2

  • 6
    tail -F file | egrep --color 'pattern|$'
    sklm · 2009-10-16 04:01:14 0
  • For the record: I didn't build this. Just shared what I found that worked. Apologies to the original author! I decided I should fix the case where is not matched for the next time I need this. So I read rfc1035 and formalized the host name regex. If anyone finds any more holes, please comment.

    egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?'
    putnamhill · 2009-11-28 15:41:42 3
  • This is the most straightforward approach: first regexp limits dictionary file to words with thirteen or more characters, second regexp discards any words that have a letter repeated. (Bonus challenge: Try doing it in a single regexp!) Show Sample Output

    cat /usr/share/dict/words | egrep '^\w{13,}$' | egrep -iv '(\w).*\1'
    hackerb9 · 2014-09-29 12:52:09 3
  • Greps IRC logs for phrases and lists users who said them. Show Sample Output

    cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
    rhythmx · 2009-02-05 21:23:53 0

  • 5
    u=`curl -d 'dl.start=Free' $(curl $1|perl -wpi -e 's/^.*"(http:\/\/rs.*)" method.*$/$1/'|egrep '^http'|head -n1)|grep "Level(3) \#2"|perl -wpi -e 's/^.*(http:\/\/rs[^\\\\]*).*$/$1/'`;sleep 60;wget $u
    fel1x · 2009-04-01 20:14:41 1
  • Quick and dirty command that counts how many words can be typed just using the home row on the Dvorak Simplified Keyboard layout from a dictionary file, in this case /usr/share/dict/words. According to the regular expression supplied, each word must contain all the keys on the Dvorak home row, and no other characters. For comparison, I've shown how many words are installed in my dictionary, how many can be typed with just the Dvorak home row and how many can be typed with just the QWERTY home row in the sample output. Nearly 10 times the amount. If you want to see the words, remove the -c switch, and each word will be printed out. Show Sample Output

    egrep -ci ^[aoeuidhtns-]+$ /usr/share/dict/words
    atoponce · 2009-04-15 20:31:46 3
  • webserver adds an X-Bender or X-Fry HTTP header to every response! Show Sample Output

    echo -e "HEAD / HTTP/1.1\nHost:\n\n" | nc 80 | egrep "Bender|Fry" | sed "s/X-//"
    ricardoarguello · 2009-07-30 19:15:07 0

  • 4
    egrep '^[^#]' some_file
    nottings · 2009-02-19 17:35:52 9
  • Want to know why your load average is so high? Run this command to see what processes are on the run queue. Runnable processes have a status of "R", and commands waiting on I/O have a status of "D". On some older versions of Linux may require -emo instead of -eo. On Solaris: ps -aefL -o s -o user -o comm | egrep "^O|^R|COMMAND" Show Sample Output

    ps -eo stat,pid,user,command | egrep "^STAT|^D|^R"
    jyoder · 2009-02-20 19:00:17 0
  • url can be a working copy or url to a svn repository, revision is any valid revision number for that branch. Show Sample Output

    svn log $url -r $revision -v | egrep " [RAMD] \/" | sed s/^.....//
    nitehawk · 2009-04-27 19:50:06 2

  • 4
    egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file.txt
    P17 · 2009-05-28 14:46:17 4
  • this is useful to highlight only some code without losing other lines (eg. software, logs, scripts)

    egrep --color=auto 'usb|' /var/log/messages
    ioggstream · 2009-07-08 15:20:31 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.

    kill -9 `ps ax | egrep [f]elix.jar | egrep -o -e '^ *[0-9]+'`
    yababay · 2010-09-30 16:45:47 0
  • Get the IP of a hostname.

    ping -c 1 | 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
  • This command would be useful when it is desirable to list only the directories. 'egrep' chooses only the lines that begin with 'd'. Show Sample Output

    ls -l | egrep ^d
    ergut · 2009-02-08 22:21:55 4
  •  1 2 3 >  Last ›

What's this? 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

Check These Out

Set GIT_COMMITTER_DATE = GIT_AUTHOR_DATE for all the git commits

List Network Tools in Linux
Get all the networking related commands for your distro

Inverted cowsay
It's quite fun to invert text using "" (ref: ). Slightly more challenging is to flip a whole "cowsay". :-)

Find the package that installed a command

Optimal way of deleting huge numbers of files

find text in a file
this will find text in the directory you specify and give you line where it appears.

SSH Auto-login with password
You need to install "sshpass" for this to work. apt-get install sshpass

Get the full path to a file
Part of coreutils - so needs no extra package...

Backup with versioning
Apart from an exact copy of your recent contents, also keep all earlier versions of files and folders that were modified or deleted. Inspired by the excellent EVACopy

Create a new file

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.


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: