
Terminal - Commands tagged grep - 308 results
find /path/to/search/directory -exec grep -Hn "pattern" {} \;
This is sample output - yours may be different.
vim $(grep [REGULAR_EXPRESSION] -R * | cut -d":" -f1 | uniq)
This is sample output - yours may be different.
for k in `git branch -r|awk '{print $1}'`;do echo -e `git show --pretty=format:"%Cgreen%ci_%C(blue)%c r_%Cred%cn_%Creset" $k|head -n 1`$k;done|sort -r|awk -F"_" '{printf("%s %17s %-22s %s\n",$1,$2,$3,$4)}'
This is sample output - yours may be different.
brd = "! f() { for k in $(git branch $@ | sed 's/^..//; s/ .*//'); do echo "$(git log -1 --pretty='%Cgreen%ci %Cblue(%cr)%Creset ' $k) $k" ; done | sort -r; }; f"
This is sample output - yours may be different.
$ git brd
2012-09-13 06:03:06 -0700 (2 weeks ago) master
2012-08-20 02:32:13 -0700 (6 weeks ago) feature-foo
$ git brd -r
2012-09-13 06:03:06 -0700 (2 weeks ago) origin/feature-foo
2012-09-13 06:03:06 -0700 (2 weeks ago) origin/master
2012-09-13 06:03:06 -0700 (2 weeks ago) origin/HEAD
Add this line to your ~/.gitconfig for a git alias "git brd" (i.e., brd = (br)anch+(d)ate) which sorts branches by date. Allows you to pass in limited "git branch" options such as "-r" (remote) or "-a" (all). (Note: forum added "$" prefix to command; obviously in gitconfig there is no "$" prefix.)
for file in `svn st | awk '{print $2}'`; do svn revert $file; done
This is sample output - yours may be different.
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic*//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
This is sample output - yours may be different.
Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.
egrep_escape() { echo "$1" |sed -re 's/([\\.*+?(|)^$[])/\\\1/g' -e 's/\{/[{]/g'; }
This is sample output - yours may be different.
$ egrep_escape '../lost+found'
\.\./lost\+found
$ egrep_escape "^(\W+|[a-z]{2}.*)$"
\^\(\\W\+\|\[a-z][{]2}\.\*\)\$
Use if you want to include untrusted literal strings in your grep regexes.
I use it to list all mounts below a directory:
dir=/mnt/gentoo; cat /proc/mounts |awk '{print $2}' |egrep "^$(egrep_escape "$dir")(/|$)"
/mnt/gentoo
/mnt/gentoo/proc
/mnt/gentoo/sys
/mnt/gentoo/dev
/mnt/gentoo/home
Works even if $dir contains dangerous characters (e.g. comes from a commandline argument).
egrep '.*(("STATUS)|("HEAD)).*' http_access.2012.07.18.log | awk '{sum+=$11; ++n} END {print "Tot="sum"("n")";print "Avg="sum/n}'
This is sample output - yours may be different.
Tot=134020202(15201)
Avg=8816.54
Depending on your Apache access log configuration you may have to change the sum+=$11 to previous or next awk token.
Beware, usually in access log last token is time of response in microseconds, penultimate token is size of response in bytes. You may use this command line to calculate sum and average of responses sizes.
You can also refine the egrep regexp to match specific HTTP requests.
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic-pae//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
This is sample output - yours may be different.
This is sample output - yours may be different.
This pattern matches empty lines in the file and -c gives the count
netstat -tn | grep :80 | awk '{print $5}'| grep -v ':80' | cut -f1 -d: |cut -f1,2,3 -d. | sort | uniq -c| sort -n
This is sample output - yours may be different.
1 192.168.1.5
5 192.168.1.2
8 192.168.1.52
15 192.168.1.3
19 192.168.1.30
cut -f1,2 - IP range 16
cut -f1,2,3 - IP range 24
cut -f1,2,3,4 - IP range 24
find /path/to/dir -type f -print0 | xargs -0 grep -l "foo"
This is sample output - yours may be different.
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
This is sample output - yours may be different.
.{D.ezENPOST /users/register HTTP/1.1
Host: www.commandlinefu.com
...
Referer: http://www.commandlinefu.com/users/register
...
Content-Type: application/x-www-form-urlencoded
Content-Length: 147
username=jseidl&password=MASKED&password-confirmation=MASKED&email-address=MASKED%MASKED.MASKEDhomepage=MASKED&submit=Sign+me+up
Simple TCPDUMP grepping for common unsafe protocols (HTTP, POP3, SMTP, FTP)
svn status | grep "^M" | while read entry; do file=`echo $entry | awk '{print $2}'`; echo $file; svn revert $file; done
This is sample output - yours may be different.
my/files.txt
Reverted 'my/files.txt'
This command allows you to revert every modified file one-by-one in a while loop, but also after "echo $file;" you can do any sort of processing you might want to add before the revert happens.
grep -r -Z -l "<text>" . | xargs -0 echo rm
This is sample output - yours may be different.
-r recursively
-Z zero byte after each file name instead of the usual newline
-l only filenames
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
This is sample output - yours may be different.
mysqlbinlog <logfiles> | grep exec | grep end_log_pos | cut -d' ' -f2- | cut -d: -f-2 | uniq -c
This is sample output - yours may be different.
....
6 0:18
1 0:17
69 0:18
4270 0:19
7032 0:20
1118 0:21
....
shows number of mysql bin log events (which are mysql server events) per minute, useful to check stress times postmortem
mysqlbinlog <logfiles> | grep exec | grep end_log_pos | grep -v exec_time=0 | sed 's/^\(.*exec_time=\([0-9]\+\).*\)/\2 - \1 /' | sort -n
This is sample output - yours may be different.
...
1 - #120528 21:55:39 server id 1 end_log_pos 10474343 Query thread_id=2446084 exec_time=1 error_code=0
15 - #120528 21:55:17 server id 1 end_log_pos 10473569 Query thread_id=2446071 exec_time=15 error_code=0
22 - #120528 21:55:17 server id 1 end_log_pos 10474905 Query thread_id=2446084 exec_time=22 error_code=0
...
Shows sorted by query time, the headers of mysqlbinlog entries. Then is easy to locate the heavier events on the raw log dump
cal 04 2012 | awk 'NF <= 7 { print $7 }' | grep -v "^$" | tail -1
This is sample output - yours may be different.
This is a little trickier than finding the last Sunday, because you know the last Sunday is in the first position of the last line. The trick is to use the NF less than or equal to 7 so it picks up all the lines then grep out any empty lines.
while true; do iptables -nvL > /tmp/now; diff -U0 /tmp/prev /tmp/now > /tmp/diff; clear; cat /tmp/diff; mv /tmp/now /tmp/prev; slee p 1; done
This is sample output - yours may be different.
@@ -28 +28 @@
- 339 27684 zone_lan_forward all -- br-lan * 0.0.0.0/0 0.0.0.0/0
+ 340 27768 zone_lan_forward all -- br-lan * 0.0.0.0/0 0.0.0.0/0
this alternative shows the differences as they occur so that they are made plain
find ./src -type d -name "Entity" | xargs ls -A | cut -d . -f1 | sed 's_^_app/console doctrine:generate:entities YourOwnBundleName:_'
This is sample output - yours may be different.
app/console doctrine:generate:entities YourOwnBundleName:Catalog
app/console doctrine:generate:entities YourOwnBundleName:Site
app/console doctrine:generate:entities YourOwnBundleName:User
app/console doctrine:generate:entities YourOwnBundleName:Software
app/console doctrine:generate:entities YourOwnBundleName:Template
...
When I do a major change in my entities, I want to find a way to find all my Entities names and create the commande for me.
So instead of doing ls src/Your/OwnBundle... and then do it manually, this helps a lot.
egrep "([_a-zA-Z][_a-zA-Z0-9]*) *= *\1 *[*/+-] *[0-9]+ *;"
This is sample output - yours may be different.
i = i + 1;
j = j - 1;
iter = iter + 2;
Search for java explicit incrementation in order to replace it with postfix or assignment operator
find /some/path -type f -and -printf "%f\n" | egrep -io '\.[^.]*$' | sort | uniq -c | sort -rn
This is sample output - yours may be different.
.m3u
.M3U
.m4a
.m4v
.mp3
.Mp3
.MP3
the
find -printf "%f\n" prints just the file name from the given path. This means directory paths which contain extensions will not be considered.
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
This is sample output - yours may be different.
small update for this command to work with linux kernels 3.x
curl -s -d "CSField=Name" -d "CSInput=BostonUCompSci" http://torstatus.blutmagie.de/index.php | grep -oP "ip=\K(\d+)(\.\d+){3}"
This is sample output - yours may be different.
#: ip2node() { curl -s -d "QueryIP=$1" http://torstatus.blutmagie.de/tor_exit_query.php | grep -oP "Server name:.*'>\K\w+" ; }
#: ip2node 204.8.156.142
#: BostonUCompSci