Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible on linux to find directories where all contained files and directories (and sub-directories' files etc.) are older than a given age? In other words, if a directory has one or more files within that have a modification date more recent than a given threshold, that directory should not be listed. If all of the files and folders below that directory are older than the given threshold, then that directory should be listed.

The use case is that my home directory is full of hidden directories, and I'm sure that many of them are left overs from previous installations, and software that I haven't used in years. I'd like to be able to find these directories, so I can easily decide whether to cull them.

share|improve this question
What do you mean by "older": modification or access time? Note that the latter will be meaningless if the file system is mounted with relatime or noatime. Also a very old modification time doesn't necessarily mean that a file is useless. – cYrus Jun 26 '12 at 7:39
@cyrus modification time. I know it doesn't mean it's useless. As I said, I just want to use this as a tool to help me to decide what is useless.. – naught101 Jun 28 '12 at 1:13

2 Answers

find -type f -mtime +30

to check files older than 30 days

if you add -iname '.*' it will show you the hidden files

or -type d for directories

share|improve this answer
Yes, I know this. I'm not looking for files older than the date, I'm looking for directories which only contain files and directories which are all older than the given date. – naught101 Jun 26 '12 at 6:09

You could use the following workaround to implement your need:

$ touch -t 201206010100 some_file
$ find . -newer some_file

At touch man page:

-t STAMP
    use [[CC]YY]MMDDhhmm[.ss] instead of current time

There is also -d option of touch but i haven't used it. You could give it a try.

[Edit] you could use touch -d option as follows to generate a file at a given date:

$ touch -d "Wed Jun 27 09:44:44 EEST 2012" some_file
$ ls -l some_file
-rw-r--r-- 1 user user 0 2012-06-27 09:44 some_file

The you could use the same approach i mentioned above

share|improve this answer
See my comment on Petkaux answer. This doesn't solve my question, and it's also a bit nutty, Why wouldn't I just use find -newert 201206010100 ? – naught101 Jun 27 '12 at 0:56
you could use -d option on touch command which will enable you to create file at a given date. – scriptmonster Jun 27 '12 at 6:44
Before you spend more time on this answer, I think you should re-read the question. It is not asking what you think it is asking. – naught101 Jun 28 '12 at 1:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.