listing the latest file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting listing the latest file
# 1  
Old 02-24-2009
Power listing the latest file

if i am having files as below in a directory----

-rwxrwxrwx 1 dsadm dstage 43 Nov 21 2005 CheckfreeFtpSeq.err
-rwxrwxrwx 1 dsadm dstage 37 Jun 22 2007 EDIRemitVendorAdviceSeq.log
-rwxrwxrwx 1 dsadm dstage 43 Jun 22 2007 EDIRemitVendorAdviceSeq.err
-rw-rw-r-- 1 10155 staff 37 May 16 2008 PSIActiveDirMasterSeq.log
-rw-rw-r-- 1 10155 staff 43 May 16 2008 PSIActiveDirMasterSeq.err


can anybody tell me if i want to list the latest file i mean if i want the latest modified file.....how can i list alone that file in script,...
# 2  
Old 02-24-2009
ls -lrt | tail -1
# 3  
Old 02-24-2009
Quote:
Originally Posted by Sagarddd
if i am having files as below in a directory----

-rwxrwxrwx 1 dsadm dstage 43 Nov 21 2005 CheckfreeFtpSeq.err
-rwxrwxrwx 1 dsadm dstage 37 Jun 22 2007 EDIRemitVendorAdviceSeq.log
-rwxrwxrwx 1 dsadm dstage 43 Jun 22 2007 EDIRemitVendorAdviceSeq.err
-rw-rw-r-- 1 10155 staff 37 May 16 2008 PSIActiveDirMasterSeq.log
-rw-rw-r-- 1 10155 staff 43 May 16 2008 PSIActiveDirMasterSeq.err


can anybody tell me if i want to list the latest file i mean if i want the latest modified file.....how can i list alone that file in script,...
Code:
latest_file=$( ls -t | head -1 )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Picking the latest file based on a timestamp for a Dynamic file name

Hi , I did the initial search but could not find what I was expecting for. 15606Always_9999999997_20160418.xml 15606Always_9999999998_20160418.xml 15606Always_9999999999_20160418.xml 9819Always_99999999900_20160418.xml 9819Always_99999999911_20160418.xmlAbove is the list of files I... (4 Replies)
Discussion started by: chillblue
4 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. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

4. Shell Programming and Scripting

Listing latest modified or created files recursively

Hi, I want to display latest files (created or modified) recursively in a path. I tried in different ways, but didn't get any desired output: find $path -type f -exec ls -lt {} \; | sort -n -r find $path -type f -printf %p";" | xargs -d ";" ls -t Second one is giving the error:... (21 Replies)
Discussion started by: karumudi7
21 Replies

5. Shell Programming and Scripting

Listing latest & large files from a mounted drive

Hi All, My AIX server have a mounted drive "/stage". I want to list the latest modified/created files in this drive. Also large files in this drive. I tried to ls -l | sort +4nr | head -10 Someother solutions to list from entire drive. Thanks. :) (6 Replies)
Discussion started by: karumudi7
6 Replies

6. Shell Programming and Scripting

To get the latest file

Hi Experts Team, I wish to store the latest file name of partcular pattern in the remote server in a variable. i tried this LATEST_FILE=`ssh ${USER_ID}@${REMOTE_HOSTNAME} 'ls -t ${SOURCE_DIRECTORY}/${SOURCE_FILEPATTERN}'` but its nt working..pls guide me.. Regards, Kanda (2 Replies)
Discussion started by: spkandy
2 Replies

7. Shell Programming and Scripting

get latest file

i have the following in my directory x: 3 files with the word "LIST" inside the files 2 files without the word "LIST" 1 folder (sudirectory) i want to get the filename of the latest file (timestamp) with the word "LIST". by the way the script and the list of files are in seperate... (4 Replies)
Discussion started by: inquirer
4 Replies

8. Shell Programming and Scripting

how to get the latest file

I am trying to scp the latest file which ends with "_abc.log". Can some help me figure out how can do that? (3 Replies)
Discussion started by: shehzad_m
3 Replies

9. Shell Programming and Scripting

How do I get the name of latest file?

1) How do I get the name of latest file in a variable? 2) Is it safe to delete all files from a dir I am doing cd $dir_name if return_code > 0 rm * fi what are other alternates to delete all files from a dir in a shell script? :) (5 Replies)
Discussion started by: Hangman2
5 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question