Posts Tagged ‘bash’

22 08 2010

find 查找指定时间的文件

bigCat Posted in Linux - 0 Comment

http://www.cyberciti.biz/faq/howto-finding-files-by-date/\r\n\r\n[a] access (read the file's contents) - atime\r\n\r\n[b] change the status (modify the file or its attributes) - ctime\r\n\r\n[c] modify (change the file's contents) - mtime\r\n\r\nYou can search for files whose time stamps are within a certain age range, or compare them to other time stamps.\r\n\r\nYou can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option.\r\n

    \r\n
  • -mtime +60 means you are looking for a file modified 60 days ago.
  • \r\n

  • -mtime -60 means less than 60 days.
  • \r\n

  • -mtime 60 If you skip + or - it means exactly 60 days.
  • \r\n

\r\nSo to find text files that were last modified 60 days ago, use\r\n$ find /home/you -iname "*.txt" -mtime -60 -print\r\n\r\nDisplay content of file on screen that were last modified 60 days ago, use\r\n$ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \; \r\n\r\nCount total number of files using wc command\r\n$ find /home/you -iname "*.txt" -mtime -60 | wc -l\r\n\r\nYou can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days:\r\n$ find /home/you -iname "*.pdf" -atime -60 -type -f\r\n\r\nList all mp3s that were accessed exactly 10 days ago:\r\n$ find /home/you -iname "*.mp3" -atime 10 -type -f\r\n\r\nThere is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command\r\n$ find /home/you -iname "*.mp3" -daystart -type f -mtime 1 \r\n\r\nWhere,\r\n

    \r\n
  • -type f - Only search for files and not directories
  • \r\n

\r\n

-daystart option

\r\nThe -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:\r\n

find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl"

\r\nYou can also list perl files that were modified 8-10 days ago, enter:\r\nTo list all of the files in your home directory tree that were modified from two to four days ago, type:\r\n

find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl"

\r\n

-newer option

\r\nTo find files in the /nas/images directory tree that are newer than the file /tmp/foo file, enter:\r\n

find /etc -newer /tmp/foo

\r\nYou can use the touch command to set date timestamp you would like to search for, and then use -newer option as follows\r\n

touch --date "2010-01-05" /tmp/foo\r\n# Find files newer than 2010/Jan/05, in /data/images\r\nfind /data/images -newer /tmp/foo\r\n

\r\nRead the man page of find command for more information:\r\nman find

2 04 2009

重启apache的bash脚本

bigCat Posted in Linux - 2 Comments
INFO=`netstat -ln | grep -P ":80"`\r\nDATE=`date`\r\nif [ "$INFO" == "" ]\r\nthen\r\n/etc/init.d/httpd restart\r\necho "$DATE shit happens" >> /var/log/httprestart.log\r\nps aux | mail -s mt17down httprestart@ooxx.me\r\nelse\r\necho "$DATE pass" >> /var/log/httprestart.log\r\nfi

\r\n\r\n\r\n\r\n

*/1 * * * * /root/httprestart.sh >/dev/null 2>&1

\r\n\r\n

Host: (miao) | Word: Press | Code: HTML5