
Terminal - Commands using grep - 1,674 results
This is sample output - yours may be different.
This is sample output - yours may be different.
short command to find a string in all text files in all subdirectories, excluding all files grep does not deem text files.
$ grep -or string path/ | wc -l
This is sample output - yours may be different.
grep -o puts each occurrence in a separate line
while true; do netstat -p |grep "tcp"|grep --color=always "/[a-z]*";sleep 1;done
This is sample output - yours may be different.
tcp 0 0 x.x.x.x:49013 tx-in-f191.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:53838 hk-in-f83.google.:https ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:37727 72.14.203.106:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:35615 hk-in-f19.google.:https ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:52213 tx-in-f103.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:38914 tx-in-f133.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:45856 tx-in-f99.google.c:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:37726 72.14.203.106:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:45863 tx-in-f99.google.c:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:45862 tx-in-f99.google.c:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:44211 ag-in-f12:jabber-client ESTABLISHED 4351/pidgin
tcp 0 0 x.x.x.x:45861 tx-in-f99.google.c:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:37725 72.14.203.106:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:44212 ag-in-f12:jabber-client ESTABLISHED 4351/pidgin
tcp 0 0 x.x.x.x:52210 tx-in-f103.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:37718 tx-in-f101.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:52212 tx-in-f103.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:52211 tx-in-f103.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:52209 tx-in-f103.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:36595 72.14.203.138:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:52377 hk-in-f104.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:41747 calvino.freenode.n:ircd ESTABLISHED 4406/irssi
tcp 0 0 x.x.x.x:49014 tx-in-f191.google.:http ESTABLISHED 3156/firefox-bin
tcp 0 0 x.x.x.x:45857 tx-in-f99.google.c:http ESTABLISHED 3156/firefox-bin
The -p parameter tell the netstat to display the PID and name of the program to which each socket belongs or in digestible terms list the program using the net.Hope you know what pipe symbol means!
Presently we wish to only moniter tcp connections so we ask grep to scan for string tcp, now from the op of grep tcp we further scan for regular expression /[a-z]*.
Wonder what that means ?
If we look at the op of netstat -p we can see that the name of the application is preceded by a / ( try netstat -p ) so,now i assume application name contains only characters a to z (usually this is the case) hope now it makes some sense.Regular expression /[a-z]* means to scan a string that start with a / and contains zero or more characters from the range a-z !!. Foof .. is t
grep -rc logged_in app/ | cut -d : -f 2 | awk '{sum+=$1} END {print sum}'
This is sample output - yours may be different.
grep's -c outputs how may matches there are for a given file as "file:N", cut takes the N's and awk does the sum.
This is sample output - yours may be different.
I often use "vim -p" to open in tabs rather than buffers.
export LANG=C; grep string longBigFile.log
This is sample output - yours may be different.
greps using only ascii, skipping the overhead of matching UTF chars.
Some stats:
$ export LANG=C; time grep -c Quit /var/log/mysqld.log
7432
real 0m0.191s
user 0m0.112s
sys 0m0.079s
$ export LANG=en_US.UTF-8; time grep -c Quit /var/log/mysqld.log
7432
real 0m13.462s
user 0m9.485s
sys 0m3.977s
Try strace-ing grep with and without LANG=C
find . -name '*.html' -print0| xargs -0 -L1 cat |sed "s/[\"\<\>' \t\(\);]/\n/g" |grep "http://" |sort -u
This is sample output - yours may be different.
http://fonts.apple.com/TTRefMan/index.html
http://gnuwin32.sourceforge.net/packages/ttf2pt1.htm
http://heliotrope.homestead.com/files/printsoft.html
http://linuxartist.org/fonts/
Just a handy way to get all the unique links from inside all the html files inside a directory. Can be handy on scripts etc.
tar cvfz changes.tar.gz --exclude-vcs `svn diff -rM:N --summarize . | grep . | awk '{print $2}' | grep -E -v '^\.$'`
This is sample output - yours may be different.
Handy when you need to create a list of files to be updated when subversion is not available on the remote host. You can take this tar file, and upload and extract it where you need it. Replace M and N with the revisions specific to yours. Make sure you do this from an updated (svn up) working directory.
grep <pattern> -R . --exclude-dir='.svn'
This is sample output - yours may be different.
fmiss() { grep -RL "$*" * }
This is sample output - yours may be different.
This one would be much faster, as it's only one executed command.
tokill=`ps -fea|grep process|awk '{ printf $2" "}'`; kill -9 $tokill;
This is sample output - yours may be different.
ssh
[email protected] 'tail --max-unchanged-stats=10 -n0 -F /var/log/auth.log ' | grep Accepted | while read l ; do kdialog --title "SSH monitor" --passivepopup "$l" 3; done
This is sample output - yours may be different.
sudo port installed | grep -v 'active\|The' | xargs sudo port uninstall
This is sample output - yours may be different.
grep -r 'keyword keyword2' your/path/ | grep -v svn
This is sample output - yours may be different.
this command searches for a keyword or an expression in a path and avoids versionned files
find . -not \( -name .svn -prune \) -type f -print0 | xargs --null grep <searchTerm>
This is sample output - yours may be different.
By putting the "-not \( -name .svn -prune \)" in the very front of the "find" command, you eliminate the .svn directories in your find command itself. No need to grep them out.
You can even create an alias for this command:
alias svn_find="find . -not \( -name .svn -prune \)"
Now you can do things like
svn_find -mtime -3
unzip -lt foo.zip | grep testing | awk '{print $2}' | xargs rm -r
This is sample output - yours may be different.
LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
This is sample output - yours may be different.
Solves "tr" issues with non C-locales under BSD-like systems (like OS X)
grep -v "\ *#\|^$" /etc/path/to.config
This is sample output - yours may be different.
A short, *easy-er* to remember command for stripping whitespace and comments from a config file, (or any file for that matter).
Remember regex as:
slash, space, star.
pound, slash, bar.
pointy-hat, dollar. (or "caret, dollar" if you must)
:-P
tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
This is sample output - yours may be different.
S=`pidof skype`;grep heap /proc/$S/maps|cut -f1 -d' '|awk -F- '{print "0x" $1 " 0x" $2}'|xargs echo "du me t ">l;gdb -batch -p $S -x l>/dev/null 2>&1;strings t|grep \(smirk|head -n1
This is sample output - yours may be different.
(...) |\(banghead\)|\(bear\)|\(beer\)|\(blush\)|\(bow\)|\(bricklayers\)|\(brokenheart\)|\(bug\)|\(bye\)|\(cake\)|\(call\)|\(cash\)|\(chuckle\)| (...)
Skype has an internal regex which depicts the emoticons it supports. However you cannot simply search the binary file for it. This small 181 character line will do just that, provided skype is running. And of course, only works in linux.
ps aux | grep -v `whoami`
This is sample output - yours may be different.
echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
This is sample output - yours may be different.
-------------
+ sander
media: autoselect (100baseTX <full-duplex,flow-control>) status: active
media: autoselect (<unknown type>) status: inactive
media: autoselect <full-duplex> status: inactive
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet6 fe80::216:cbff:fe36:f966%en0 prefixlen 64 scopeid 0x4
inet 192.168.10.220 netmask 0xffffff00 broadcast 192.168.10.255
ether 00:16:cb:36:f9:66
ether 00:16:cb:36:f9:67
Processor type: ppc970 (PowerPC 970)
get desired info from machine and pipe it txt file.
while true; do { $(which logger) -p local4.notice `free -m | grep Mem`; sleep 60; } done &
This is sample output - yours may be different.
Uses logger in a while loop to log memory statistics frequently into the local syslog server.
svn status | grep '!' | sed 's/!/ /' | xargs svn del --force
This is sample output - yours may be different.