Commands using egrep (220)


  • 1
    pidof () { ps acx | egrep -i $@ | awk '{print $1}'; }
    pmbuko · 2009-02-06 15:33:46 12
  • Yet another ps grep function, but this one includes the column headings. Show Sample Output


    1
    psg () { ps auxwww | egrep "$1|PID" | grep -v grep }
    mulad · 2009-02-18 23:37:35 6
  • Ran as the postgres user, dumps each database individually. It dumps with the create statements as well, so you can just 'zcat $x-nightly.dmp.gz | psql' to reimport/recreate a database from a backup.


    1
    for x in `psql -e\l | awk '{print $1}'| egrep -v "(^List|^Name|\-\-\-\-\-|^\()"`; do pg_dump -C $x | gzip > /var/lib/pgsql/backups/$x-nightly.dmp.gz; done
    f4nt · 2009-02-21 15:21:09 6

  • 1
    system_profiler SPPowerDataType | egrep -e "Connected|Charge remaining|Full charge capacity|Condition" | sed -e 's/^[ \t]*//'
    bpfx · 2009-07-01 15:09:08 8
  • There's probably a more efficient way to do this rather than the relatively long perl program, but perl is my hammer, so text processing looks like a nail. This is of course a lot to type all at once. You can make it better by putting this somewhere: clf () { (curl -d "q=$@" http://www.commandlinefu.com/search/autocomplete 2>/dev/null) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/<a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +|\([0-9]+ votes,//g;s/^\//http:\/\/commandlinefu.com\//g'; } Then, to look up any command, you can do this: clf diff This is similar to http://www.colivre.coop.br/Aurium/CLFUSearch except that it's just one line, so more in the spirit of CLF, in my opinion. Show Sample Output


    1
    (curl -d q=grep http://www.commandlinefu.com/search/autocomplete) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +//g;s/^\//http:\/\/commandlinefu.com\//g'
    isaacs · 2009-07-08 22:10:49 13
  • just bored here at work ... if your are daring ... add '| bash' .... enjoy require 'ruby' Show Sample Output


    1
    curl -s http://www.commandlinefu.com/commands/browse|egrep '("Fin.*and"|<div class="command">.*</div>)'|sed 's/<[^<]*>//g'|ruby -rubygems -pe 'require "cgi"; $_=sprintf("\n\n%-100s\n\t#%-20s",CGI.unescapeHTML($_).chomp.strip, gets.lstrip) if $.%2'
    copremesis · 2009-08-18 19:04:03 4
  • better integration. works on all Unices works one bash and ksh. Show Sample Output


    1
    function catv { egrep -v "^$|^#" ${*} ; }
    mobidyc · 2009-09-11 14:58:47 3
  • Work for me on CentOS, grep and print ip addresses of ssh bruteforce attempts Show Sample Output


    1
    egrep 'Failed password for invalid' /var/log/secure | awk '{print $13}' | uniq
    servermanaged · 2009-10-04 18:08:13 7
  • Of course, you can adjust "Maildir" to your config... Show Sample Output


    1
    find ~/Maildir/ -mindepth 1 -type d | egrep -v '/cur$|/tmp$|/new$' | xargs
    ook · 2009-11-05 14:11:29 3

  • 1
    nmap -sP <subnet>.* | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' > results.txt ; for IP in {1..254} ; do echo "<subnet>.${IP}" ; done >> results.txt ; cat results.txt | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -u
    bortoelnino · 2010-01-22 00:26:42 4
  • lists all files that are opened by processess named $processname egrep 'w.+REG' is to filter out non file listings in lsof, awk to get the filenames, and sort | uniq to remove duplciation Show Sample Output


    1
    lsof -c $processname | egrep 'w.+REG' | awk '{print $9}' | sort | uniq
    alustenberg · 2010-02-24 16:47:49 6
  • This shows you which files are most in need of commenting (one line of output per file)


    1
    find ./ -name *.h -exec egrep -cH "// | /\*" {} \; | awk -F':' '{print $2 ":" $1}' | sort -gr
    blocky · 2010-04-23 19:00:07 3
  • Will automatically take the size of the file but longer, usefull only if in an function.


    1
    dd if=FILE | pv -s $(stat FILE | egrep -o "Size: [[:digit:]]*" | egrep -o "[[:digit:]]*") | dd of=OUTPUT
    andrepuel · 2011-02-09 22:21:06 4
  • Look mah! All pipes


    1
    ps ax | egrep "*.exe|*exe]" | awk '{ print $1 }' | xargs kill
    coffeeaddict_nl · 2011-03-01 09:48:47 3

  • 1
    egrep -v "^$|^#" file
    wincus · 2011-05-23 11:39:24 18
  • Say your dependencies specified in your Makefile (or dates on your source files) is causing 'make' to skip some source-files (that it should not) or on the other other end, if it is causing make to always build some source-files regardless of dates of target, then above command is handy to find out what 'make' thinks of your date v/s target date-wise or what dependencies are in make's view-point. The egrep part removes the extra noise, that you might want to avoid. Show Sample Output


    1
    make -d | egrep --color -i '(considering|older|newer|remake)'
    b_t · 2011-06-03 01:55:08 53
  • Advanced revision to the command 8776 . This revision follows symbolic links. The quotation-marks surrounding $(which $1) allows for graceful handling of errors ( ie. readlink does not complain incase 'which' command generates (null) output) Show Sample Output


    1
    whichpkg () { dpkg -S $1 | egrep -w $(readlink -f "$(which $1)")$; }
    b_t · 2011-07-17 13:39:56 3
  • Get all URLs from website via Regular Expression... You must have lynx installed in your computer to execute the command. --> lynx --dump "" | egrep -o "" - Must substitute it for the website path that you want to extract the URLs - Regular Expression that you wanna filter the website Show Sample Output


    1
    lynx --dump "http://www.google.com.br" | egrep -o "http:.*"
    felipelageduarte · 2011-09-05 01:12:15 3
  • Hide comments and empty lines, included XML comments, Show Sample Output


    1
    nocomments () { cat $1 | egrep -v '^[[:space:]]*#|^[[:space:]]*$|^[[:space:]]*;' | sed '/<!--.*-->/d' | sed '/<!--/,/-->/d'; }
    RuizTapiador · 2011-11-04 12:47:39 57
  • Command is properly working on HP-UX 11.31 Show Sample Output


    1
    for i in `netstat -rn|egrep -v "Interface|Routing"|awk '{print $5}'`;do ifconfig $i;done
    giorger · 2011-12-16 09:49:03 6
  • First get a api key for google url shortner from here https://developers.google.com/url-shortener/ Then replace the API_KEY in the command Show Sample Output


    1
    shorty () { curl -s https://www.googleapis.com/urlshortener/v1/url\?key\=API_KEY -H 'Content-Type: application/json' -d '{"longUrl": "'"$1"'"}' | egrep -o 'http://goo.gl/[^"]*' }
    cybersiddhu · 2012-04-26 18:30:50 4
  • Simple TCPDUMP grepping for common unsafe protocols (HTTP, POP3, SMTP, FTP) Show Sample Output


    1
    tcpdump port http or port ftp or port smtp or port imap or port pop3 -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user ' --color=auto --line-buffered -B20
    jseidl · 2012-06-18 19:27:54 3

  • 1
    egrep -v '(\t)?#.*|^$' /etc/apache2/sites-available/default
    sc0rp1us · 2012-12-07 06:04:14 4

  • 1
    tcpdump -i eth0 port http or port smtp or port imap or port pop3 -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|userna me:|password:|login:|pass |user '
    ene2002 · 2013-02-07 19:14:58 4
  • Enhanced version: fixes sorting by human readable numbers, and filters out non MB or GB entries that have a G or an M in their name.


    1
    du --max-depth=1 -h * |sort -h -k 1 |egrep '(M|G)\s'
    TerDale · 2013-02-14 08:56:56 6
  •  < 1 2 3 4 5 >  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


Check These Out

Adding Prefix to File name
Adding course name prefix to lecture pdfs

Rename all subtitles files with the same name of mp4 files in same folder
Use this command if you want to rename all subtitles for them to have the same name as the mp4 files. NOTE: The order of "ls -1 *.mp4" must match the order of "ls -1 *.srt", run the command bellow to make sure the *.srt files will really match the movies after run this command: paste -d:

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Google Translate
$ translate [output-language] [source-language] 1) "some phrase" should be in quotes 2) [output-language] - optional (default: English) 3) [source-language] - optional (default: auto) $ translate "bonjour petit lapin" hello little rabbit $ translate "bonjour petit lapin" en hello little rabbit $ translate "bonjour petit lapin" en fr hello little rabbit

Calculate days on which Friday the 13th occurs (inspired from the work of the user justsomeguy)
Friday is the 5th day of the week, monday is the 1st. Output may be affected by locale.

Check if the LHC has destroyed the world
This says if the LHC has destroyed the world. Run it in a loop to monitor the state of Earth. Might not work reliable, if the world has actually been destroyed.

Use socat to emulate an SMTP mail SERVER
Lots of scripts show you how to use socat to send an email to an SMTP server; this command actually emulates an SMTP server! It assumes the client is only sending to one recipient, and it's not at all smart, but it'll capture the email into a log file and the client will stop retrying. I used this to diagnose what emails were being sent by cron and subsequently discarded, but you can use it for all sorts of things.

find the rpm package name that provides a specific file
For Linux distributions using rpm (eg Mandriva), this command will find the rpm package name that provides a file.

Redirect STDIN
Several times, I find myself hitting my up arrow, and changing the search term. Unfortunately, I find myself wasting too much time typing: $ grep kernel /var/log/messages Redirecting STDIN allows me to put the search term at the end so I less cursor movement to change what I'm searching for: $ < /var/log/messages grep kernel If you're using the emacs keyboard binding, then after you press your up arrow, press CTRL+w to erase the word. If this has already been submitted, I couldn't find it with the search utility.

dd with progress bar and statistics
Will automatically take the size of the file but longer, usefull only if in an function.


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: