Friday, September 25, 2015

Linux Script

[oracle@oidm-dev1 bin]$ lsb_release -i -r
Distributor ID: RedHatEnterpriseServer
Release:        6.6

Check running tasks: ps -elf | grep oracle

#netstat -an |grep 443 (to check if the port if open)
#netstat -an | egrep 'Proto|LISTEN'
#service iptables status



osearch in vi: /searchtext 

osudo su - (to work as root)
onetstat -an |grep 443 (to check if the port if open)
otail -f catalina.out (tail the content of a file)
o./file to run a local file
· show port:
onetstat -an | egrep 'Proto|LISTEN'
oservice iptables status



computer IP: nslookup computer.name.com
find file contains some text: find / -type f -name *.xml  | xargs grep -l "looking for text"

find some files: find . -name 'conf*' 


Last modified file summarized into one file:
#find *csv -mtime -10 -exec cat {} >> today.csv \;

Grep the content of a log file and sort the result, no repeat record
#grep "BIND dn=\"uid=" slapd.log | sort -k8 -u 

How do I find the most recently changed files in a set of subdirectories on Unix or Linux?

Answer 1: This will show the most recent 10 files in current directory and below.

It supports filenames with spaces. And can be slow with lots of files http://stackoverflow.com/a/7448828
sudo find . -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head
2015-08-03 13:59:49.000000000 -0700 files/CV_Smith_1July2015.pdf
2014-12-05 09:46:33.000000000 -0800 files/CV_Smith_1Dec2014.pdf
2013-03-04 10:23:16.000000000 -0800 files/Thumbs.db
2013-03-04 10:16:57.000000000 -0800 files/CV_Smith_March2013.pdf
2013-01-07 11:44:11.000000000 -0800 files/CV_Smith_5Jan2013.pdf

Answer 2: This will show all files modified in last day, in current directory and below

find . -mtime -1 -ls
This version will just print the filenames, without the file sizes or times.
find . -mtime -1 -print




Books:
http://www.freeos.com/guides/lsst/
http://www.codecoffee.com/tipsforlinux/articles/030.html?sudo

No comments: