
Terminal - Commands tagged grep - 313 results
This is sample output - yours may be different.
Will search for the given pattern and build a list of occurrences.
Then you can use :copen and :cclose to toggle the list.
When browsing the list, ENTER will take you to that line in the file.
egrep -v '(\t)?#.*|^$' /etc/apache2/sites-available/default
This is sample output - yours may be different.
find . -name "*.[ch]" -exec grep -i /dev/null "search pharse" {} \;
This is sample output - yours may be different.
Old Sys5 system and SUN computers don't have the -H option. Adding /dev/null forces grep to use the multi-file output and report the file name.
ifconfig eth0 | grep HW | cut -d " " -f 11
This is sample output - yours may be different.
systemd-analyze plot | curl -sF file1=@- http://ompldr.org/upload | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>" | sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@'
This is sample output - yours may be different.
http://ompldr.org/vZ2dyOA
Useful for figuring out which services are lagging the boot time on the system.
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