我正在寻找一个可以显示超过1天的文件列表的命令以及一个可以删除这些文件的命令。
这是我的命令:
sudo find -type f -name "*.tmp" -mtime +1 -exec ls -ltrh {} \;
此命令为我提供了超过2天的文件列表。但我想获得超过24小时的文件列表。
同样,我有以下命令删除文件:
sudo find -type f -name "*.tmp" -mtime +1 -delete
同样的问题,它只删除那些2天的文件。
你能帮助我使用正确的命令。
**更新:**
如果我ls -ltr
-rw------- 1 user user 56344 Jun 18 03:22 4852594605084969096.tmp
-rw------- 1 user user 62420 Jun 18 03:52 8128596406378306564.tmp
-rw------- 1 user user 45108 Jun 18 05:14 9221373979761847380.tmp
-rw------- 1 user user 52092 Jun 18 05:38 8803375736497642014.tmp
-rw------- 1 user user 46076 Jun 18 05:55 2597624169466947823.tmp
-rw------- 1 user user 45108 Jun 18 06:10 7331064027553067163.tmp
-rw------- 1 user user 57600 Jun 18 06:53 571617644221476695.tmp
-rw------- 1 user user 46076 Jun 18 06:53 3250632105294480811.tmp
-rw------- 1 user user 46076 Jun 18 06:53 3049416494164364083.tmp
-rw------- 1 user user 56344 Jun 18 07:28 3800708410202563331.tmp
-rw------- 1 user user 45108 Jun 18 07:28 8459614580010423232.tmp
-rw------- 1 user user 43520 Jun 18 07:57 8661904436966583049.tmp
-rw------- 1 user user 46076 Jun 18 07:57 1204891285897472382.tmp
-rw------- 1 user user 81900 Jun 18 09:32 8465358150249612844.tmp
-rw------- 1 user user 124432 Jun 18 09:32 7187243412111611681.tmp
-rw------- 1 user user 56436 Jun 18 09:51 8372171566419231034.tmp
-rw------- 1 user user 42904 Jun 18 09:51 667863893329482278.tmp
-rw------- 1 user user 41972 Jun 18 10:11 3847591475306960147.tmp
-rw------- 1 user user 116872 Jun 18 10:11 7966362913792512054.tmp
-rw------- 1 user user 45108 Jun 18 10:11 8439035344531042431.tmp
-rw------- 1 user user 185560 Jun 18 10:11 8474346694096813378.tmp
-rw------- 1 user user 46076 Jun 18 10:11 4760470706645148372.tmp
-rw------- 1 user user 41972 Jun 18 10:11 9157761570806548970.tmp
-rw------- 1 user user 42904 Jun 18 10:12 8915926699291849585.tmp
-rw------- 1 user user 41972 Jun 18 10:22 4483378368608075076.tmp
-rw------- 1 user user 46076 Jun 18 10:22 8039354996724735242.tmp
-rw------- 1 user user 46076 Jun 18 10:22 1441427612150519563.tmp
-rw------- 1 user user 46076 Jun 18 13:39 3895289049566214606.tmp
-rw------- 1 user user 46076 Jun 18 13:41 4523819359899311681.tmp
-rw------- 1 user user 59608 Jun 18 14:28 5171792312670553667.tmp
-rw------- 1 user user 41972 Jun 18 16:07 1381867850547954997.tmp
-rw------- 1 user user 46076 Jun 18 16:08 2377385254288601418.tmp
-rw------- 1 user user 46076 Jun 18 16:08 2757855781341192620.tmp
-rw------- 1 user user 46076 Jun 18 16:08 990402164110920641.tmp
-rw------- 1 user user 88980 Jun 18 17:02 3519429446055316602.tmp
-rw------- 1 user user 46076 Jun 18 18:34 2718504484399041994.tmp
-rw------- 1 user user 52588 Jun 18 20:40 8282149999256755040.tmp
-rw------- 1 user user 45108 Jun 18 20:40 2535213203951007401.tmp
-rw------- 1 user user 62804 Jun 18 20:41 3344181299125676547.tmp
-rw------- 1 user user 46076 Jun 18 20:56 5704898344921554440.tmp
-rw------- 1 user user 57600 Jun 18 21:04 6910781806107437056.tmp
-rw------- 1 user user 57600 Jun 18 21:05 8996587449350363530.tmp
-rw------- 1 user user 57600 Jun 18 21:05 2201114289500171076.tmp
-rw------- 1 user user 171212 Jun 18 21:43 568113257671337808.tmp
-rw------- 1 user user 46076 Jun 19 02:22 4686252438135803799.tmp
-rw------- 1 user user 46076 Jun 19 02:23 1024337710253657481.tmp
-rw------- 1 user user 46076 Jun 19 02:23 8138681836575745204.tmp
-rw------- 1 user user 46076 Jun 19 02:23 4551895045706757158.tmp
-rw------- 1 user user 72880 Jun 19 02:58 6720139662475805522.tmp
-rw------- 1 user user 138036 Jun 19 03:39 4261193719990867277.tmp
-rw------- 1 user user 43520 Jun 19 04:30 2189638076744384268.tmp
-rw------- 1 user user 46076 Jun 19 04:30 9069524378589378948.tmp
-rw------- 1 user user 46076 Jun 19 06:21 4197944256637931725.tmp
-rw------- 1 user user 41972 Jun 19 07:01 4881839192080059356.tmp
-rw------- 1 user user 41972 Jun 19 07:29 7939325415825814975.tmp
-rw------- 1 user user 52092 Jun 19 08:02 334987770024624782.tmp
-rw------- 1 user user 38504 Jun 19 09:19 2006993025338095576.tmp
-rw------- 1 user user 43520 Jun 19 09:41 7349787809048549539.tmp
-rw------- 1 user user 42904 Jun 19 09:45 1393091432117053268.tmp
-rw------- 1 user user 52588 Jun 19 09:45 6110897423492319793.tmp
-rw------- 1 user user 62804 Jun 19 09:45 9143197155997936730.tmp
-rw------- 1 user user 88980 Jun 19 10:47 2758611773267584579.tmp
-rw------- 1 user user 88980 Jun 19 10:47 8190296254180009992.tmp
-rw------- 1 user user 45108 Jun 19 13:06 5668356474649690853.tmp
-rw------- 1 user user 46076 Jun 19 13:06 8831342235645870908.tmp
-rw------- 1 user user 52092 Jun 19 13:07 3760436936603717823.tmp
-rw------- 1 user user 46020 Jun 19 13:43 5381449090462674458.tmp
-rw------- 1 user user 45108 Jun 19 13:51 5714193329079454521.tmp
-rw------- 1 user user 62420 Jun 19 14:08 1861226554558152474.tmp
-rw------- 1 user user 45108 Jun 19 14:09 8180644227674226434.tmp
-rw------- 1 user user 56344 Jun 19 14:11 1162382849464709134.tmp
-rw------- 1 user user 56344 Jun 19 14:11 4473912385829326236.tmp
-rw------- 1 user user 59224 Jun 19 14:12 44816572340739296.tmp
-rw------- 1 user user 49416 Jun 19 14:29 2253955402032058887.tmp
-rw------- 1 user user 46076 Jun 19 14:54 2224021715630683512.tmp
-rw------- 1 user user 83472 Jun 19 15:25 455967079139355584.tmp
-rw------- 1 user user 83472 Jun 19 15:26 1074541420877403068.tmp
-rw------- 1 user user 46076 Jun 19 15:59 3632140460732481164.tmp
-rw------- 1 user user 45108 Jun 19 17:30 8847261278086377700.tmp
-rw------- 1 user user 54000 Jun 19 18:02 8681044407184944721.tmp
-rw------- 1 user user 54564 Jun 19 20:01 7703927324243684958.tmp
-rw------- 1 user user 54564 Jun 19 20:01 7448280277407508823.tmp
-rw------- 1 user user 54564 Jun 19 20:01 7069154843842198769.tmp
-rw------- 1 user user 54564 Jun 19 20:02 1431729105371009759.tmp
-rw------- 1 user user 54564 Jun 19 20:02 8359037531819485082.tmp
-rw------- 1 user user 54564 Jun 19 20:03 6457682749783413761.tmp
-rw------- 1 user user 54564 Jun 19 20:03 2038572826201539987.tmp
-rw------- 1 user user 54564 Jun 19 20:04 6491355393264185784.tmp
-rw------- 1 user user 59224 Jun 19 20:16 2043006978494200118.tmp
-rw------- 1 user user 45108 Jun 19 20:17 6492540855183189725.tmp
-rw------- 1 user user 45108 Jun 19 20:17 6477956601825850231.tmp
-rw------- 1 user user 45108 Jun 19 20:18 1074194357181759005.tmp
-rw------- 1 user user 45108 Jun 19 20:19 5440321220011066253.tmp
-rw------- 1 user user 45108 Jun 19 20:19 260683267390104293.tmp
-rw------- 1 user user 45108 Jun 19 20:20 1824196232656746433.tmp
-rw------- 1 user user 45108 Jun 19 20:20 8724797559370142565.tmp
-rw------- 1 user user 45108 Jun 19 20:21 6397991201954236018.tmp
-rw------- 1 user user 72880 Jun 20 04:14 7838401226118727100.tmp
-rw------- 1 user user 72880 Jun 20 04:15 7801714965385023569.tmp
-rw------- 1 user user 45108 Jun 20 08:42 1274908829136861980.tmp
-rw------- 1 user user 52092 Jun 20 08:43 5780888862258234581.tmp
-rw------- 1 user user 38628 Jun 20 08:52 756204766770614860.tmp
-rw------- 1 user user 45108 Jun 20 08:52 7485022978628098434.tmp
-rw------- 1 user user 105900 Jun 20 09:11 7854932029957477444.tmp
-rw------- 1 user user 105900 Jun 20 09:11 3956354999155285593.tmp
-rw------- 1 user user 105900 Jun 20 09:11 3966927481297956709.tmp
-rw------- 1 user user 105900 Jun 20 09:12 1705387516049599565.tmp
-rw------- 1 user user 105900 Jun 20 09:12 2525082796466540228.tmp
-rw------- 1 user user 105900 Jun 20 09:13 1591380519419898347.tmp
-rw------- 1 user user 105900 Jun 20 09:13 1102639893375607994.tmp
-rw------- 1 user user 105900 Jun 20 09:13 5262767813878310145.tmp
-rw------- 1 user user 105900 Jun 20 09:13 3288610156358797188.tmp
-rw------- 1 user user 105900 Jun 20 09:14 5829119682812572228.tmp
-rw------- 1 user user 105900 Jun 20 09:14 2452109250260818709.tmp
-rw------- 1 user user 105900 Jun 20 09:14 4590122970450657628.tmp
-rw------- 1 user user 105900 Jun 20 09:14 2294389195637964118.tmp
-rw------- 1 user user 105900 Jun 20 09:15 1676044168282755245.tmp
-rw------- 1 user user 105900 Jun 20 09:15 4366308640611104547.tmp
-rw------- 1 user user 46076 Jun 20 10:06 1107385874840309577.tmp
-rw------- 1 user user 41972 Jun 20 10:27 1085531486653661362.tmp
-rw------- 1 user user 62420 Jun 20 10:27 2101806982432516818.tmp
-rw------- 1 user user 62420 Jun 20 10:53 1624354934648606290.tmp
-rw------- 1 user user 65568 Jun 20 10:53 7654095057348026506.tmp
-rw------- 1 user user 65568 Jun 20 10:54 7700552507815118770.tmp
-rw------- 1 user user 65568 Jun 20 10:54 6308712112426443403.tmp
-rw------- 1 user user 102740 Jun 20 11:00 8795448846476018069.tmp
-rw------- 1 user user 52092 Jun 20 12:54 500845023343173208.tmp
-rw------- 1 user user 46076 Jun 20 12:54 3121276696569990545.tmp
-rw------- 1 user user 49416 Jun 20 13:46 5340608448298127831.tmp
-rw------- 1 user user 45108 Jun 20 13:46 6205360401301143413.tmp
-rw------- 1 user user 46076 Jun 20 13:59 855287858467535972.tmp
-rw------- 1 user user 56344 Jun 20 14:06 1803842700206075916.tmp
-rw------- 1 user user 46076 Jun 20 14:37 6491060217824383745.tmp
-rw------- 1 user user 45108 Jun 20 15:22 4328564943420472688.tmp
-rw------- 1 user user 45108 Jun 20 15:22 673290658104000296.tmp
-rw------- 1 user user 62804 Jun 20 15:22 3787216729224135023.tmp
-rw------- 1 user user 56344 Jun 20 21:08 4510338970233080762.tmp
-rw------- 1 user user 41972 Jun 21 00:13 398372327339912681.tmp
-rw------- 1 user user 56344 Jun 21 00:13 6904086396325952937.tmp
-rw------- 1 user user 59608 Jun 21 00:46 4051984352785933079.tmp
-rw------- 1 user user 127044 Jun 21 01:45 1935681615649757944.tmp
-rw------- 1 user user 55380 Jun 21 04:00 788398820398782761.tmp
-rw------- 1 user user 57600 Jun 21 04:00 3451867978654331939.tmp
-rw------- 1 user user 81900 Jun 21 06:09 3933771831691223539.tmp
-rw------- 1 user user 41304 Jun 21 06:10 5072654537578520166.tmp
-rw------- 1 user user 63668 Jun 21 06:10 8226596435615677441.tmp
-rw------- 1 user user 52092 Jun 21 07:48 7828279481225944808.tmp
-rw------- 1 user user 45684 Jun 21 10:30 2656910068365164057.tmp
-rw------- 1 user user 45108 Jun 21 10:31 195381961836753748.tmp
-rw------- 1 user user 43520 Jun 21 12:17 2400956652998491214.tmp
-rw------- 1 user user 49416 Jun 21 12:17 30508930089948393.tmp
-rw------- 1 user user 46020 Jun 21 12:17 6661846546424060419.tmp
-rw------- 1 user user 138036 Jun 21 12:17 5959997606181451969.tmp
-rw------- 1 user user 77388 Jun 21 13:03 331824420489889105.tmp
-rw------- 1 user user 52092 Jun 21 13:04 3758738812509306383.tmp
-rw------- 1 user user 45108 Jun 21 13:37 7496237755092762906.tmp
-rw------- 1 user user 59608 Jun 21 13:38 6544683383068478158.tmp
-rw------- 1 user user 52092 Jun 21 14:16 5731163136062904185.tmp
-rw------- 1 user user 45108 Jun 21 16:18 5547529479186863324.tmp
-rw------- 1 user user 171212 Jun 21 16:20 8323838581661442775.tmp
-rw------- 1 user user 42904 Jun 21 16:20 7250838806301761089.tmp
-rw------- 1 user user 171212 Jun 21 16:20 813682571379587717.tmp
-rw------- 1 user user 171212 Jun 21 16:20 8291233772358876144.tmp
-rw------- 1 user user 42904 Jun 21 16:20 4576361552735460033.tmp
-rw------- 1 user user 171212 Jun 21 16:20 1380471275230087315.tmp
-rw------- 1 user user 42904 Jun 21 16:21 3773859160506116712.tmp
-rw------- 1 user user 42904 Jun 21 16:21 1093442959977787407.tmp
-rw------- 1 user user 45684 Jun 21 16:21 7132957373537332056.tmp
-rw------- 1 user user 81900 Jun 21 17:41 4874781119889192787.tmp
-rw------- 1 user user 81900 Jun 21 18:59 458733250710614684.tmp
-rw------- 1 user user 45108 Jun 21 18:59 8010533676207338451.tmp
-rw------- 1 user user 49416 Jun 21 22:47 6193537558164312069.tmp
-rw------- 1 user user 45108 Jun 21 22:47 5030888357164286514.tmp
-rw------- 1 user user 38628 Jun 22 01:53 5987612845570695845.tmp
-rw------- 1 user user 45108 Jun 22 01:53 8340424949591407739.tmp
现在运行命令find . -mtime 1 -type f -exec ls -lrth "{}" \;
会给我以下列表:
-rw------- 1 user user 62K Jun 20 15:22 3787216729224135023.tmp
-rw------- 1 user user 45K Jun 20 13:46 6205360401301143413.tmp
-rw------- 1 user user 104K Jun 20 09:14 2452109250260818709.tmp
-rw------- 1 user user 45K Jun 20 15:22 673290658104000296.tmp
-rw------- 1 user user 45K Jun 20 13:59 855287858467535972.tmp
-rw------- 1 user user 56K Jun 21 00:13 6904086396325952937.tmp
-rw------- 1 user user 104K Jun 20 09:14 2294389195637964118.tmp
-rw------- 1 user user 45K Jun 20 14:37 6491060217824383745.tmp
-rw------- 1 user user 125K Jun 21 01:45 1935681615649757944.tmp
-rw------- 1 user user 45K Jun 20 08:52 7485022978628098434.tmp
-rw------- 1 user user 104K Jun 20 09:14 5829119682812572228.tmp
-rw------- 1 user user 104K Jun 20 09:15 4366308640611104547.tmp
-rw------- 1 user user 104K Jun 20 09:12 1705387516049599565.tmp
-rw------- 1 user user 104K Jun 20 09:13 3288610156358797188.tmp
-rw------- 1 user user 104K Jun 20 09:11 7854932029957477444.tmp
-rw------- 1 user user 65K Jun 20 10:54 7700552507815118770.tmp
-rw------- 1 user user 45K Jun 20 15:22 4328564943420472688.tmp
-rw------- 1 user user 41K Jun 20 10:27 1085531486653661362.tmp
-rw------- 1 user user 51K Jun 20 08:43 5780888862258234581.tmp
-rw------- 1 user user 56K Jun 20 14:06 1803842700206075916.tmp
-rw------- 1 user user 72K Jun 20 04:15 7801714965385023569.tmp
-rw------- 1 user user 41K Jun 21 00:13 398372327339912681.tmp
-rw------- 1 user user 38K Jun 20 08:52 756204766770614860.tmp
-rw------- 1 user user 104K Jun 20 09:13 1591380519419898347.tmp
-rw------- 1 user user 49K Jun 20 13:46 5340608448298127831.tmp
-rw------- 1 user user 45K Jun 20 12:54 3121276696569990545.tmp
-rw------- 1 user user 104K Jun 20 09:15 1676044168282755245.tmp
-rw------- 1 user user 101K Jun 20 11:00 8795448846476018069.tmp
-rw------- 1 user user 104K Jun 20 09:11 3956354999155285593.tmp
-rw------- 1 user user 45K Jun 20 10:06 1107385874840309577.tmp
-rw------- 1 user user 61K Jun 20 10:27 2101806982432516818.tmp
-rw------- 1 user user 104K Jun 20 09:11 3966927481297956709.tmp
-rw------- 1 user user 72K Jun 20 04:14 7838401226118727100.tmp
-rw------- 1 user user 56K Jun 20 21:08 4510338970233080762.tmp
-rw------- 1 user user 51K Jun 20 12:54 500845023343173208.tmp
-rw------- 1 user user 104K Jun 20 09:12 2525082796466540228.tmp
-rw------- 1 user user 61K Jun 20 10:53 1624354934648606290.tmp
-rw------- 1 user user 65K Jun 20 10:54 6308712112426443403.tmp
-rw------- 1 user user 45K Jun 20 08:42 1274908829136861980.tmp
-rw------- 1 user user 59K Jun 21 00:46 4051984352785933079.tmp
-rw------- 1 user user 104K Jun 20 09:14 4590122970450657628.tmp
-rw------- 1 user user 104K Jun 20 09:13 5262767813878310145.tmp
-rw------- 1 user user 65K Jun 20 10:53 7654095057348026506.tmp
-rw------- 1 user user 104K Jun 20 09:13 1102639893375607994.tmp
我期待的所有文件都是6月18日,6月19日,6月20日,6月21日。可以将Jun 21文件限制为24小时或更早的文件。但该命令只给出了Jun 20& Jun 21文件超过24小时而忽略了Jun 18& 6月19日档案。
答案 0 :(得分:1)
find
允许使用-mtime
选项,正如答案here
中所解释的那样,可以帮助您。
您期待的答案如下:找到在1天到2天之前完全修改过的文件。
-mtime 1 (实际答案)
find /sourcedirectory -mtime 1 -type f -exec ls -lrth "{}" \; -exec rm "{}" \;
通常会查找在N
和N+1
天之前修改过的文件。
将足以列出和删除文件。只要您遵循语法,就可以使用任意数量的-exec
。
其他选项的工作原理如下: -
-mtime +N
- >文件已修改至少N + 1天前
-mtime -N
- >修改的文件少于N天前