Results 1 to 9 of 9
Hello, I'm writing a script to remove files from a directory more than 30 days old, matching a certain pattern (*name*) without removing from subvols.
I am far enough that ...
- 07-31-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 3
Removing old fies from a directory
Hello, I'm writing a script to remove files from a directory more than 30 days old, matching a certain pattern (*name*) without removing from subvols.
I am far enough that it finds the old files by name (using find) and writes them to a file. When I loop through the file and read it, it executes every line instead of performing a move of it.
Any ideas?
Thanks
Geoff
Here is the read and copy section of my code. Note: once this works it will be changed to a move
# Read logfile, get file basename (no dir) and move to output file loc
while read -u3 oldfile
do
oldbase=basename $oldfile
cp $oldfile $outdir/$oldbase
done 3<oldpaths.log
- 07-31-2007 #2
You can move files older than 30 days with one command:
So there's really no need to do file i/o, unless you need a log.Code:find / -name whatever -ctime +30 -exec mv {} /newdir/ \;
And if by old, you mean modification time change ctime to mtime. Or atime for access.
- 07-31-2007 #3
That might not be what you're looking for but I am a little unclear as to what you mean by "subvols."
- 07-31-2007 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 3
I don't want the find to be recursive. I only want it to move files in the directory I specify.
Thanks,
Geoff
- 07-31-2007 #5I think that should do it.Code:
find / -name whatever -maxdepth 1 -ctime +30 -exec mv {} /newdir/ \;
- 07-31-2007 #6Just Joined!
- Join Date
- Jul 2007
- Posts
- 3
The version of find I have doesn't support the -maxdepth arg. it also doesn't have -path.
- 07-31-2007 #7
Then troll through the man pages. I am using GNU find.
- 07-31-2007 #8Linux User
- Join Date
- Jun 2007
- Posts
- 318
Then try -prune:
Code:find * -prune -type f -name <whatever> -ctime +30 -exec mv {} /newdir/ \;
- 07-31-2007 #9Just Joined!
- Join Date
- Jul 2007
- Posts
- 41
I think your script would work if you changed
toCode:oldbase=basename $oldfile
The first way will create an environment in which oldbase=basename then run the file at the path stored in $oldfile, like the env command.Code:oldbase=$(basename $oldfile)
The second way will execute basename on oldfile and store the result in oldbase.


Reply With Quote