How to find files in directory tree by date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find files in directory tree by date
# 1  
Old 09-19-2012
How to find files in directory tree by date

I'm using a directory naming convention to organize files as exemplified here:

2012/Aug/week-20-Aug/23-Thu/tuv.txt
2012/Aug/week-27-Aug/30-Thu/abc.txt
2012/Sep/week-27-Aug/01-Sat/def.txt
2012/Sep/week-03-Sep/07-Fri/xyz.txt

How do I write a command that will list the file names abc.txt and def.txt because they are both in same week?

I cannot assume the file system dates for modification or creation of the file matches the directory they are stored in.

Thanks
Siegfried
# 2  
Old 09-19-2012
Use find(1):
Code:
find 2012/Aug/week-27-Aug -type f

# 3  
Old 09-19-2012
All the files

Thanks but that won't find the file 2012/Sep/week-27-Aug/01-Sat/def.txt.

How can I start searching from 2012 and find both files def.txt and abc.txt and not find tuv.txt or xyz.txt?
# 4  
Old 09-19-2012
What's your system?

On Linux I might do this:

Code:
# Search inside all months for weeks
find 2012 -maxdepth 2 -mindepth 2 -type d | while read WEEK
do
        # Glob all files for that week
        set -- "$WEEK"/*/*.txt

        # Print if more than one is found for that week
        [ "$#" -gt 1 ] && echo "$@"
done


Last edited by Corona688; 09-19-2012 at 01:03 PM..
# 5  
Old 09-19-2012
Code:
find 2012/*/week-27-* -type f

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

2. UNIX for Dummies Questions & Answers

How to find directory listing from root to all files in tree format with details of perm/own/grp?

Hi, My apologies if my query is already available on this forum but I am new and could not find. I need a script to list all directories/sub directories and files with permissions/groups/owners. The script would run from home directory and should capture every directory. How do I do this? ... (4 Replies)
Discussion started by: 8709711
4 Replies

3. Shell Programming and Scripting

Delete all files with specific extension in directory tree

I'm sure this has been asked many times, but a search didn't turn up a definitive best method for this (if there ever is such a thing). I have been using rsync to back up my main data directory, but I have accumulated a large number of older backups that I don't need. All of the files I don't... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

4. Shell Programming and Scripting

Shell script to build directory tree and files

Hi all, I'm trying at the moment to write a shell script to build a directory tree and create files within the built directories. I've scoured through sites and text books and I just can't figure out how to go about it. I would assume that I need to use loops of some sort, but I can't seem... (8 Replies)
Discussion started by: Libertad
8 Replies

5. Shell Programming and Scripting

remove a whole directory tree WITH files inside?

Assume I want to remove a whole directory tree beginning with /foo/bar/ The directory or sub-directories may contain files. The top directory /foo/bar/ itself should not be deleted. rm -f- r /foo/bar does not work because it requires a directory tree without files. How does it work... (3 Replies)
Discussion started by: pstein
3 Replies

6. UNIX for Dummies Questions & Answers

Copy directory tree with files

Iam in the process of copying a directory with thousands of directories and files into a new directory. I need to preserve permissions, owner, group, date and timestamps, everything. Iam using AIX and would need help of writing the command whether it is cp-RP or cpio. Apprecaite your... (3 Replies)
Discussion started by: baanprog
3 Replies

7. Shell Programming and Scripting

Find Oldest file in a directory tree

This might just be one command. Any1 having the solution? Thanks, Rahul. (25 Replies)
Discussion started by: rahulrathod
25 Replies

8. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies

9. Shell Programming and Scripting

Recursively copy only specific files from a directory tree

Hi I am a shell-script newbie and am looking to synchronize certain files in two directory structures. Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over. I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)
Discussion started by: sharpsharkrocks
3 Replies

10. Shell Programming and Scripting

Read from fileList.txt, copy files from directory tree

Hi, hopefully this is a fairly simple Q&A. I have a clean file list of approximately 180 filenames with no directory or slashes in front of the filename nor any extension or dot ".". I would like to read from this list, find these files recursively down through directory trees, copy the files... (1 Reply)
Discussion started by: fxvisions
1 Replies
Login or Register to Ask a Question