finding latest file in Unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding latest file in Unix
# 1  
Old 03-04-2005
finding latest file in Unix

Hi,
i want to search a file in the dir , if file exists for todays date print the message that file found or if file does not exist for todays date/ if file not found i want to display message saying that file not found. How to do this.

Thx for your help.
# 2  
Old 03-04-2005
Something like this might work.
#! /bin/csh
set d1=`ls -lrt test.sh | cut -c34-39`
set d2=`date | cut -c5-10`
echo $d1
echo $d2
if($d1==$d2) then
echo "file exists for today"
else
echo "file does not exist for today"
endif
exit(0)
# 3  
Old 03-05-2005
Code:
ls -ltr | grep "`date | cut -c5-10`"

if test $? -eq 0
then
    echo "FOUND"
else
    echo "NOT FOUND"
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding latest file in dir but getting syntax errors

I believe there are couple of syntax issues in my script, couldn't find them :( can someone help me with fixing it to make it work. cd /abcde/ #get the latest filename excluding subdirs filename=`ls -ltr | grep ^- | tail -1 | awk '{print $8}'` #get system date and file timestamp and... (3 Replies)
Discussion started by: simpltyansh
3 Replies

2. Shell Programming and Scripting

Need help with finding the latest files

Hi, Actually i got a client requirment and i need experts help here. we have 30 parent directories and in that we have so many subdirectories and files. i want to find only latest timestamp files with out touching subdirectories and need to redirect the latest files into some other... (3 Replies)
Discussion started by: lkeswar
3 Replies

3. Shell Programming and Scripting

Finding the Latest record

Dear All, I have getting data as follows, the second field signifies table name and last one is time stamp. I have return always latest record based on time stamp. Could you please help me ? I/P ==== ... (1 Reply)
Discussion started by: srikanth38
1 Replies

4. Shell Programming and Scripting

Help with finding the latest modified version of a file within directories

I am trying to look into multiple directories and pluck out the latest version of a specific file, regardless of where it sits within the directory structure. Ex: The file is a .xls file and could have a depth within the directory of anywhere from 1-5 Working directory - Folder1... (6 Replies)
Discussion started by: co21ss
6 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Finding the latest file in a directory

Hi All, I am using the below command to find the latest file in a dir: ls -tr $v_sftphomedir/$v_sourcefile |tail -1 or ls -t1 $v_sftphomedir/$v_sourcefile |head -1 and the outpur returned is below: /home/cobr_sftp/var/controllingload/Backup/Dbrwds_Div_1796050246.txt I need only the... (5 Replies)
Discussion started by: abhi_123
5 Replies

6. Shell Programming and Scripting

Finding the Latest file in a Dir

Hi Everyone, I am writing a shell script and I am struck here: I need to find the latest file in a directory depending upon the date. For example: The files in the directory are: Filename_bo_20110619 Filename_bo_20110620 Filename_bo_20110621 Filename_bo_20110622 So here, I want... (2 Replies)
Discussion started by: filter
2 Replies

7. UNIX for Dummies Questions & Answers

Get the latest file from UNIX

Dear Friends, Am very much new to UNIX and this is my first task in UNIX. Can you pls help me with the below problem: i want to get the latest file from unix to mainframes. I did the following remote ls -t $AMR/data01/extract/monthly/source/- AMR_D*""_REC_STAT.dat - > v1 remote... (2 Replies)
Discussion started by: amarpandian
2 Replies

8. Shell Programming and Scripting

ftp the latest file from unix to windows

Hi, I have a ftp script to ftp files from unix to windows. Now i need to pull the latest file from unix to windows. It is not working. ftp -nvi $SERVER > ${FILE_DIR}/NavigationftpLog << EOD user $USER $PWD lcd $FILE_DIR echo "the local directory is $FILE_DIR" cd $Remote_PATH echo... (2 Replies)
Discussion started by: ammu
2 Replies

9. UNIX for Dummies Questions & Answers

How to find the latest file on Unix or Linux

Please help me out how to identify the latest file in one directory by looking at file's timestamp or datestamp. You can say using system command. Thanks (10 Replies)
Discussion started by: duke0001
10 Replies

10. Shell Programming and Scripting

finding latest file having timestamp on it.....

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (1 Reply)
Discussion started by: kaushik25
1 Replies
Login or Register to Ask a Question