0

Alright so i have a web server running CentOS at work that is hosting a few websites internally only. It's our developpement server and thus has lots [read tons] of old junk websites and whatnot.

I was trying to elaborate a command that would find files that haven't been modified for over 6 months, group them all in a tarball and then delete them. Thus far i have tried many different type of find commands with arguments and whatnot. Our structure looks like such

/var/www/joomla/username/fileshere/temp /var/www/username/fileshere

So i tried something amongst the lines of :

find /var/www -mtime -900 ! -mtime -180 | xargs tar -cf test4.tar

Only to have a 10MB resulting tar, when the expected result would be over 50 GB's.

I tried using gzip instead, but i ended up zipping MY WHOLE SERVER thus making is unusable, had to transfer the whole filesystem and reinstall a complete new server and lots of shit and trouble and... you get the idea. So i want to find the perfect command that won't blow up our server but will find all FILES and DIRECTORIES that haven't been modified for over 6 months.

4

2 回答 2

1

小心ctime。

  1. ctime 与对 inode 所做的更改有关(更改权限、所有者等)

  2. 上次访问文件的时间(检查您的文件系统是否使用 noatime 或 relatime 选项,在这种情况下,atime 选项可能无法按预期方式工作)

  3. 上次修改文件中数据的时间。

根据您要执行的操作,mtime 选项可能是您的最佳选择。

此外,您应该检查 print0 选项。从男人找到:

-print0
          True;  print  the full file name on the standard output, followed by a null character (instead of the newline character that -print uses).  This allows file names that contain newlines or
          other types of white space to be correctly interpreted by programs that process the find output.  This option corresponds to the -0 option of xargs.

我不知道您要做什么,但此命令可能对您有用:

find /var/www -mtime +180 -print0 | xargs -0 tar -czf example.tar.gz
于 2013-10-15T20:30:49.917 回答
0

尝试这个:

find /var/www -ctime +180 | xargs tar cf test.tar

ctime 参数告诉您当前时间和每个文件修改时间之间的差异,如果您使用 + 而不是减号,它将为您提供“在早于 x 天的日期修改的文件”。

然后只需将它传递给带有 xargs 的 tar 就可以了。

于 2013-10-15T18:48:43.607 回答