2017-01-03 34 views
0

我試圖列出x天以前的目錄(但不是文件)。我用下面的命令來做到這一點。但它列出了目錄和文件。任何人都可以幫我解決它嗎?謝謝。在Linux中只刪除x天以前的目錄(不是文件)

find /path/to/base/dir/* -type d -ctime +10 -exec ls {} \; 
+0

它列出了目錄和文件,因爲你在說'ls {}'結果。相反,請使用'ls -d {}'列出目錄本身。 – fedorqui

+0

GNU'find'有一個'-ls'動作,就像'ls -dils'一樣,'find'可以找到。 –

+0

如果你只是想像'ls -d'這樣的輸出顯示它,你可以刪除這個動作,默認爲'-print',和'-exec ls -d {} \ –

回答

0

試試這個

find /path/to/base/dir -maxdepth 1 -type d -ctime +10 -exec rm -r {} \; 
0

先行先試,如果一切正常的:

find /path/to/base/dir -type d -ctime +10 -exec ls -d {} \; 

當一切正常:

find /path/to/base/dir -type d -ctime +10 -exec rm -fr {} \; 

說明:

ls -d : list directories themselves, not their contents 
rm -f : ignore nonexistent files and arguments, never prompt