Skip to content

Instantly share code, notes, and snippets.

@hilfritz
Last active February 8, 2022 04:23
Show Gist options
  • Save hilfritz/27e7f5cc1441fea243770bf5663e941a to your computer and use it in GitHub Desktop.
Save hilfritz/27e7f5cc1441fea243770bf5663e941a to your computer and use it in GitHub Desktop.
Linux commands
find . -name "*textToSearch*" -print
find . -iname "*textToSearch*" -print (case insensitive)
--recursive search for a file in directory that contains 'textToSearch' in file name
find . -maxdepth 1 -name "*textToSearch*" -print
-- -maxdepth 1 - means search only in current directory, not subdirectories
-- https://stackoverflow.com/questions/11328988/find-all-files-with-name-containing-string
find libdir -name "*.jar" -exec zipgrep "TEXTTOFINDINSIDEJAR" '{}' \;
find . -name "*.jar" -exec zipgrep "TEXTTOFINDINSIDEJAR" '{}' \;
-libdir the directory that contains the jar files
- . means search in current directory
grep -r "textToSearch" logfilename.txt
--search occurence of 'textToSearch' string inside logfile name
grep -r "textToSearch" logfilename.txt > res.txt
--search occurence of 'textToSearch' string inside logfile name, and saves the result inside file called res.txt
-- add -n to show line number where textToSearch occurs ex. grep -r -n "textToSearch" logfilename.txt
-- -r search recursively
-- search all files recursively then replace logfilename.txt with . (dot)
https://stackoverflow.com/questions/15286947/how-perform-grep-operation-on-all-files-in-a-directory
//this will get all the lines inside the directory from all the files
grep -rni '<string to compare>' *
https://stackoverflow.com/questions/15286947/how-perform-grep-operation-on-all-files-in-a-directory
//this will get all the lines inside the directory from all the files
grep -rni '<string to compare>' *
watch realtime a log file for occurence of text
tail -1000f logFileName.log | grep -i "textToFindOccurence"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment