Skip to content

Instantly share code, notes, and snippets.

@byteofprash
Last active January 31, 2020 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byteofprash/187ba60bdf4a8373b024992d89437af5 to your computer and use it in GitHub Desktop.
Save byteofprash/187ba60bdf4a8373b024992d89437af5 to your computer and use it in GitHub Desktop.

Grep

  1. To use a Color GREP to only highlight matched patterns but not otherwise change the output:

grep --color=always -e "^" -e "hello" testfile

  1. Find a pattern in all files
    grep -rnw '/path/to/somewhere/' -e 'pattern' 
    * -r or -R is recursive,
    * -n is line number, and
    * -w stands for match the whole word.
    * -l (lower-case L) can be added to just give the file name of matching files.
  • To find only with certain extension grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
  • To exclude certain extension grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
  • To exclude dirs grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

SSH

  1. Bind a port connecting to a remote server. (Eg: tensorboard running on remote server)
   ssh -N -f -L localhost:16006:localhost:6006 <user@remote>
   -N : no remote commands
   -f : put ssh in the background
   -L <machine1>:<portA>:<machine2>:<portB> :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment