2016年11月15日 星期二

[Linux 常見問題] Linux all files of folder modified yesterday

Source From Here 
Question 
I have modified some files present in various folders in my webroot. This was development environment. Now I have to find all files modified yesterday to migrate to productions. Is there any way (Linux command) to list only those files modified yesterday in my webroot tree? 

How-To 
Finds everything, what was modified in the current directory at the last 24 hours: 
# date +"%Y/%m/%d:%H:%M" // Check current date
2016/11/16:15:30
# date --date "1 day ago" +"%Y%m%d%H%M.%S"
201611151538.15
# date --date "2 day ago" +"%Y%m%d%H%M.%S"
201611141539.34
# date --date "3 day ago" +"%Y%m%d%H%M.%S"
201611131539.38
# touch -a -m -t 201611151538.15 1dayago
# touch -a -m -t 201611141539.34 2dayago
# touch -a -m -t 201611131539.38 3dayago
# ls -hl
-rw-r--r--. 1 root root 0 Nov 15 15:38 1dayago
-rw-r--r--. 1 root root 0 Nov 14 15:39 2dayago
-rw-r--r--. 1 root root 0 Nov 13 15:39 3dayago


// -mtime n: File's data was last modified n*24 hours ago.
# find ./ -mtime -1 // Within 1 day
# find ./ -mtime -2 // Within 2 days
./1dayago
# find ./ -mtime -3 // Within 3 days
./1dayago
./2dayago

Or you can use option -daystart which gets just files modified YESTERDAY - ie: today is Jun 21, only files for Jun 20 are found. (-mtime takes a '-', a '+', or an explicit number of exact days): 
# find -daystart -mtime 1 -exec ls -ld \;
./1dayago

Supplement 
[Linux 命令] find : 尋找特定字串的檔案或目錄 
35 Practical Examples of Linux Find Command

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...