Searching for files over 30 days old in current directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for files over 30 days old in current directory
# 15  
Old 05-29-2006
I think it should be '-maxdepth 0' then it will work,

how ever man pages definetly say that -purne option will not allow find to search in subdirectories of current directory...

cheers,
# 16  
Old 05-30-2006
maxdepth 0 has maximum of one line of output

maxdepth 0 has maximum of one line of output -- TITS. (Try It To See)

maxdepth -1 outputs the contents of one directories, without recursing into subdirs.

At least, seems that way to me Smilie

A use that I have found for the prune option is to find everything in a directory but skip version controlling dirs and their contents, eg folders named .csv or .svn.

find . -type d -name .svn -prune -false -o -type f
# 17  
Old 05-30-2006
Most recent HP-UX find man page: HP-UX find(1)
Most recent Solaris find man page: Solaris find(1)
The official Posix standard for find: IEEE Std 1003.1, 2004 Edition find

Please notice what these documents have to say regarding the -maxdepth option: not one word. Solutions involving -maxdepth are not portable at all.

Quote:
Originally Posted by tphyahoo
maxdepth 0 has maximum of one line of output -- TITS. (Try It To See)
Well, I can find only two flavors of -maxdepth and neither supports the view that output is limited to a single line. When I tried it...
Code:
$ touch one two three
$ find one two three -maxdepth 0 -type f
one
two
three
$ find .
.
./one
./two
./three
$

# 18  
Old 05-30-2006
I hadn't really thought about portability...

Thanks for pointing that out.

I hadn't really thought about portability, but I am going to try be more "portably" correct.

In terms of portability, I am assuming that the posix definition should be fairly portable, so I will pay the most attention to that.
# 19  
Old 06-11-2006
30 days

Try this :

#!/bin/sh

i="/pat/to/dir/you/wanna/check/"
msg () {
for i
do echo "clearing: $i" >&2
done
}

fatal () { msg "$@"; exit 1; }

if [ ! -d "$i" ]
then msg "no directory: $i"
elif [ ! -r "$i" -o ! -w "$i" ]
then msg "access denied (no rw- access): $i"
else
# search & destroy
find "$i" ! -type d -mtime +30d -print | xargs rm -f > /dev/null 2>&1

[ -d "$i" ] || continue
(cd $i || continue
for d in *
do
[ -d "$d" ] || continue
find . -depth -type d -mtime +30d -print |
xargs rmdir > /dev/null 2>&1
done
)
fi
exit 0

This works for me to delete files 30 days old from directory $i in depth

Last edited by Heimdal; 06-11-2006 at 03:34 AM..
Heimdal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. Shell Programming and Scripting

How to clean 3 days before files, from a directory?

I have a Solaris System. I am using bash shell. I want to prepare a script which can do the below. There are few directories i need to clean. In those directories, I need to delete files which are older than 3 days. 3 days before files need to be deleted. The directories are as follows.... (7 Replies)
Discussion started by: Saidul
7 Replies

4. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

5. Shell Programming and Scripting

How to strip ^M at end of each files for all files found in current directory

I am trying to use a loop to strip of the funny character ^M at the end of all lines in each file found in current directory and I have used the following in a script: find . -type f -name '*.txt' | while read file do echo "stripping ^M from ..." ex - "$file" > $tempfile %s/^M//g wq! # mv... (4 Replies)
Discussion started by: bisip99
4 Replies

6. Shell Programming and Scripting

mget * (obtein files from current directory but not the files form sub-directories)

Hello, Using the instruction mget (within ftp) and with "Interactive mode off", I want to get all files from directory (DirAA), but not the files in sub-directories. The files names don't follow any defined rule, so they can be just letters without (.) period Directory structure example: ... (0 Replies)
Discussion started by: Peter321
0 Replies

7. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

8. Shell Programming and Scripting

searching content of files in the current and sub directories

Hi I was wondering why command 2 doesn't work like command 1 below. 1. find . -exec grep "test" '{}' \; -print 2. ls -R | grep "test" I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2? Thanks in advance for your help (4 Replies)
Discussion started by: tiger99
4 Replies

9. Shell Programming and Scripting

searching files through all subdirectories beneath the current directory

i want to make a bash script that searches a specific pattern in files through all subdirectories beneath the current directory..without using the command grep-R but only the command grep.. e.g for i in * do grep "pattern" $i ..... ... done using the character (*) the script... (5 Replies)
Discussion started by: milagros
5 Replies

10. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question