I'm writing a script to find the oldest file in a directory. I know this can be done by using ls -rt | tail -1 but these are rather large directories and that can be somewhat slow since the script will be running constantly.
Are there any other ways to do this that would be faster? I looked to... (2 Replies)
Hi all,
I need your assistance in removing the oldest file in a directory.
I posted the same thread 3 days back and I got the following answer
ls -1 -t | tail -1 | xargs rm
which is not covering the case when there are directories older than the oldest file.
So, could you please... (2 Replies)
I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves.
Also, the script should only move a file from /exports to... (6 Replies)
I am using a bash script to perform some automated maintenance on files in a directory. When I run the script using $sh -x script.sh <directory> the script works fine. It sets the variable to the oldest file, and continues on. However when I run the script like this $./script.sh <directory>, it... (5 Replies)
Hi:-
I need help with a script I need to modify: - what's the best/easiest way to find out the oldest file in a directory and then move this file to another directory?
Thanks, (5 Replies)
Hi all,
I am a newbie to scripting and I need your help regarding finding the oldest file in a particular directory. My intention is to remove that oldest file.
Are there any options available with the "find" command to do this..
Thanks in advance for your help
Pavan (4 Replies)
Hey! I have found similar posts both here and on other sites regarding this, but I cannot seem to get my script to work. I want to delete the oldest file in a test directory if there are more than two files. My script is currently:
#!/bin/bash
MEPATH=/usr/local/bin/test
FILECOUNT=`ls... (4 Replies)
There are some 25,000 files in 7,000 directories in my source library and I am trying to find oldest files. I am running this find:
find /usr/mysrc -name "*." -type f -mtime +8000 -exec ls -l {} 2>/dev/null
and playing with the days parameter for mtime, but the output is not sorted... (3 Replies)
Discussion started by: migurus
3 Replies
LEARN ABOUT SUNOS
closedir
closedir(3C) Standard C Library Functions closedir(3C)NAME
closedir - close a directory stream
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dirp);
DESCRIPTION
The closedir() function closes the directory stream referred to by the argument dirp. Upon return, the value of dirp may no longer point to
an accessible object of the type DIR. If a file descriptor is used to implement type DIR, that file descriptor will be closed.
RETURN VALUES
Upon successful completion, closedir() returns 0. Otherwise, -1 is returned and errno is set to indicate the error.
ERRORS
The closedir() function may fail if:
EBADF The dirp argument does not refer to an open directory stream.
EINTR The closedir() function was interrupted by a signal.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |Safe |
+-----------------------------+-----------------------------+
SEE ALSO opendir(3C), attributes(5), standards(5)SunOS 5.10 24 Jul 2002 closedir(3C)