简体   繁体   English

Linux Change文件的修改日期?

[英]Linux Change Modification date of files?

I extract .php files in one of my directory and there were many files in there so most of the files replaced ! 我将.php文件提取到我的目录之一中,并且那里有很多文件,因此大多数文件都被替换了!

but I have a problem since the modification date of new files are 23 April 2013 so I want to find all files and folders in this directory that are not 23 April 2013 ! 但是我有一个问题,因为新文件的修改日期是2013年4月23日,所以我想查找此目录中不是2013年4月23日的所有文件和文件夹!

In other way, I want to change all files in this directory that have 23 April 2013 modification date to 30/08/2013 ! 换句话说,我想将此目录中所有具有2013年4月23日修改日期的文件更改为30/08/2013!

How its possible to find and change the files ? 如何找到和更改文件?

Combine FIND and TOUCH function to replace all files modification date. 结合查找触摸功能来替换所有文件的修改日期。

You could cd to the folder containing the PHP files and: 您可以cd到包含PHP文件的文件夹,并且:

touch -d '30 August 2013' *.php

Or if it has sub folders with php files - search through them recursively: 或者,如果它具有包含php文件的子文件夹-递归搜索它们:

find /path/to/your/php/ -exec touch -d '30 August 2013' *.php {} \;

the folder 'php' in the command above would be included. 上面命令中的文件夹“ php”将包括在内。

Edit: 编辑:

If you ONLY need to find/change EXACTLY files modified on 23 April 2013, you can use the -mtime parameter in your find command. 如果仅需要查找/更改在2013年4月23日修改过的文件,则可以在find命令中使用-mtime参数。

  • -mtime +60 means you are looking for a file modified 60 days ago or more. -mtime +60表示您要查找60天或-mtime +60之前修改的文件。

  • -mtime -60 means less than 60 days. -mtime -60表示少于60天。

  • -mtime 60 If you skip + or - it means exactly 60 days. -mtime 60如果跳过+-则表示恰好60天。

So modifying the command above like this: 因此,像这样修改上面的命令:

find /path/to/your/php/ -mtime 127 -exec touch -d '30 August 2013' *.php {} \;

Where 127 is the exact amount of days since 23 April (if my quick head calculation is correct). 其中127是4月23日以来的确切天数(如果我的快速估算正确的话)。 Else you can change the number to the correct amount of days, or use the + or - as described above if it doesn't need to be 'that' exact. 否则,您可以将数字更改为正确的天数,或者如果不需要精确的话,可以使用如上所述的+-

You can read more about the find commands -mtime parameter here: http://www.cyberciti.biz/faq/howto-finding-files-by-date/ 您可以在此处阅读有关查找命令-mtime参数的更多信息: http ://www.cyberciti.biz/faq/howto-finding-files-by-date/

(yes I borrowed 3 lines from there) (是的,我从那里借了三行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM