WebSphere Issues

14/07/2015

Useful grep and find commands

Filed under: Linux — Ishtiaque @ 12:57 pm

1. Search a given pattern for on a particular date and less output:

  • grep ‘pattern’ ssl_access_log* | grep ‘*/Apr/2015’ | less

2. Search a given pattern and count number of results:

  • grep ‘pattern’ ssl_access_log* | wc -l

3. Search a string in the given directory:

  • grep -C 2 “open for e-business” /logs/SystemOut*
  • grep -Ri “open for e-business” /logs/

4. Search the given string in the current directory and sort the output:

  • grep ‘pattern’ $(ls -tr *) > /tmp/response.txt

5. Exclude one or more strings from the tail command:

  • tail -fn1000 /etc/httpd/logs/ssl_access_logs|grep -vE ‘200|404|403’

6. Some useful ‘find’ command usages:

  • find / -type f -iname *.txt
  • find / -type d iname mydir
  • find / -perm /a=x
  • find / -type f -perm 0777 -print -exec chmod 644 {} \;
  • find / -type f -name “*.txt” -exec rm -f {} \;
  • find / -type f -empty (Find empty files)
  • find /tmp -type f -name “.*” (Find hidden files)
  • find /home -user user1 (Find files of a user1)
  • find /home -group developer (Find files of a group)
  • find / -mtime 7 (Find all files modified 7 days back)
  • find / -atime 7 (Find all files accessed 7 days back)
  • find / -mtime +5 –mtime -10 (Find files modified more than 5 and less than 10 days)
  •  find / -size +5M -size -10M (Find all files greater than 5 and less than 10 MB)
  • find / -type f -name *.txt-size +10M -exec rm {} \;
Advertisements

Blog at WordPress.com.

%d bloggers like this: