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

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

HTTP GET request on wireshark remotly

cycle through everything sox knows how to read, playing only the first three seconds
I wasted two hours reading the sox documentation and searching on the web for the format of some obscure fscking sound sample, and then finally came up with this. This plays only the first three seconds of your unknown formatted sound file using every one of sox's built-in filetypes. If you don't get an exact match, you may get close. . I could not fit every single type in and keep it under 127 characters, so you will have to replace "..." with the full list obtainable by `$ sox --help` (or try `Show sample output`) . note: /usr/bin/play should be linked to sox on most systems.

kill all foo process
Kill all processes with foo in them. Similar to pkill but more complete and also works when there is no pkill command. Works on almost every Linux/Unix platform I have tried.

List out classes in of all htmls in directory
Lists out all classes used in all *.html files in the currect directory. usefull for checking if you have left out any style definitions, or accidentally given a different name than you intended. ( I have an ugly habit of accidentally substituting camelCase instead of using under_scores: i would name soemthing counterBox instead of counter_box) WARNING: assumes you give classnames in between double quotes, and that you apply only one class per element.

Remove the first character of each line in a file

Hide or show Desktop Icons on MacOS
Hides all Files and Folders on the MacOS Desktop. To show files and folders, type "true" instead of "false". "Finder" at the end is case sensitive, "finder" doesn’t work

generate random tone

Show crontabs for all users
This is flatcaps tweaked command to make it work on SLES 11.2

print crontab entries for all the users that actually have a crontab
This is how I list the crontab for all the users on a given system that actually have a crontab. You could wrap it with a function block and place it in your .profile or .bashrc for quick access. There's prolly a simpler way to do this. Discuss.


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: