ksh - Checking directory trees containing wild cards
Hi
Can somebody please show me how to check from within a KSH script if a directory exists on that same host when parts of the directory tree are unknown?
If these wildcard dirs were the only dirs at that level then ...
... will work as $RETCODE will have a value if the dir exists.
But if there are multiple sub dirs at the 'wildcard' level, how can I grab the one that was last created?
It does not make sense to request the most recent directory and then want a return code for an answer. This returns the ouptut for ls -l for one file.
Do you want the last time modified or the inode time? Change the ls parameters to match your requirements. The reason I ask is that some posters do not fully understand the difference.
inode time is as close as you get for "create" time - for many kinds of file systems. Since I do not know what filesystems you are using this is the best I can do for you....
This User Gave Thanks to jim mcnamara For This Post:
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Not knowing what your environment is, many systems utilize locate:
which might be faster than probing the filesystem, since the updatedb database already contains the results of such a probe.
Available on Linux, Solaris, macOS.
See man locate for details.
For example, finding a file xxx-yyy-zzz (edited ~ for actual home):
Best wishes ... cheers, drl
Hi Jim. Actually I originally only wanted to check that the dir existed but then had to change it to handle the possibility of multiple dirs with the same name in different directory trees. I don't need a return code in this scenario. You're right of course, like some of the other comments also mention, the best way to do this is using find. Thanks very much for your reponse.
---------- Post updated at 09:32 AM ---------- Previous update was at 09:32 AM ----------
Quote:
Originally Posted by RudiC
This is not related to ksh at all - you'll need external commands for this. Try - if your find version allows for it -
or
This worked perfectly. Many thanks Rudi.
---------- Post updated at 09:34 AM ---------- Previous update was at 09:32 AM ----------
Quote:
Originally Posted by drl
Hi.
Not knowing what your environment is, many systems utilize locate:
which might be faster than probing the filesystem, since the updatedb database already contains the results of such a probe.
Available on Linux, Solaris, macOS.
See man locate for details.
For example, finding a file xxx-yyy-zzz (edited ~ for actual home):
Best wishes ... cheers, drl
Thanks also for this. I wasn't familiar with this command before. Checking it out now.
I want to use Find command to find directories that have certain name and them find files in that directory having only some extensions. So far, I have come up with this command to list directories with wild card name and list ALL the files in that directory.
find . -type d -name prog\* -print... (11 Replies)
Hi experts,
I am new to perl.
I am trying to get the last file from set of files.
Using the below code; but getting error
pls help
Files:
-rw-r--r-- 1 abc abc 12584 Mar 18 16:22 /abc/def/ghi/xyz.HOSTNAME.2016.03.18.16.21.69709-6
-rw-r--r-- 1 abc abc 12623 Mar 18 16:25... (4 Replies)
I have constant trouble with XCOPY/s for multi-gigabyte transfers.
I need a utility like XCOPY/S that remembers where it left off if I reboot. Is there such a utility? How about a free utility (free as in free beer)?
How about an md5sum sanity check too?
I posted the above query in another... (3 Replies)
Im trying to use wild cards to find files that start with either an upper or lower case letter e.g. list files that beginning with b or B, i also want to sort them by the time they were last modified. e.g latest file created first.
At the moment i have the following code that
ls -d... (3 Replies)
Hi,
How do i check if I have read/write/execute rights on a UNIX directory?
What I'm doing is checking read access on the files but i also want to check if user has rights on the direcory in whcih these files are present.
if then......
And I check if the directory exists by using... (6 Replies)
I want to backup all the directory tress, including hidden directories, without copying any files.
find . -type d gives the perfect list.
When I tried tar, it won't work for me because it tars all the files.
find . -type d | xargs tar -cvf a.tar
So i tried rsync.
On my own test box, the... (4 Replies)
hi all,
i have created a file by name tt and while listing the file ,i used the command
$ls t from which i was expecting not to list tt file output coz of uppercase range, But it listed that file tt file and am not able understand the reason. kindly help.
NOTE OS :Red Hat Enterprise... (0 Replies)
Hi
I have a job that will be running nightly incremental backsup of a large directory tree.
I did the initial backup, now I want to write a script to verify that all the files were transferred correctly. I did something like this which works in principle on small trees:
diff -r -q... (6 Replies)
how do you put a space in a wild card thing..
example
"LastAnalysisT.*${MONTH}.*${DAY}.*20${YEAR}"
I need to make it something like
"LastAnalysisT.*${MONTH}<I need a space here>.*${DAY}.*20${YEAR}"
So it would be something like:
LastAnalyst*May 24*2004
Where * just means I dont... (1 Reply)