Tuesday, July 24, 2018

Search string


Find files with particular string in file name
  • find / -name "*.err"
    / - starting from / to all sub directories.
  • Specify file type with find type = d (directory) , f (file)
  • Find SUID files
    find / -perm /u=s
  • To find all the files which are modified more than 50 days back and less than 100 days.
    # find / -mtime +50 –mtime -100
  •  To find all the files which are changed in last 1 hour.
    # find / -cmin -60
  • To find all the files which are modified in last 1 hour.
    # find / -mmin -60
  • To find all the files which are accessed in last 1 hour.# find / -amin -60

Find String inside files and print file name
  • grep -rnw '/path/to/somewhere/' -e 'pattern'
    /path/to/somewhere/ - Starting directory
    -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.
     
  • ack 'text-to-find-here'

 
Redirect errors to Stdout


  • 2&>1
  • Now you can grep out the errors
    find / -name "*.err" 2&>1 | grep -v denied


     

No comments:

Post a Comment