Reputation: 3
I'm using "ls -alR" to input directories and files in those directories into another text file.
ls -alR > testalR.txt
text file is created like so:
./test-file_folders/test_folder_1:
total 400
drwx------ 5 "user" "group" "size" May 2 10:30 test_file_1
.... file info ... more file info ....test_file_2
...more files
./test-file_folders/test_folder_2:
total 400
drwx------ 5 "user" "group" "size" Oct 2 11:35 test_file_1
.... file info ... more file info ....test_file_2
...more files
I am trying to show files that have not been accessed since October 2 2018. I've tried:
`sed -n '/Oct 2 00:00/,/Oct/ 2 23:59/p' /testalR.txt
..but it produces no results. Is there a better way to display this or even possible?
Sorry, should have added this to begin with. I know using find -atime variant would be the best option. But we are using a system and a process that is bogged down by the find command. I am trying to find alternatives so using "find" can be avoided and wouldn't have to access directories directly each time I wanted to run a search.
Upvotes: 0
Views: 30
Reputation: 7516
Parsing the output of ls
is a slippery slope.
Use find
:
find . -type f -atime +3 -print
find . -type f -atime +3 -exec ls -uld {} +
Using -print
simply returns a list of the filenames. Using -exec ls -ld {} +
causes ls
to be run for every file returned, giving you the details you may want.
The argument. to atime
(or mtime
or ctime
) is in 24-hour steps. The argument can be positive or negative (or zero). Using -atime +3
finds a files that have been accessed at least FOUR days ago.
Using -exec ... {} +
causes the command in "..." to be executed for every object returned, bundling as many objects (files) as possible at a time. This is much more efficient than forking a process for every file returned, as with:
... -exec ls -uld {} \;
One way to limit your results to a specific date, is to create two reference points (files) like this:
touch -amt 201809302359 f1
touch -amt 201810012359 f2
find . -type f \( -anewer f1 -a ! -anewer f2 \) -exec ls -uld -exec {} +
Upvotes: 1
Reputation: 948
try with find:
find /folder -atime +30
where +30 = days
others params: man find
Upvotes: 0