LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   BASH: filters for ls command (https://www.linuxquestions.org/questions/linux-desktop-74/bash-filters-for-ls-command-880569/)

snorky 05-13-2011 01:19 PM

BASH: filters for ls command
 
In BASH how do I list all files older than 1000 days?

szboardstretcher 05-13-2011 01:21 PM

Quote:

Originally Posted by snorky (Post 4355551)
In BASH how do I list all files older than 1000 days?

Code:

find / -mtime +1000

EricTRA 05-13-2011 01:22 PM

Hello,

Have a look at the man page for find, more in particular the -mtime and -atime parameters.
Code:

man find
Kind regards,

Eric

szboardstretcher 05-13-2011 01:24 PM

Quote:

Originally Posted by EricTRA (Post 4355557)
Hello,

Have a look at the man page for find, more in particular the -mtime and -atime parameters.
Code:

man find
Kind regards,

Eric

One of the most confusing man pages ever. For me anyway. I really needed a chart and graph to grasp the -x, x and +x of mtime.

EricTRA 05-13-2011 01:26 PM

Hi,

It is indeed pretty complex (but also complete) but after reading what you need like 4 times it becomes clear.

Kind regards,

Eric

snorky 05-13-2011 03:41 PM

Quote:

Originally Posted by szboardstretcher (Post 4355555)
Code:

find / -mtime +1000

The problem is that I need the kind of information that ls gives, e.g., date, owner.

Also, the find command chokes on some files (it stopped on a rather large .mov file

EricTRA 05-13-2011 03:56 PM

Hello,

Have a look at the man page for ls:
Code:

-c    with -lt: sort by, and show, ctime (time of  last  modification  of  file
            status  information) with -l: show ctime and sort by name otherwise: sort
            by ctime

That will sort your files by last modification time for example. From there you'd have to use some more scripting to calculate if the last modification time exceeds your limit of 1000 days.

Kind regards,

Eric

catkin 05-13-2011 03:58 PM

Quote:

Originally Posted by snorky (Post 4355694)
The problem is that I need the kind of information that ls gives, e.g., date, owner.

Also, the find command chokes on some files (it stopped on a rather large .mov file

Try this (it will fail if there are a very large number of files)
Code:

ls -l $( find / -mtime +1000 )
Are you sure about find choking? It is very robust.


All times are GMT -5. The time now is 01:15 AM.