
Terminal - Commands using grep - 1,374 results
ps -e | grep SearchStringHere
This is sample output - yours may be different.
lsof -i -n | grep ESTABLISHED
This is sample output - yours may be different.
Uses lsof to list open network connections (file descriptors), grepping for only those in an established state
This is sample output - yours may be different.
username 8804 8802 0 09:03:19 pts/5 0:00 -tcsh
username 8802 8799 0 09:03:19 ? 0:01 /usr/lib/ssh/sshd
username 9020 8804 0 09:53:33 pts/5 0:00 ps -ef
username 9021 8804 0 09:53:33 pts/5 0:00 grep username
I like to make it an alias in my .bashrc file, as such:
alias psme='ps -ef | grep $USER'
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "optimize table " $1 ";"}' | mysql -u uname dbname
This is sample output - yours may be different.
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "drop table " $1 ";"}' | mysql -u uname dbname
This is sample output - yours may be different.
lspci | grep Ether | awk '{ VAR=$1; split(VAR,ARR,"."); count[ARR[1]]++; LINE=$0; split(LINE,LINEARR,":"); LINECOUNT[ARR[1]]=LINEARR[3]; } END { for(i in count) { printf("PCI address: %s\nPorts: %d\nCard Type: %s\n", i, count[i], LINECOUNT[i]) } }'
This is sample output - yours may be different.
echo "SHOW PROCESSLIST\G" | mysql -u root -p | grep "Info:" | awk -F":" '{count[$NF]++}END{for(i in count){printf("%d: %s\n", count[i], i)}}' | sort -n
This is sample output - yours may be different.
ps awwwux | grep httpd | grep -v grep | awk '{mem = $6; tot = $6 + tot; total++} END{printf("Total procs: %d\nAvg Size: %d KB\nTotal Mem Used: %f GB\n", total, mem / total, tot / 1024 / 1024)}'
This is sample output - yours may be different.
sudo lsof | awk '{printf("%s %s %s\n", $1, $3, $NF)}' | grep -v "(" | sort -k 4 | gawk '$NF==prv{ct++;next} {printf("%d %s\n",ct,$0);ct=1;prv=$NF}' | uniq | sort -nr
This is sample output - yours may be different.
grep -v "^#" file.txt | more
This is sample output - yours may be different.
ps -ef | grep [f]oo | awk '{print $2}' | xargs kill -9
This is sample output - yours may be different.
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.
alias 'ps?'='ps ax | grep '
This is sample output - yours may be different.
ps? ruby
13687 s000 S+ 0:06.91 ruby script/server
13693 s001 R+ 0:00.00 grep ruby
nm --defined-only --print-file-name lib*so 2>/dev/null | grep ' pthread_create$'
This is sample output - yours may be different.
strings libc-2.2.5.so | grep stat.h
This is sample output - yours may be different.
diff -q dir1/ dir2/ | grep differ | awk '{ print "vimdiff " $2 " " $4 }'
This is sample output - yours may be different.
vimdiff dir1/filea dir2/filea
vimdiff dir1/fileb dir2/fileb
vimdiff dir1/filec dir2/filec
We use this to quickly highlight differences and provide a quick way to cut and paste the command to view the files using the marvellous vimdiff
screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main
This is sample output - yours may be different.
Open a terminal (urxvt in this case) to connect to a screen session (named "main") and create the screen session if necessary.
find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM"
This is sample output - yours may be different.
Variant of find grep that ignores files with .svn in the name. Useful for searching through a local repository of source code.
zcat /usr/share/man/man1/grep.1.gz | grep "color"
This is sample output - yours may be different.
groups of context lines) with escape sequences to display them in color
The colors are defined by the environment variable
This variable specifies the color used to highlight matched (non-empty) text.
It can only specify the color used to highlight
Specifies the colors and other attributes
The default is empty (i.e., the terminal's default color pair).
The default is empty (i.e., the terminal's default color pair).
each time a colorized item ends.
This decompresses the file and sends the output to STDOUT so it can be grepped. A good one to put in loops for searching directories of gzipped files, such as man pages.
This is sample output - yours may be different.
"\C-g": abort
"\C-x\C-g": abort
"\e\C-g": abort
"\C-j": accept-line
"\C-m": accept-line
"\C-b": backward-char
"\C-h": backward-delete-char
"\C-?": backward-delete-char
"\C-x\C-?": backward-kill-line
"\e\C-h": backward-kill-word
"\e\C-?": backward-kill-word
"\C-a": beginning-of-line
"\C-xe": call-last-kbd-macro
"\C-]": character-search
"\e\C-]": character-search-backward
"\C-l": clear-screen
"\C-i": complete
"\C-d": delete-char
Useful for getting to know the available keyboard shortcuts.
find /path/to/dir -type f -exec grep \-H "search term" {} \;
This is sample output - yours may be different.
Simple use of find and grep to recursively search a directory for files that contain a certain term.
grep -o "\(new \(\w\+\)\|\w\+::\)" file.php | sed 's/new \|:://' | sort | uniq -c | sort
This is sample output - yours may be different.
1 parent
1 product_Item
1 promotion_Base
1 swc_Response
2 product_ViewHelper
2 product_ViewTransformer
4 promotion_Tab
5 site_Template
6 self
This grabs all lines that make an instantation or static call, then filters out the cruft and displays a summary of each class called and the frequency.
find . -name "*.php" -exec grep \-H "new filter_" {} \;
This is sample output - yours may be different.
tao/tests/filter/TestUrl.php: $this->objFilter = new filter_Url();
tao/classes/local/view/Photos.php: $objFilter = new filter_Url();
This greps all PHP files for a given classname and displays both the file and the usage.
alias cr='find . 2>/dev/null -regex '\''.*\.\(c\|cpp\|pc\|h\|hpp\|cc\)$'\'' | xargs grep --color=always -ni -C2'
This is sample output - yours may be different.
./openssl/signatures.c-600-xmlSecOpenSSLDsaSha1EvpInit(EVP_MD_CTX *ctx)
./openssl/signatures.c-601-{
./openssl/signatures.c:602: return SHA1_Init(ctx->md_data);
./openssl/signatures.c-603-}
./openssl/signatures.c-604-
--
./openssl/signatures.c-706- NULL,
./openssl/signatures.c-707-#else /* XMLSEC_OPENSSL_096 */
./openssl/signatures.c:708: SHA1_Init,
./openssl/signatures.c-709- SHA1_Update,
./openssl/signatures.c-710- SHA1_Final,
Creates a command alias ('cr' in the above example) that searches the contents of files matching a set of file extensions (C & C++ source-code in the above example) recursively within the current directory. Search configured to be in colour, ignore-case, show line numbers and show 4 lines of context. Put in shell initialisation file of your choice. Trivially easy to use, e.g:
cr sha1_init
find . -name "*\.php" | xargs grep -o --color "\w\+::\w\+" | cut -d":" -f2 | sort | uniq -c
This is sample output - yours may be different.
Searches all .php files for a static instantiation of a class and displays the class names along with their frequencies.