0

I am trying to list the directories (but not files) older than x days. I used below command to do it. But it is listing directories and files. Could anyone help me in resolving it? Thanks.

find /path/to/base/dir/* -type d -ctime +10 -exec ls {} \;
fedorqui
  • 275,237
  • 103
  • 548
  • 598
sunil
  • 65
  • 3
  • 11
  • it is listing directories and files because you are saying `ls {}` to the results. Instead, do use `ls -d {}` to list the directory itself. – fedorqui Jan 03 '17 at 20:28
  • GNU `find` has an `-ls` action that behaves like `ls -dils` for what `find` finds. – Benjamin W. Jan 03 '17 at 20:31
  • If you just want the output like `ls -d` would show it, you can remove the action, which defaults to `-print` and is the same as `-exec ls -d {} \;` – Benjamin W. Jan 03 '17 at 20:33

2 Answers2

0

Try this

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

First to test if all is alright :

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

When all is ok :

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

Explanations :

ls -d :  list directories themselves, not their contents
rm -f :  ignore nonexistent files and arguments, never prompt
V. Michel
  • 1,599
  • 12
  • 14