Sponsored Content
Full Discussion: Rename The Latest File
Top Forums Shell Programming and Scripting Rename The Latest File Post 302331930 by wtolentino on Tuesday 7th of July 2009 02:30:06 PM
Old 07-07-2009
Rename The Latest File

i need to get the latest file based on timestamp. assuming that i have the following files:

Code:
$ ls -latr
total 40
drwxr-sr-x    6 pcrdftdv pcrdgrp         512 Jun 30 12:53 ..
-rwxrwxrwx    1 pcrdftdv pcrdgrp           6 Jul 07 13:35 sample1.csv
-rwxr-xr-x    1 pcrdftdv pcrdgrp           6 Jul 07 14:14 sample2.scv
-rwxr-xr-x    1 pcrdftdv pcrdgrp           6 Jul 07 14:15 sample3.csv
drwxr-sr-x    2 pcrdftdv pcrdgrp         512 Jul 07 14:15 .
$

in the example above the file sample3.csv is the last or latest that was created. how can i get the latest file and rename it to PCARDEXPT file? thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Getting latest file from ftp

Hi, i have multile JAMA01.DAT.* files in my ftp. how can i get the latest file in from the ftp by executing the script :rolleyes:? Regards, Arun S (3 Replies)
Discussion started by: arunavlp
3 Replies

2. 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

3. 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

4. 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

5. 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

6. UNIX for Dummies Questions & Answers

Need to include getting latest file and rename into some generic name

I have a sftp script which was earlier getting a file with the same name, but now, i need to get the same log file which has been moved to a different directory which has all the historical logs which have the time stamp suffixed ex: testfile.log.020111 testfile.log.020211 So now i have to get... (0 Replies)
Discussion started by: win4luv
0 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

search for latest file

Hi, In need to write a bash script which will be run periodically to check the files in a target directory. This receives files on an ad hoc basis and the script need to compare the time stamp of the latest file received with system time and write a message to the server log file if the time... (2 Replies)
Discussion started by: mark_s_g
2 Replies

9. 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

10. 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
FTP_RAWLIST(3)								 1							    FTP_RAWLIST(3)

ftp_rawlist - Returns a detailed list of files in the given directory

SYNOPSIS
mixed ftp_rawlist (resource $ftp_stream, string $directory, [bool $recursive = false]) DESCRIPTION
ftp_rawlist(3) executes the FTP LIST command, and returns the result as an array. PARAMETERS
o $ftp_stream - The link identifier of the FTP connection. o $directory - The directory path. May include arguments for the LIST command. o $recursive - If set to TRUE, the issued command will be LIST -R. RETURN VALUES
Returns an array where each element corresponds to one line of text. Returns FALSE when passed $directory is invalid. The output is not parsed in any way. The system type identifier returned by ftp_systype(3) can be used to determine how the results should be interpreted. EXAMPLES
Example #1 ftp_rawlist(3) example <?php // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // get the file list for / $buff = ftp_rawlist($conn_id, '/'); // close the connection ftp_close($conn_id); // output the buffer var_dump($buff); ?> The above example will output something similar to: array(3) { [0]=> string(65) "drwxr-x--- 3 vincent vincent 4096 Jul 12 12:16 public_ftp" [1]=> string(66) "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 public_html" [2]=> string(73) "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www -> public_html" } SEE ALSO
ftp_nlist(3). PHP Documentation Group FTP_RAWLIST(3)
All times are GMT -4. The time now is 11:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy