Sponsored Content
Full Discussion: Find the latest folder
Top Forums Shell Programming and Scripting Find the latest folder Post 302458657 by malcolmpdx on Friday 1st of October 2010 10:59:19 AM
Old 10-01-2010
"find" isn't going to do what you want it to. It doesn't keep track of concepts like "newest". If you had a file that was, say, created by the last run of whatever you're tracing, you could use the --newer flags to find directories created after that point, but you would still get more than one, likely. You would get all the directories created after that point in time.

This is usually where I would write a small c program calling ftw, or write something in perl (or whatever your favorite scripting language is) to stat each directory and keep track of their timestamp (you would want mtime, likely) and then emit the most recent one.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Take a folder name and find it in another folder (Complicated)

Hi Script Experts, Here is my scenario: 1. /var/mqm/qmgrs folder will contain 11 folders as follows: 1. /var/mqm/qmgrs/Folder_Name1 ....................../Folder_Name2 ....................../Folder_Name3 ....... ...................../Folder_Name11 2. if Folder_Name1 exists... (5 Replies)
Discussion started by: hkhan12
5 Replies

2. UNIX for Dummies Questions & Answers

Copy the latest file from a folder

Hi, I have a problem. I have some text files in a folder. The names can be like: emp_20080307053015.dat emp_20080306053015.dat emp_20080305053015.dat emp_20080304053015.dat The date format appended is like yyyymmdd and timestamp. What i need is i have to copy the latest file every... (3 Replies)
Discussion started by: Aswarth
3 Replies

3. Shell Programming and Scripting

Copying latest file into a folder

Hello all, this is my first post while i am trying to understand unix. I would basically like to know if i can do this: Lets say i have a folderA and folderB And i save something in folderA Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Discussion started by: takissd
16 Replies

4. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

5. Shell Programming and Scripting

Find folder within folder, then find other folder in same dir

Hi all I'm new to your forum but not new to shells. I'm having a little trouble though as it's been quite some time since I scripted. Here's what I'm trying to do: I'm trying to search a directory named '/var/root/Applications' for another directory 'fooBar'. The "Applications" directory... (9 Replies)
Discussion started by: DC Slick
9 Replies

6. UNIX for Dummies Questions & Answers

Copy the latest (last file) in given folder

#!/bin/bash for i in {1..1536..1} do #find /home/test/Desktop/up111/workplace/Malware/$i/logs for a in /home/test/Desktop/up111/workplace/Malware/$i/logs/* do #max=a for b in /home/test/Desktop/up111/workplace/Malware/$i/logs/* do ... (4 Replies)
Discussion started by: upvan111
4 Replies

7. UNIX and Linux Applications

Need to copy the latest file from Unix server to Shared folder

Hi All, One job in unix server will generate .csv files daily. I need to copy the latest of these .csv file from the unix server to the shared drive/folder in windows through unix script. My shared folder will look something like W:\some folder(for example). Could any one of you please help... (3 Replies)
Discussion started by: jaya@123
3 Replies

8. Shell Programming and Scripting

Delete all except latest datetime entery folder

Hello Expert, I have a strange requirement, I have folder where weekly backup are taken... week1_bkup_02102011 week2_bkup_09102011 week3_bkup_16102011 . . everyweek a backup is created I want to delete all folder except latest one for example in above a week4_bkup_23102011 is added... (3 Replies)
Discussion started by: aks_1902
3 Replies

9. Shell Programming and Scripting

Find latest date in folder

HI I have folder in home dir. /home/kpp/07222013 /home/kpp/07212013 /home/kpp/07202013 Output :-- /home/kpp/07222013 Just find latest date (5 Replies)
Discussion started by: pareshkp
5 Replies

10. UNIX for Beginners Questions & Answers

Retrieve the Latest file in a folder using SFTP

HI Guys, Can anyone help me to retrieve the latest file from below example using SFTP I have below list of files in a folder v403t.lstprgms.sortin1 val027.d099.fwest.oct2711 xcelrptd.d1400sqp.dec1713.t040459.@02del xcelrptd.d1400sqp.dec1713.t073308.@02del... (3 Replies)
Discussion started by: heye18
3 Replies
FTW(3)							   BSD Library Functions Manual 						    FTW(3)

NAME
ftw, nftw -- traverse (walk) a file tree SYNOPSIS
#include <ftw.h> int ftw(const char *path, int (*fn)(const char *, const struct stat *ptr, int flag), int depth); int nftw(const char *path, int (*fn)(const char *, const struct stat *ptr, int flag, struct FTW *), int depth, int flags); DESCRIPTION
These functions are provided for compatibility with legacy code. New code should use the fts(3) functions. The ftw() and nftw() functions traverse (walk) the directory hierarchy rooted in path. For each object in the hierarchy, these functions call the function pointed to by fn. The ftw() function passes this function a pointer to a NUL-terminated string containing the name of the object, a pointer to a stat structure corresponding to the object, and an integer flag. The nftw() function passes the aforementioned argu- ments plus a pointer to a FTW structure as defined by <ftw.h> (shown below): struct FTW { int base; /* offset of basename into pathname */ int level; /* directory depth relative to starting point */ }; Possible values for the flag passed to fn are: FTW_F A regular file. FTW_D A directory being visited in pre-order. FTW_DNR A directory which cannot be read. The directory will not be descended into. FTW_DP A directory being visited in post-order (nftw() only). FTW_NS A file for which no stat(2) information was available. The contents of the stat structure are undefined. FTW_SL A symbolic link. FTW_SLN A symbolic link with a non-existent target (nftw() only). The ftw() function traverses the tree in pre-order. That is, it processes the directory before the directory's contents. The depth argument specifies the maximum number of file descriptors to keep open while traversing the tree. It has no effect in this imple- mentation. The nftw() function has an additional flags argument with the following possible values: FTW_PHYS Physical walk, don't follow symbolic links. FTW_MOUNT The walk will not cross a mount point. FTW_DEPTH Process directories in post-order. Contents of a directory are visited before the directory itself. By default, nftw() traverses the tree in pre-order. FTW_CHDIR Change to a directory before reading it. By default, nftw() will change its starting directory. The current working directory will be restored to its original value before nftw() returns. RETURN VALUES
If the tree was traversed successfully, the ftw() and nftw() functions return 0. If the function pointed to by fn returns a non-zero value, ftw() and nftw() will stop processing the tree and return the value from fn. Both functions return -1 if an error is detected. ERRORS
The ftw() and nftw() functions may fail and set errno for any of the errors specified for the library functions close(2), open(2), stat(2), malloc(3), opendir(3) and readdir(3). If the FTW_CHDIR flag is set, the nftw() function may fail and set errno for any of the errors speci- fied for chdir(2). In addition, either function may fail and set errno as follows: [EINVAL] The depth argument is less than 1 or greater than OPEN_MAX. LEGACY ERRORS
The ftw() and nftw() functions are far more tolerant of symlink cycles and are lax in reporting errors while accessing the initial path. When nftw() is passed FTW_MOUNT, it will pass the mount point to the callback function. SEE ALSO
chdir(2), close(2), open(2), stat(2), fts(3), malloc(3), opendir(3), readdir(3), compat(5) STANDARDS
The ftw() and nftw() functions conform to IEEE Std 1003.1-2001 (``POSIX.1'') and Version 3 of the Single UNIX Specification (``SUSv3''). HISTORY
Prior to MacOS X 10.4 ftw did not follow symlinks. BUGS
The depth argument is currently ignored. BSD
May 20, 2003 BSD
All times are GMT -4. The time now is 06:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy