Select the latest dated file-ksh script

Thread Tools Search this Thread
# 1  
Select the latest dated file-ksh script

Hello all!! I am new here and new in scripting!
I want to write a ksh script to select the most recent file from a dir and use it in a variable.

I have a directory with files named like: YYYMMDD
A basic idea of the script I want to write is

latest= latest_dated_file at /path

so I can use the variable $latest later..

Any idea of how to do that?
Thanks in advance!!
# 2  
If the dates in the names are the same as the actual file times:
latest=$(ls -t * | head -1)

If the names of the files are really not related to dates of the file itself
latest=$(ls * | tail -1)

# 3  
Many thanks jim SmilieSmilie

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #487
Difficulty: Easy
A program's entry point is always defined by a main function or method.
True or False?

10 More Discussions You Might Find Interesting

1. Ubuntu

FTP script to get latest file from server

Hello people, I have to download, with a scheduled script, the latest file from an FTP server. In the remote DIR, named .../TEKNONET/60468/, every night a CDR file like this gets uploaded into it: 000006046820151122N001.CDR, so my script will have to download every day the previous day... (12 Replies)
Discussion started by: virtus96
12 Replies

2. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

3. Shell Programming and Scripting

To select a script name till .ksh or .sh

Hi All, My requirement is to search for a Table Name being used in list of script placed at a dir path : we are using below command to get the desired result : grep -H -i <Table_name> <dir_path>/* -r|awk '{print $1}'| uniq -d #It gives me below result ... (3 Replies)
Discussion started by: sanjaydubey2006
3 Replies

4. Shell Programming and Scripting

Why stderr file descriptor redirection makes ksh's "select" construct hang.

I am trying to use one global declaration --> "exec 2>$ERR" to capture all stderr outputs that may occur anywhere in my script. Then close it at the end of the script using --> "exec 2<&-" I am using KSH on Solaris 8. KSH Version M-11/16/88i If I comment two "exec .." statements in the... (11 Replies)
Discussion started by: kchinnam
11 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

Help in writing a KSH script to filter the latest record?

Hi All, I have a text file with the folowing content. BANGALORE|1417|2010-02-04 08:41:04.174|dob|xxx BANGALORE|1416|2010-02-04 08:23:19.566|dob|yyy BANGALORE|1415|2010-02-04 08:20:14.497|dob|aaa BANGALORE|1414|2010-02-04 08:19:40.065|dob|vvv BANGALORE|1413|2010-02-04... (4 Replies)
Discussion started by: Karpak
4 Replies

7. Shell Programming and Scripting

Script to untar latest tar file

I am trying to put together a script that will check for the latest file in a directory then extract it. The extraction and the scheduling I can do, but am not sure how to get it to check for the latest file. These files are uploaded every evening by an external party and the previous days files... (3 Replies)
Discussion started by: stheologo
3 Replies

8. Shell Programming and Scripting

find full directory and delete old dated file?

I want to write a code that will look for a particular directory which is full or more than 95% used, and will search older file and delete it. My code looks like this: df -k|while read f1 f2 f3 f4 f5 f6 do if expr '$f5' -ge '95%' || continue then echo $f5 else echo "there is no... (2 Replies)
Discussion started by: xramm
2 Replies

9. Shell Programming and Scripting

Script to cd into newest (dated) FTP directory

I have written the following simple bash script. It logs onto an FTP site and then CDs into a directory that corresponds to the last business day. So for example the directory I would access today is 20060110 (2006 jan 10). I am currently taking today's date and subtracting 1, putting this... (3 Replies)
Discussion started by: steved
3 Replies

10. Shell Programming and Scripting

ksh: How to get latest file from a list of files in a directory

Hi, I need to get the latest file from a list of files in a particular directory. Please could anyone help me out to get the file. Thank you, - Jay. (1 Reply)
Discussion started by: Jayathirtha
1 Replies

Featured Tech Videos